Skip to content

A zsh language definition for Ctags wrapped in tags Make target#332

Merged
vladdoster merged 5 commits intozdharma-continuum:mainfrom
psprint:ctags-targets
Sep 19, 2022
Merged

A zsh language definition for Ctags wrapped in tags Make target#332
vladdoster merged 5 commits intozdharma-continuum:mainfrom
psprint:ctags-targets

Conversation

@psprint
Copy link
Contributor

@psprint psprint commented Jul 7, 2022

Just run make tags (or more specific targets: tags-vim, tags-emacs) to
obtain a dictionary of all functions and variables.

This can be very handy, especially with a good editor. Features of Universal Ctags are very heavily utilized, although old Exuberant Ctags is also supported. I've created a Zsh language definition with use of pcre regexps, so be sure to compile this feature into universal ctags.

PS. UPDATE: A recipe to install universal ctags 🤣 zinit has the best support and delivery 😄:

zinit id-as null configure'#' make'install' \
        for universal-ctags/ctags

Update 2: Also a recipe for pcre2-8 which can be used with uni-ctags – easy dizzy – only changed the repo ID 😄:

zinit id-as null configure'#' make'install' \
          for PCRE2Project/pcre2

Update 3: Turns out that the regexes are compatible with regular {extended} regex engine that's almost certainly built with ctags, so no need for pcrer2 to utilize the 1700 symbols that this setup digs out from zinit sources 😆 .

Description

Motivation and Context

Related Issue(s)

Usage examples

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

psprint added 2 commits July 7, 2022 10:33
Run `make tags` (or more specific targets: tags-vim, tags-emacs) to
obtain a dictionary of all functions and variables.
@psprint
Copy link
Contributor Author

psprint commented Jul 14, 2022

Here is a presentation of the tags usage in my mcedit fork neomcedit: https://asciinema.org/a/SuGXSc7U0Mx9dhHtcd0DEjRJg

There are 1700 symbols in the index 😄

Comment on lines +20 to +51
tags: tags-emacs tags-vim

# Build only the Emacs-style `TAGS` file.
tags-emacs:
@if type ctags >/dev/null 2>&1; then \
if ctags --version | grep >/dev/null 2>&1 "Universal Ctags"; then \
ctags -e -R --options=share/zsh.ctags --languages=zsh \
--pattern-length-limit=250 --maxdepth=1; \
else \
ctags -e -R --languages=sh --langmap=sh:.zsh; \
fi; \
printf "Created the Emacs \`TAGS\` file.\\n"; \
else \
printf 'Error: Please install a Ctags (e.g.: either the Exuberant or Universal %b' \
'version) utility first.\n'; \
fi

# Build only the Vim-style `tags` file.
tags-vim:
@if type ctags >/dev/null 2>&1; then \
if ctags --version | grep >/dev/null 2>&1 "Universal Ctags"; then \
ctags -R --options=share/zsh.ctags --languages=zsh \
--pattern-length-limit=250 --maxdepth=1; \
else \
ctags -R --languages=sh --langmap=sh:.zsh; \
fi; \
printf "Created the Vim's style \`tags\` file.\\n"; \
else \
printf 'Error: Please install a Ctags (e.g.: either the Exuberant or Universal %b' \
'version) utility first.\n'; \
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this would be more appropriate under a zi sub-command.

zi tags (--all|--vim|--emacs)

This lets us utilize zi output formatting and doesn't clutter the Makefile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a misuse of Make, IMHO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already is tags target in the Makefile that tries to use etags command so I would tell that it's ok to use Makefile for this (hence the duplication probably). But I can change to zi if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, no previous tags target in existing Makefile – what I meant is that Automake projects have such targets (tags, ctags and other) created automatically for C,C++ and Fortran projects, see this page for details. is this a sufficient reassurance that Makefile is the correct place for ctags invocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladdoster: What do you think, should the zi subcommand be created, or can it be in Makefile?

@psprint
Copy link
Contributor Author

psprint commented Jul 20, 2022

@vladdoster: Check this out – a browsable/searchable TAGS popup-menu, allowing quick jumping to a specific function or variable definition: https://asciinema.org/a/4zNRsZo6saHDu2ImCC5Cziiqq
I've just added commit with the feature. Color flickers a little at startup, but the rest works fine.

@psprint psprint closed this Aug 13, 2022
@psprint psprint reopened this Sep 8, 2022
@psprint
Copy link
Contributor Author

psprint commented Sep 8, 2022

I've now got time to work on the pr so I reopened it.

@psprint
Copy link
Contributor Author

psprint commented Sep 10, 2022

I've solved the incorrect highlighting, everything works OK (see a cast: https://asciinema.org/a/JaVB2yqHn8RC7nalwYXQu0L1B).

I wonder if such feature, making zinit a part of programmers' stack, have chance of merging? That's the obstacle – do we want to add a subtle, general programming appearance to zinit?

@psprint psprint force-pushed the ctags-targets branch 2 times, most recently from bc85b33 to d9e149c Compare September 10, 2022 07:44
@psprint
Copy link
Contributor Author

psprint commented Sep 17, 2022

Hi guys @vladdoster @pschmitt @alichtman.
I would like to give some motion to this PR. I think that it's interesting to try to give zinit some software engineering rite. With these changes zinit becomes an additional, fairly unexpected tool in dev stack – ability to jump open a symbol right from the command line… What is your opinion?

Here is current state of it: https://asciinema.org/a/4WPnH3shbu7tQoVehpCVNAwid

@psprint psprint force-pushed the ctags-targets branch 2 times, most recently from 6b31d35 to 0354db0 Compare September 18, 2022 14:34
@psprint
Copy link
Contributor Author

psprint commented Sep 18, 2022

A new sub-feature: ability to switch to a function-only kind listing of the symbols, see: https://asciinema.org/a/Zffgvk1yEevU5GhRzXp8Ig6fg

…OR on enter

It's possible to jump directly from the shell to a specific function or
variable definition, for example. TAGS from current $PWD is being read.
It can hold any symbols for any programming language supported by Exuberant
Ctags or Universal Ctags (recommended).
@psprint
Copy link
Contributor Author

psprint commented Sep 19, 2022

@vladdoster, @pschmitt, @alichtman, @jankatins Check this out – a basic synatx highlighting in the symbol popup menu: https://asciinema.org/a/4lG1v1wYMRG8wmA3GMtWZfewY

Does this PR have a chance of merging?

@vladdoster vladdoster merged commit 17fd453 into zdharma-continuum:main Sep 19, 2022
@psprint
Copy link
Contributor Author

psprint commented Sep 19, 2022

thanks! zinit is now also a software engineering aid tool :) I wonder if there are some other such features.

psprint added a commit to psprint/.priv-zinit-fork that referenced this pull request Sep 20, 2022
@github-actions
Copy link

github-actions bot commented Nov 7, 2022

🎉 This PR is included in version 3.8.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

psprint added a commit to psprint/.priv-zinit-fork that referenced this pull request Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants