On 25/05/14 08:17, Nikolay Pavlov wrote:
>
> On May 25, 2014 4:24 AM, "Tony Mechelynck" <antoine.mechelynck@gmail.com
> <mailto:antoine.mechelynck@gmail.com>> wrote:
> >
> > On 23/05/14 13:19, John Little wrote:
> >>
> >> On Friday, May 23, 2014 10:36:56 AM UTC+12, Nate Soares wrote:
> >>>
> >>> Is there a way to get the expansion of a digraph (entered e.g. with
> ^K in insert mode) programatically?
> >>
> >>
> >> There isn't a vim script way to do this directly. I can think of
> two ways, one somewhat unclean, the other pedestrian.
> >>
> >> Firstly, this approach may have side effects, might spoil your
> screen layout, and harm innocent animals:
> >>
> >> function! ExpandDigraph(dig)
> >> if a:dig !~ '^..$'
> >> return ""
> >> endif
> >> new
> >> exe "norm! a\<c-k>" . a:dig . "\<esc>"
> >> let result = getline(".")
> >> close!
> >> return result
> >> endfunc
> >>
> >> Secondly: capture the output of the command :digraph, (:help redir)
> and reformat it to one column (that's tricky because there's lots of
> funny characters), and write it to a file, say "digraphs.txt". Then,
> >>
> >> function! ExpandDigraph(dig)
> >> if !exists("s:digs")
> >> let s:digs = {}
> >> for line in readfile("digraphs.txt")
> >> let s:digs[line[0:1]] = line[3:]
> >> endfor
> >> endif
> >> return has_key(s:digs, a:dig) ? s:digs[a:dig] : ""
> >> endfunc
> >>
> >>> For example, I have vim set up to insert the ellipsis character '…'
> when I type "^K..". Is there a way, programatically, to write a function
> ExpandDigraph such that ExpandDigraph("..") yields "…"?
> >>
> >>
> >> BTW, with my vim 7.4.274 on linux ".." is a digraph for "‥" U+2025
> TWO DOT LEADER, not an ellipsis, "…" U+2026 HORIZONTAL ELLIPSIS. My vim
> only has digraphs for U+22EF MIDLINE HORIZONTAL ELLIPSIS and U+22EE
> VERTICAL ELLIPSIS. If you've defined your own digraphs, and you use my
> second approach you'd have to add yours to the file.
> >>
> >> Regards, John Little
> >>
> >
> > Note that nothing forbids having more than one digraph for the same
> character, and in fact by default some characters have both an RFC1345
> digraph and a "legacy Vim" digraph (as the latter was used before Vim
> digraphs were standardized to RFC1345). Having more than one character
> for a single digraph, however, is of course not possible: trying to
> define a new equivalent for an existing digraph replaces it.
> >
> > The above function would always return the last character-pair in the
> list for any given character, for instance (with the default digraphs)
> n~ (the legacy digraph) and not n? (the RFC1345 digraph) for U+00F1
> LATIN SMALL LETTER N WITH TILDE. (Any previous digraph for the same
> character would be replaced when creating the Dictionary.)
>
> ?! Quoted functions solve forward problem: given n? return U+00F1, not
> backward: given U+00F1 return n?.
Oops, sorry.
>
> >
> >
> > Best regards,
> > Tony.
--
With every passing hour our solar system comes forty-three thousand
miles closer to globular cluster M13 in the constellation Hercules, and
still there are some misfits who continue to insist that there is no
such thing as progress.
-- Ransom K. Ferm
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment