Skip to content

Commit

Permalink
vis-digraph: add utility to handle digraphs
Browse files Browse the repository at this point in the history
Hook it up via Lua to <C-k> in insert and replace mode.

Close martanne#460 martanne#475
  • Loading branch information
josuah authored and martanne committed Jan 27, 2017
1 parent 8871316 commit b8afec9
Show file tree
Hide file tree
Showing 6 changed files with 2,113 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/vis
/vis-menu
/vis-single
/vis-digraph
*.css
*.gcda
*.gcno
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SRC = array.c buffer.c libutf.c main.c map.c register.c ring-buffer.c \
ui-curses.c view.c vis.c vis-lua.c vis-modes.c vis-motions.c \
vis-operators.c vis-prompt.c vis-text-objects.c $(REGEX_SRC)

EXECUTABLES = vis vis-clipboard vis-complete vis-menu vis-open
EXECUTABLES = vis vis-clipboard vis-complete vis-menu vis-digraph vis-open

MANUALS = $(EXECUTABLES:=.1)

Expand Down Expand Up @@ -44,7 +44,7 @@ LDFLAGS_VIS = $(LDFLAGS_AUTO) $(LDFLAGS_TERMKEY) $(LDFLAGS_CURSES) $(LDFLAGS_ACL

STRIP?=strip

all: vis vis-menu
all: vis vis-menu vis-digraph

config.h:
cp config.def.h config.h
Expand All @@ -58,6 +58,9 @@ vis: config.h config.mk *.c *.h
vis-menu: vis-menu.c
${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@

vis-digraph: vis-digraph.c
${CC} ${CFLAGS} ${CFLAGS_AUTO} ${CFLAGS_STD} ${CFLAGS_EXTRA} $< ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@

debug: clean
@$(MAKE) CFLAGS_EXTRA='${CFLAGS_EXTRA} ${CFLAGS_DEBUG}'

Expand All @@ -77,7 +80,7 @@ test:

clean:
@echo cleaning
@rm -f vis vis-menu vis-${VERSION}.tar.gz *.gcov *.gcda *.gcno
@rm -f vis vis-menu vis-digraph vis-${VERSION}.tar.gz *.gcov *.gcda *.gcno

dist: clean
@echo creating dist tarball
Expand All @@ -95,7 +98,7 @@ luadoc:
luadoc-all:
@cd lua/doc && ldoc -a . && sed -e "s/RELEASE/${VERSION}/" -i index.html

install: vis vis-menu
install: vis vis-menu vis-digraph
@echo stripping executable
@${STRIP} vis
@echo installing executable files to ${DESTDIR}${PREFIX}/bin
Expand Down
24 changes: 24 additions & 0 deletions lua/vis-std.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,27 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
local right = ' ' .. table.concat(right_parts, " « ") .. ' '
win:status(left, right);
end)

-- additional default keybindings

vis:map(vis.modes.INSERT, "<C-k>", function(keys)
if #keys < 2 then
return -1 -- need more input
end
local file = io.popen(string.format("vis-digraph '%s' 2>&1", keys:gsub("'", "'\\''")))
local output = file:read('*all')
local success, msg, status = file:close()
if success then
if vis.mode == vis.modes.INSERT then
vis:insert(output)
elseif vis.mode == vis.modes.REPLACE then
vis:replace(output)
end
elseif msg == 'exit' then
if status == 2 then
return -1 -- prefix need more input
end
vis:info(output)
end
return #keys
end, "Insert digraph")
68 changes: 68 additions & 0 deletions man/vis-digraph.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.Dd January 27, 2017
.Dt VIS-DIGRAPH 1
.Os Vis VERSION
.Sh NAME
.Nm vis-digraph
.Nd print Unicode character using mnemonics
.
.Sh SYNOPSIS
.
.Nm
.Ar digraph ...
.
.Nm
.Fl
.
.Sh DESCRIPTION
.
.Nm vis-digraph
read a digraph from command line argument or standard input and print
a corresponding Unicode character to standard output, encoded in current
locale.
.
.Bl -tag -width 8
.It Ar digraph
A set of two (or more) characters that get replaced by a single Unicode
character.
.It Fl
Read digraph from standard input.
.El
.Pp
Without argument,
.Nm
displays all available digraphs along with a description.
.
.Sh ENVIRONMENT
.
.Bl -tag -width 8
.
.It Ev LC_CTYPE
Locale definition, setting the encoding format of the Unicode character printed out.
See
.Xr locale 1
for more information.
.El
.
.Sh EXIT STATUS
.
.Bl -tag -width 4
.It 0
Digraph correctly read recognised and printed out.
.It 1
Digraph not recognised.
.It 2
Digraph is the beginning of an existing digraph, but does not correspond to a full digraph.
.It 3
An error occured and digraph could not be read or printed.
.El
.
.Sh SEE ALSO
.
.Xr locale 1 ,
.Xr vis 1
.
.Sh STANDARDS
.
.Nm
follows the digraph format from
.Lk http://tools.ietf.org/rfc/rfc1345.txt "RFC 1345"
1 change: 1 addition & 0 deletions man/vis.1
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ Spawn background process and pipe range to its standard input:
.Sh SEE ALSO
.Xr vis-clipboard 1 ,
.Xr vis-complete 1 ,
.Xr vis-digraph 1 ,
.Xr vis-menu 1 ,
.Xr vis-open 1 ,
.Xr vi 1
Expand Down
Loading

0 comments on commit b8afec9

Please sign in to comment.