all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] `org-ctags-create-tags` creates empty TAGS file [9.6.15 (release_9.6.15 @ /home/martin/Projects/emacs/lisp/org/)]
@ 2024-02-09 23:57 Martin Marshall
  2024-02-10  4:49 ` Is there something people use instead of org-ctags? (was: [PATCH] `org-ctags-create-tags` creates empty TAGS file) Martin Marshall
  2024-02-10 14:27 ` [PATCH] `org-ctags-create-tags` creates empty TAGS file [9.6.15 (release_9.6.15 @ /home/martin/Projects/emacs/lisp/org/)] Ihor Radchenko
  0 siblings, 2 replies; 25+ messages in thread
From: Martin Marshall @ 2024-02-09 23:57 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2317 bytes --]

Hi, the docstring of `org-ctags-create-tags` says it should "(Re)create
tags file in the directory of the active buffer," creating tags from the
internal links found in the org files.  However, it always creates an
empty TAGS file.

The cause appears to be a pair of escaped quotes used with
`shell-command` when it calls the "ctags" executable.

* Re-creating the issue

1. First, as explained in the commentary of "org-ctags.el", make sure
you have exuberant-ctags installed on your system.  On a debian-based
system, like so...

--8<---------------cut here---------------start------------->8---
sudo apt install exuberant-ctags
--8<---------------cut here---------------end--------------->8---

2. Start Emacs from the command-line with "emacs -Q".

3. In the "*scratch*" buffer, paste the expression shown below.

--8<---------------cut here---------------start------------->8---
(let* ((testdir (expand-file-name "test1234xyz" "~"))
       (orgfile (expand-file-name "test-file.org" testdir))
       (tagsfile (expand-file-name "TAGS" testdir)))
  (unless (file-exists-p testdir)
    (make-directory testdir))
  (find-file orgfile)
  (insert "<<test link>>")
  (save-buffer)
  (require 'org-ctags)
  (org-ctags-create-tags testdir)
  (find-file tagsfile))
--8<---------------cut here---------------end--------------->8---

4. If you evaluate the above code.  It creates the "~/test1234xyz"
directory, an org file containing a link, and a new TAGS file.

It also opens the new TAGS file.  But as you can see, it's empty.

* Cause

The cause appears to be some escaped quotes around a shell command
argument.  The FILES argument passed to the "ctags" executable uses
globbing.  But since it's surrounded by double quotes, no globbing
occurs, and "ctags" doesn't actually scan any files.

If we change this:
                    "--regex-orgmode=\"%s\" -f \"%s\" -e -R \"%s\"")

To this:
                    "--regex-orgmode=\"%s\" -f \"%s\" -e -R %s")

It works as expected.

I've attached a patch against the current Emacs master branch.  I hope
that's sufficient, given the minimal nature of the change.


Emacs  : GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0)
 of 2024-02-09
Package: Org mode version 9.6.15 (release_9.6.15 @ /home/martin/Projects/emacs/lisp/org/)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix for org-ctags-create-tags command --]
[-- Type: text/x-diff, Size: 1067 bytes --]

From a6719edafd928a5ce27036be5d5bec00eaafa8ec Mon Sep 17 00:00:00 2001
From: Martin Marshall <law@martinmarshall.com>
Date: Fri, 9 Feb 2024 17:40:03 -0500
Subject: [PATCH] org-ctags.el: Fix use of "ctags" executable

* lisp/org/org-ctags.el (org-ctags-create-tags): Allow file
globbing in `shell-command' invocation of "ctags".

TINYCHANGE

---
 lisp/org/org-ctags.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org/org-ctags.el b/lisp/org/org-ctags.el
index 2417353ee5d..9e523e7dc67 100644
--- a/lisp/org/org-ctags.el
+++ b/lisp/org/org-ctags.el
@@ -486,7 +486,7 @@ org-ctags-create-tags
       (setq exitcode
             (shell-command
              (format (concat "%s --langdef=orgmode --langmap=orgmode:.org "
-                             "--regex-orgmode=\"%s\" -f \"%s\" -e -R \"%s\"")
+                             "--regex-orgmode=\"%s\" -f \"%s\" -e -R %s")
                      org-ctags-path-to-ctags
                      org-ctags-tag-regexp
                      (expand-file-name (concat dir-name "/TAGS"))
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 34 bytes --]

-- 
Best regards,
Martin Marshall

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2024-05-01 13:57 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-09 23:57 [PATCH] `org-ctags-create-tags` creates empty TAGS file [9.6.15 (release_9.6.15 @ /home/martin/Projects/emacs/lisp/org/)] Martin Marshall
2024-02-10  4:49 ` Is there something people use instead of org-ctags? (was: [PATCH] `org-ctags-create-tags` creates empty TAGS file) Martin Marshall
2024-02-10 14:29   ` Ihor Radchenko
2024-02-10 14:27 ` [PATCH] `org-ctags-create-tags` creates empty TAGS file [9.6.15 (release_9.6.15 @ /home/martin/Projects/emacs/lisp/org/)] Ihor Radchenko
2024-02-10 21:10   ` Morgan Willcock
2024-02-10 21:20     ` Ihor Radchenko
2024-03-19 10:21     ` Max Nikulin
2024-03-20 12:08       ` Ihor Radchenko
2024-04-28  7:37         ` [PATCH] org-ctags.el: Protect shell specials in directory name Max Nikulin
2024-04-28 12:53           ` Ihor Radchenko
2024-04-28 16:51             ` Max Nikulin
2024-04-28 16:55               ` Ihor Radchenko
2024-04-28 16:58                 ` Max Nikulin
2024-04-28 17:02                   ` Ihor Radchenko
2024-04-29 10:26                     ` Max Nikulin
2024-04-29 13:12                       ` Ihor Radchenko
2024-04-29 16:54                         ` [PATCH] org-ctags.el: Do not activate on load Max Nikulin
2024-04-30 10:02                           ` Ihor Radchenko
2024-04-30 11:20                             ` [PATCH] org.el: Call EXT-enable for `org-modules' (was Re: [PATCH] org-ctags.el: Do not activate on load) Max Nikulin
2024-05-01 10:21                               ` Ihor Radchenko
2024-05-01 11:38                                 ` Max Nikulin
2024-05-01 13:57                                   ` Ihor Radchenko
2024-04-30 12:59                             ` [PATCH] org-ctags.el: Do not activate on load Ihor Radchenko
2024-04-30 13:37                               ` Max Nikulin
2024-04-30 15:31                                 ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.