Wikia

Vim Tips Wiki

Changes: Finding phone numbers

Edit

Back to page

(Clean.)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 34: Line 34:
   
 
After sourcing the above script:
 
After sourcing the above script:
*In any file, put the cursor on a phone number and type <tt>@p</tt> to dial the number.
+
*In any file, put the cursor on a phone number and type <code>@p</code> to dial the number.
*In any file with a name starting with "<tt>phone</tt>", put the cursor on a phone number and press Enter to dial the number.
+
*In any file with a name starting with "<code>phone</code>", put the cursor on a phone number and press Enter to dial the number.
   
The shell script <tt>dial</tt> (not shown) uses its argument to write modem control sequences to <tt>/dev/ttysS0</tt> to cause the modem to dial the phone number. The script removes all non-digit characters from the number, then does something like this shell command:
+
The shell script <code>dial</code> (not shown) uses its argument to write modem control sequences to <code>/dev/ttysS0</code> to cause the modem to dial the phone number. The script removes all non-digit characters from the number, then does something like this shell command:
 
<pre>
 
<pre>
 
echo -ne 'atdt,<number>;h0\r' >/dev/ttyS0
 
echo -ne 'atdt,<number>;h0\r' >/dev/ttyS0
Line 43: Line 43:
   
 
==Comments==
 
==Comments==
Not many people will have a modem (or the required <tt>dial</tt> script) to try this tip, but there are some useful ideas that might be useful for other applications. [[User:JohnBeckett|JohnBeckett]] 10:54, May 11, 2012 (UTC)
+
Not many people will have a modem (or the required <code>dial</code> script) to try this tip, but there are some useful ideas that might be useful for other applications. [[User:JohnBeckett|JohnBeckett]] 10:54, May 11, 2012 (UTC)

Latest revision as of 05:53, July 13, 2012

Tip 872 Printable Monobook Previous Next

created 2005 · complexity intermediate · author Bertram Scharpf · version 6.0


When editing a file containing phone numbers, the following can be used to dial the number under the cursor. It uses a shell script (not shown) to make a modem dial the number.

" Return phone number under cursor.
" If no number, return an empty string (if argument is zero),
" otherwise throw an error to abort script.
function! CPhone(check)
  let s = '[-+./()0-9 ]*'
  let nr = matchstr(getline('.'), '\s*\zs'.s.'\%'.col('.').'c'.s)
  let nr = substitute(nr, '\s\+$', '', '')
  if a:check && empty(nr)
    throw 'No phone number under cursor.'
  endif
  return nr
endfunction

let @p = ":execute \":!dial '\".CPhone(1).\"'\"\<CR>"

augroup LocalUser
  autocmd BufRead phone* nnoremap <buffer> <CR> :execute ":!dial '".CPhone(1)."'"<CR>
augroup END

After sourcing the above script:

  • In any file, put the cursor on a phone number and type @p to dial the number.
  • In any file with a name starting with "phone", put the cursor on a phone number and press Enter to dial the number.

The shell script dial (not shown) uses its argument to write modem control sequences to /dev/ttysS0 to cause the modem to dial the phone number. The script removes all non-digit characters from the number, then does something like this shell command:

echo -ne 'atdt,<number>;h0\r' >/dev/ttyS0

CommentsEdit

Not many people will have a modem (or the required dial script) to try this tip, but there are some useful ideas that might be useful for other applications. JohnBeckett 10:54, May 11, 2012 (UTC)

Around Wikia's network

Random Wiki