On 2023-08-08 10:48, Ihor Radchenko wrote:
The situation is a bit more complex.
To make it even more complex, here a different point of view. Sorry, I don't have any earlier mails ready I could reply to ... * TL;DR Probably the problem is not the side-effects done by loading =org-ctags=, but rather that these hook function from =org-ctags= try to do their job when the environment is not really ready for them, i.e. when there is no known tag file around. * Full Story I tried to get this thing running. Some issues and observations I came across: 1. When I execute function `org-ctags-create-tags' in file =org-manual.org= of Org =main=, an empty =TAGS= file gets created. Presumably because the asterisk in the generated command line is quoted and the warning generated by that (=cannot open source file "/home/jschmidt/work/org-mode/doc/*"=) is not shown in Emacs: #+begin_example ctags-exuberant --langdef=orgmode --langmap=orgmode:.org \ --regex-orgmode="/<<([^>]+)>>/\1/d,definition/" \ -f "/home/jschmidt/work/org-mode/doc/TAGS" -e -R \ "/home/jschmidt/work/org-mode/doc/*" ^^^ ^^^ #+end_example If I execute the statement on the command line w/o the quotes on the final parameter, I get a non-empty =TAGS= file. Besides that, I somehow doubt that =-R .../*= (=-R= meaning recursive operation) makes actually sense, this probably should be just =-R ...= instead. Besides *that* the following sexps from the function look fishy: #+begin_src emacs-lisp (expand-file-name (concat dir-name "/TAGS")) (expand-file-name (concat dir-name "/*")) #+end_src Why not =(expand-file-name "TAGS" dir-name)=? 2. When one looks at the =TAGS= file generated thus, one immediately notices that the regular expression from parameter =--regex-orgmode= used to match these <<targets>> matches also non-targets, like in the following example section: #+begin_example 1. one item 2. <<target>>another item Here we refer to item [[target]]. #+end_example But that is probably intentional or not avoidable. Probably these are even valid Org targets? Ok, that was more or less cheap criticism. Or a bug report? Anyway, what is more interesting is: 3. When one later visits =org-manual.org=,\\ and there is a =TAGS= file in that directory,\\ and =org-ctags= previously has been loaded, then,\\ by virtue of the following snippet from =org-ctags.el=: #+begin_src emacs-lisp (add-hook 'org-mode-hook (lambda () (when (and org-ctags-enabled-p (buffer-file-name)) ;; Make sure this file's directory is added to default ;; directories in which to search for tags. (let ((tags-filename (expand-file-name (concat (file-name-directory (buffer-file-name)) "/TAGS")))) (when (file-exists-p tags-filename) (visit-tags-table tags-filename)))))) #+end_src that =TAGS= file gets automatically visited, meaning that future tag look-ups with =C-c C-o= do not ask about any tag files to load. (Yes, there is again that funny =(expand-file-name (concat ...))= pattern used above.) 4. From that and also from the header documentation: #+begin_example ;; When you click on a link "[[foo]]" and org cannot find a ;; matching "<<foo>>" in the current buffer, the tags ;; facility will take over. The file TAGS in the active ^^^^^^^^^^^^^^^^^^^^^^^ ;; directory is examined to see if the ^^^^^^^^^ ;; tags facility knows about "<<foo>>" in any other files. ;; If it does, the matching file will be opened and the ;; cursor will jump to the position of "<<foo>>" in that ;; file. #+end_example I conclude that the whole =org-ctags= functionality is based on the assumption that a =TAGS= file lives in the working directory of the currently visited Org mode file. Why not test for that condition in the hook functions: #+begin_src emacs-lisp org-ctags-find-tag org-ctags-ask-rebuild-tags-file-then-find-tag org-ctags-rebuild-tags-file-then-find-tag org-ctags-ask-append-topic org-ctags-append-topic org-ctags-ask-visit-buffer-or-file org-ctags-visit-buffer-or-file org-ctags-fail-silently #+end_src in some way or other, probably also testing variable =tags-file-name=, and just skip their execution returning =nil=, if the environment does not seem to be ready for a tag search. Then regular link operation would kick in. Of course, that is all based on educated guesses and ad-hoc poking in the code, not on long-term usage. Is there a known user of =org-ctags= who one could ask? I think the number of people using =org-ctags= is much smaller than the number of people not using it, in particular because of the issue described in the first item. If above assumption is true and hook functions get wrapped as indicated, we could keep the former happy without affecting the latter with unexpected and inexplicable tag file prompts.