Skip to content

Instantly share code, notes, and snippets.

@DeaR
Last active December 11, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeaR/4631987 to your computer and use it in GitHub Desktop.
Save DeaR/4631987 to your computer and use it in GitHub Desktop.
Abbreviations for NYAOS 3.x
-- Abbreviations for NYAOS 3.x
--
-- Maintainer: DeaR <nayuri@kuonn.mydns.jp>
-- Last Change: 13-Aug-2013.
-- License: MIT License {{{
-- Copyright (c) 2013 DeaR <nayuri@kuonn.mydns.jp>
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the
-- "Software"), to deal in the Software without restriction, including
-- without limitation the rights to use, copy, modify, merge, publish,
-- distribute, sublicense, and/or sell copies of the Software, and to
-- permit persons to whom the Software is furnished to do so, subject to
-- the following conditions:
--
-- The above copyright notice and this permission notice shall be included
-- in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- }}}
local abbrev_table = {}
function nyaos.command.abbrev(cmd, ...)
if cmd then
local arg = table.concat({...}, ' ')
if arg:len() > 0 then
abbrev_table[cmd] = arg
elseif abbrev_table[cmd] then
print(cmd .. ' ' .. abbrev_table[cmd])
end
else
for k, v in pairs(abbrev_table) do
print(k .. ' ' .. v)
end
end
end
function nyaos.command.unabbrev(cmd)
if cmd then
abbrev_table[cmd] = nil
else
for k, v in pairs(abbrev_table) do
print(k .. ' ' .. v)
end
end
end
function nyaos.keyhook.abbreviations(t)
function _get_expand_param()
for k in string.gmatch(os.getenv('_ABBREV_EXPAND') or '', '[^;]+') do
if t.key == nyaos.key[k] then
return 1
end
end
for k in string.gmatch(os.getenv('_ABBREV_EXPAND_INSERT') or '', '[^;]+') do
if t.key == nyaos.key[k] then
return 2
end
end
for k in string.gmatch(os.getenv('_ABBREV_NO_EXPAND') or '', '[^;]+') do
if t.key == nyaos.key[k] then
return -1
end
end
return 0
end
function _expand(basestring)
for k, v in pairs(abbrev_table) do
if basestring == k then
return v
end
end
end
local expand_param = _get_expand_param()
local basestring = t.text:sub(1, t.pos):match('[^%s]+$')
if expand_param ~= 0 and basestring then
local s = _expand(basestring)
if s then
if expand_param < 0 then
return ' '
end
local ret = {}
for i = 1, #basestring do
table.insert(ret, nyaos.key[os.getenv('_ABBREV_BACKSPACE') or 'BACKSPACE'])
end
table.insert(ret, s)
if expand_param == 2 then
table.insert(ret, t.key)
end
return ret
end
end
end
-- vim: ft=lua

abbreviations.lua

Abbreviations for NYAOS 3.x

Install

  1. Checkout the source from repository

    git clone https://gist.github.com/4631987.git abbreviations
  2. add to _nya

    # set keyname for expand abbrev.
    set _ABBREV_EXPAND=TAB;CTRL_I
    
    # set keyname for expand abbrev & self insert.
    # set _ABBREV_EXPAND_INSERT=SPACE;RETURN;CTRL_M
    
    # set keyname for no expand & insert space.
    # set _ABBREV_NO_EXPAND=CTRL_X
    
    # if you're binding backward-delete-char other keys (default BACKSPACE).
    # set _ABBREV_BACKSPACE=CTRL_H
    
    source abbreviations/abbreviations.lua

Usage

  • abbrev L "| less"
  • cat _nya L and press expand key
  • unabbrev L

Issue

Author

DeaR (nayuri@kuonn.mydns.jp)

@nayuri_aohime

License

Copyright (c) 2013 DeaR <nayuri@kuonn.mydns.jp>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment