Advertisement
ivangcb

Simple Diatheke plugin for Vim

Dec 7th, 2013
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 2.77 KB | None | 0 0
  1. " Author:    Ivan Guillermo Castro B. <ivan@ibgf.cl>
  2. " Version:    1.6 Dec 12, 2013 // english translation
  3. " Version:    1.5 May 09, 2012 // rango de busquedas
  4. " Version:    1.4 Mar 29, 2012
  5. " Version:    1.3 Oct 11, 2011
  6. " Version:    1.2 Aug 13, 2011
  7. " Version:    1.1 Aug 10, 2011
  8. " Version:    1.0 Aug 16, 2008
  9.  
  10.  
  11. " Diatheke
  12. vmap B y :call Biblia()<CR>
  13.  
  14. function Biblia()
  15.  
  16.     "Default Bible version (Always the zero [0] option)
  17.     let vers_bib = "SpaRV60"
  18.     "Encoding
  19.     let encoding = "UTF8"
  20.     "Some extra stuff
  21.     let search_type = ""
  22.     let extra_op = "-o nx"
  23.     let cita = @"
  24.     let rango = ""
  25.  
  26.     "Menu
  27.     echo " [0]  Reina Valera 1960 (default)"
  28.     echo " [1]  La Biblia de las Américas"
  29.     echo " [2]  King James Version"
  30.     echo " [m]  Multiword Search (default Bible)"
  31.     echo " [x]  RegEx Search (default Bible)"
  32.     echo ""
  33.  
  34.  
  35.     let sel_bib = input ("Select number or hit enter (default 0): ")
  36.  
  37.     if (sel_bib == "1")
  38.         let vers_bib = "SpaLBA"
  39.  
  40.     elseif (sel_bib == "2")
  41.         let vers_bib = "KJV"
  42.  
  43.     elseif (sel_bib == "x" || sel_bib == "X" || sel_bib == "m" || sel_bib == "M")
  44.         let extra_op = ""
  45.         let rango = input ("Search range (Example: Mat-Joh -or empty for no range-): ")
  46.  
  47.         if (sel_bib == "x" || sel_bib == "X")
  48.             let search_type = "-s regex"
  49.             let cita = input ("RegEx: (Example: paral*): ")
  50.         else
  51.             let search_type = "-s multiword"
  52.             let cita = input ("Keywords (Separated by spaces): ")
  53.         endif
  54.  
  55.     endif
  56.  
  57.     if (rango != "")
  58.         let rango = "-r " . rango
  59.     endif
  60.  
  61.     if (search_type != "")
  62.         let hint = system('diatheke -e '. encoding .' ' . search_type . ' -l es -b '. vers_bib .' '. rango .' -k "' . cita .'"')
  63.         let hint = substitute(expand(hint), 'Verses containing .*"' , '&\r\r', 'g')
  64.         let hint = substitute(expand(hint), '-- [1-9]* matches total.*', '', 'g')
  65.         let hint = substitute(expand(hint), '--', '', 'g')
  66.         let hint = substitute(expand(hint), ';', '\r', 'g')
  67.         let vers_bib = "Results_for"
  68.     else
  69.         let hint = substitute(system('diatheke -e '. encoding .' '. search_type .' '. extra_op .' -f plain -l es -b '. vers_bib .' -k "' . cita .'"'), "$", "\r", "g")
  70.     endif
  71.  
  72.     wincmd s
  73.     enew!
  74.  
  75.     setlocal buftype=nofile
  76.     setlocal bufhidden=wipe
  77.     setlocal noswapfile
  78.     setlocal wrap
  79.     setlocal nobuflisted
  80.  
  81.     let cita = substitute(cita, ' ', '_', 'g')
  82.     let cita = substitute(cita, '|', 'OR', 'g')
  83.     let cita = substitute(cita, '&', 'AND', 'g')
  84.  
  85.     execute "silent file ". vers_bib . "_" . cita
  86.     execute "silent normal i".hint."\<cr>\<esc>gg"
  87.     execute "silent normal :%s\/^\\s*\/\/g\<cr>\<esc>\\\\gg"
  88.  
  89.     redraw!
  90.  
  91. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement