-
Notifications
You must be signed in to change notification settings - Fork 3
Can you fix vis tag_jump.lua, I can't sleep lol #2
Copy link
Copy link
Open
Description
More of an obsession than a requirement.
This ctags plugin doesn't work, it just keeps saying tag not found: https://github.com/kupospelov/vis-ctags
Your tag jump plugin (with what I tried to fix) works, but it doesn't jump, it shows me a correct list though.
here's what i have so far. P.s. I'm not a coder. Sorry for any novice mistakes (like preferring one-liners instead of indenting)
--""""""""""""""""""""""
--"""" jt: Tag Jump """"
--""""""""""""""""""""""
-- Created: Fri 13 May 2016
-- Modified: Wed 22 Mar 2017
-- Author: Josh Wainwright
-- Filename: tag_jump.lua
word_at_pos = function(line, pos)
local word_end = line:match('[%w_]+', pos + 1) or ''
local rev_cur_pos = line:len() - pos + 1
local word_start = line:reverse():match('[%w_]+', rev_cur_pos) or ''
local word = word_start:reverse() .. word_end
return word
end
vis:map(vis.modes.NORMAL, 'jt', function() -- <C-]>
local win = vis.win
local line = win.file.lines[win.selection.line] -- [win.cursor.line]
local word = word_at_pos(line, win.selection.col) -- (line, win.cursor.col)
local tags_f = assert(io.open(os.getenv('PWD') .. '/tags', 'r'))
local tag_line = ""
for line in tags_f:lines() do local match = line:find('^' .. word) if match then tag_line = line break end end
local tagname, tagfile, tagaddress = tag_line:match('([^\t]+)\t([^\t]+)\t([^\t]+)')
if not tagname or not tagfile or not tagaddress then vis:info('Tag not found: ' .. word) return end
tagaddress = tagaddress:sub(1,-3)
tagaddress = tagaddress:gsub('([()])', '\\%1')
vis:info('TagJump: ' .. tagname .. ' | ' .. tagfile .. ' | ' .. tagaddress)
vis:command('e ' .. tagfile)
vis:feedkeys(tagaddress .. 'G')
-- vis:feedkeys('<editor-redraw>')
end)
local function showtags(argv, force, win, cursor, range)
local fname = win.file.name
local path = win.file.path
local cmd = 'ctags --output-format=xref --_xformat="%l\t%K\t%n\t%N" --sort=no '
cmd = cmd .. path
local f = assert(io.popen(cmd, 'r'))
local tags = assert(f:read('*a'))
f:close()
vis:message("")
local msg_win = vis.win
msg_win.file:delete(0, msg_win.file.size)
msg_win.file:insert(0, tags)
msg_win:map(vis.modes.NORMAL, '<Enter>', function()
-- local line = msg_win.file.lines[msg_win.cursor.line]
local line = msg_win.file.lines[msg_win.selection.line]
local lang, ttype, line, name = line:match('(%S+)\t(.)\t(%d+)\t(%S)')
local range = {start=0, finish=win.file.size} --
local tag_line = ""
local tagname, tagfile, tagaddress = tag_line:match('([^\t]+)\t([^\t]+)\t([^\t]+)')
local pos = win.selection.pos
-- win.cursor:to(line, 1)
-- win.selection:to(line, 1)
win.selection:to(pos,1)
-- if force then vis:command(':q') end
if force then vis:feedkeys('G') end -- G = top of buffer
-- if force then vis:feedkeys('<editor-redraw>') end
end)
end
vis:command_register("ShowTags", showtags)
--vis:map(vis.modes.NORMAL, '<C-]>', function() showtags(nil, true, vis.win, vis.win.cursor, nil) end)
--vis:map(vis.modes.NORMAL, 'jt', function() vis:feedkeys('<editor-redraw>') showtags(nil, true, vis.win, vis.win.selection, nil) end) -- <C-]>
vis:map(vis.modes.NORMAL, 'jt', function() showtags(nil, true, vis.win, vis.win.selection, nil) end) -- <C-]>
--""""""""""""""""""""""""""
--"""" Original TagJump """"
--""""""""""""""""""""""""""
--[[
-- Created: Fri 13 May 2016
-- Modified: Original
-- Author: Josh Wainwright
-- Filename: tag_jump.lua
word_at_pos = function(line, pos)
local word_end = line:match('[%w_]+', pos + 1) or ''
local rev_cur_pos = line:len() - pos + 1
local word_start = line:reverse():match('[%w_]+', rev_cur_pos) or ''
local word = word_start:reverse() .. word_end
return word
end
jump_tag = function()
local win = vis.win
local line = win.file.lines[win.selection.line] -- [win.cursor.line]
local word = word_at_pos(line, win.selection.col) -- win.cursor.col
local tags_f = assert(io.open(os.getenv('PWD') .. '/tags', 'r')) -- assert(io.open(vis.cwd .. 'tags', 'r'))
local tag_line = ""
for line in tags_f:lines() do local match = line:find('^' .. word) if match then tag_line = line break end end
local tagname, tagfile, tagaddress = tag_line:match('([^\t]+)\t([^\t]+)\t([^\t]+)')
if not tagname or not tagfile or not tagaddress then vis:info('Tag not found: ' .. word) return end
tagaddress = tagaddress:sub(1,-3)
tagaddress = tagaddress:gsub('([()])', '\\%1')
-- vis:info('TagJump: ' .. tagname .. ' | ' .. tagfile .. ' | ' .. tagaddress .. '|')
vis:info('TagJump: ' .. tagname .. ' | ' .. tagfile .. ' | ' .. tagaddress)
vis:command('e ' .. tagfile)
vis:feedkeys(tagaddress .. 'G')
end
vis:map(vis.modes.NORMAL, '<C-]>', jump_tag)
--]]
--""""""""""""""""""""""""""""""""""""""""""
--"""" jl: Line Jump: Find Longest Line """"
--""""""""""""""""""""""""""""""""""""""""""
-- Josh Wainwright. visrc.lua 2017
--vis:command_register('MaxLine', function(argv, force, win, cursor, range)
local function maxline(argv, force, win, cursor, range)
local line
local length_max = 0
local lnum = 0
local range = {start=0, finish=win.file.size}
win.selection.pos = range.start
local start = win.selection.line
win.selection.pos = range.finish
local finish = win.selection.line
for line in win.file:lines_iterator() do lnum = lnum + 1
if lnum > start and lnum < finish then if force then line = line:gsub('\t', ' ') end if #line > length_max then length_max = #line maxl = lnum end end
end
vis:info(('Max line is %i (%i chars)'):format(maxl, length_max)) win.selection:to(maxl, 1)
--end, 'Find the longest line in the current file')
end
vis:command_register("MaxLine", maxline)
vis:map(vis.modes.NORMAL, 'jl', function() maxline(nil, true, vis.win, vis.win.selection, nil) end, 'Find the longest line in the current file') --
--""""""""""""""""""""""""""
--"""" fs.lua Line Jump """"
--""""""""""""""""""""""""""
-- Fri 20 May 2016, Josh Wainwright. fs.lua
--local fs = {}
--fs.maxline = function(win, force)
-- local line
-- local max = 0
-- local cnt = 1
-- for line in win.file:lines_iterator() do if force then vis:info('Force') line = line:gsub('\t', ' ') end
-- if #line > max then max = #line maxl = cnt end
-- cnt = cnt + 1
-- end
-- vis:info('Max line is line ' .. maxl .. ' (' .. max .. ' chars)')
-- win.cursor:to(maxl, 1)
--end
--vis:command_register('MaxLine', function(argv, force, win, cursor, range) fs.maxline(win, force) end)
--return fs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels