nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] [RFC] Improve nano's completion feature to use external


From: Marco Diego Aurélio Mesquita
Subject: Re: [Nano-devel] [RFC] Improve nano's completion feature to use external sources of completion
Date: Fri, 18 May 2018 21:21:19 -0300

On Fri, May 18, 2018 at 6:17 PM, Brand Huntsman <address@hidden> wrote:
> On Fri, 18 May 2018 12:31:05 -0300
> Marco Diego Aurélio Mesquita <address@hidden> wrote:
>
>> Judging by
>> https://lists.gnu.org/archive/html/nano-devel/2016-12/msg00016.html
>> there is interest in an improved version of nano's completion feature
>> to include external sources of completion.
>>
>>   pletion grep $shard /usr/share/dict/words
>
> Would be better if nano could load a ctags index, even if it only supports 
> the tagname (ignore everything on line after a tab). Scan up the directory 
> tree for a tags file and load if found. A syntax could also reference a ctags 
> file (generated from include files) that is always loaded in addition to the 
> one found. Allow the ctags command to be used multiple times in a syntax, to 
> load multiple tag files. It could easily reference a dictionary file as well, 
> and a symlink from a tags file (in directory tree) to a dictionary would also 
> work.
>
> From https://en.wikipedia.org/wiki/Ctags
> "
> The tags file is a list of lines, each line in the format:
> {tagname}<Tab>{tagfile}<Tab>{tagaddress}
> "
>

See the attached patch. Replacing "/usr/share/dict/words" by "tags"
does the trick. There are two good reasons to get the dictionary from
an external command:
  1 - it is simpler than parsing a tags file and
  2 - it is future proof. We can easily add support for cscope or a
language server if so we want.

> A later feature could add support for tagfile/tagaddress and a key to find 
> word under cursor and jump to it in current buffer or open its file in 
> another buffer.
>

Surprise: we already have that feature! An unintended consequence of
having pre-recorded macros is that (combined with the linter feature)
it makes for a reasonably good source code navigation tool. Add the
following lines to your .nanorc:

  # Experiments for code navigation
  set wordchars "_"
  set afterends
  extendsyntax c linter ./navigate.sh
  bind M-1 "^][1;5D^[a^[[1;5C^[6^R^Xgrep ^U tags > found_tags^M^T" main

The file "navigate.sh" should be 'chmod +x' and its contents are just:

  #!/bin/bash

  cat found_tags

And the tags file is generated by:

  ctags -x src/*.[ch]|awk '{print $4":"$3": "$1}'> tags

Now, with the cursor in a symbol, M-1 will navigate you through the
source to the declaration of that symbol.

And that is it. With just a few tweaks we can have a simple,
lightweight and high quality source navigation AND completion. So,
please tell me: what do you think is the best way to arrange the
arguments that will be passed to the external completion command?

Attachment: complete.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]