3 Commits 8fe25934a8 ... 7d40b190fe

Autor SHA1 Mensagem Data
  Henrique Paone 7d40b190fe Adds 'Surround' plugin to Vim 1 mês atrás
  Henrique Paone 6e7ecb8e64 '_surround' handles token insertion in the middle of the line 1 mês atrás
  Henrique Paone 43ba825c79 Hnadle uncompressed files in 'eman' 2 meses atrás
2 arquivos alterados com 53 adições e 5 exclusões
  1. 14 5
      dot-bashrc
  2. 39 0
      dot-vim/plugin/surround.vim

+ 14 - 5
dot-bashrc

@@ -181,6 +181,7 @@ norm_name() {
 eman() {
 	# Dir we are storing the converted files
 	local -r base_dir='/tmp/autoless'
+	local -r convert='groff -spte -mandoc -Thtml'
 	local -a pages_arr
 	
 	mkdir $base_dir 2>/dev/null
@@ -190,14 +191,19 @@ eman() {
 		# Find the path to the page and format its name
 		local page=$(man -w $page)
 		(($? != 0)) && continue # Skip missing pages
-		
+
 		# Format the page name
 		local page_base=$(basename $page)
-		local page_path=$base_dir/${page_base/bz2/html}
+		local page_path=$base_dir/${page_base/%.*/.html}
 		pages_arr+=($page_path)
 
-		# Convert pages to HTML
-		bzcat $page | groff -spte -mandoc -Thtml >${page_path} 2>/dev/null
+		# Convert to HTML
+		if [[ $page_base == *bz2* ]] ; then
+			bzcat $page | $convert >${page_path} 2>/dev/null
+		else
+			# Handle uncompressed files
+			$convert $page >${page_path} 2>/dev/null
+		fi
 	done
 
 	elinks -force-html ${pages_arr[@]}
@@ -288,7 +294,6 @@ complete -F _root_command doas
 source /usr/share/bash-completion/completions/man
 complete -F _comp_cmd_man eman m
 
-
 #------------------------------------------------------------------------------
 # Binding scripts
 #------------------------------------------------------------------------------
@@ -313,6 +318,9 @@ _surround() {
 	if [[ -z "$cursor_to_end" ]] ; then 
 		line="$line$open$close"
 		point=$((${#line} - 1))
+	elif [[ "${line:$point:1}" == ' ' ]] ; then 
+		line="$start_to_cursor$open$close$cursor_to_end"
+		((point++))
 	else
 		case $action in
 		all) 
@@ -330,6 +338,7 @@ _surround() {
 	READLINE_POINT=$point
 }
 
+
 # Bindings using the '_surround' function
 bind -m vi-insert -x '"(":"_surround all \( \)"'
 bind -m vi-insert -x '"\"":"_surround all \" \""'

+ 39 - 0
dot-vim/plugin/surround.vim

@@ -0,0 +1,39 @@
+"------------------------------------------------------------------------------
+" Wrap text with specific tokens. The 'Surround' functions currently supports
+" two strategies for surrounding text: 'eol', surround text from cursor to the
+" end of line; and 'word', surround only the word 
+"------------------------------------------------------------------------------
+
+fu! Surround(args)	
+	let [action, open, close] = a:args
+	let l:ccol = getcurpos()[2]
+	let l:line = getline('.')
+	
+	if line[ccol] == ''
+		call setline('.' , line . open . close)
+		call cursor('.', len(getline('.')))
+		return
+	endif
+	
+	let l:cursor_to_end = line[ccol:]
+	let l:line_to_cursor = line[:ccol]
+	
+	if action == 'eol'
+		call setline('.', line_to_cursor . open . cursor_to_end . close)
+		call cursor('.', len(getline('.')))
+	elseif action == 'word'
+		let l:word = expand("<cword>")
+		let l:cursor_to_end = substitute(cursor_to_end, word, open . word . close, '')
+		call setline('.', line_to_cursor . cursor_to_end)
+		call cursor('.', len(word) + ccol + 2)
+	endif
+endf
+
+command! -nargs=+ Surround
+	\ let s:args = split(<q-args>) |
+	\ let s:key = s:args[0] |
+	\ let s:str = printf('nnoremap %s <esc>:call Surround(%s)<cr>', s:key, s:args[1:]) |
+	\ exe s:str
+
+"Surround <leader>( eol ( )
+"Surround <leader>{ word { }