universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.59k stars 629 forks source link

[RFC] readtags: introducing macros #4075

Open masatake opened 2 months ago

masatake commented 2 months ago

I'm enjoying using -Q.

However, writing a long S expression on CLI is painful. Writing completion rules in zsh is a choice, but I don't have enough time.

So I'm thinking about the standard way of lisp programmer: introducing macros.

$ cat ~/extern.es
;; -*- emacs-lisp -*- supports regex literals.
(defmacro +extern? ((input :string))
  (and (subst? $input input)
       (#/func.*|var.*/ $kind)
       (or (#/extern/ (or ($ "properties") ""))
           (and (not (#/static/ (or ($ "properties") "")))
                (not (#/fileScope|reference|inputFile/ (or $extras "")))))))
$ readtags --rc ~/extern.es -Q '(+extern? "foo.c")' -l
...

This one is for extracting exported names in C source files.

The + prepended to extern? represents a request for the macro expansion. With this prefix, we can avoid conflict between user-defined macros and the built-ins we will introduce.

@AmaiKinono, I would like to hear your comments.

AmaiKinono commented 2 months ago

I don't use -Q directly so I can't say I have a good understanding of this proposal, but it do look useful for power users.

In https://github.com/universal-ctags/citre/issues/172 I planned to create an interactive tool to filter a tags file. I think I should support using filter/sorter expressions directly so power users could combine user-defined macros with the convenience of a client tool.