[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 Thread Martin Marshall
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 "<>")
  (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/)
>From a6719edafd928a5ce27036be5d5bec00eaafa8ec Mon Sep 17 00:00:00 2001
From: Martin Marshall 
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

-- 
Best regards,
Martin Marshall


Is there something people use instead of org-ctags? (was: [PATCH] `org-ctags-create-tags` creates empty TAGS file)

2024-02-09 Thread Martin Marshall
I was curious how long this bug had been around and why no one
complained about it before.  So I looked through the Git log and found
that it was introduced on 1/18/2010.  That's just over two weeks after
the package was added to Emacs[1]!

Other than a 4 year old Reddit post[2], there've been no bug reports or
mailing list discussions about it in the fourteen years since the bug
was introduced.  This gives me the impression that very few people are
using the org-ctags package.

That's surprising, because it seems like it could be very useful.  It
allows for linking to "direct targets" from external files[3], which is
similar to the "come-from" links that Howm implements.  It's a very
low-effort, low-friction way to add links between different notes.

Is there some other way to create this sort of simple external link in
org-mode?  Is there some other package that provides a similar feature?

[1] Commit 53868111d000302b50706769526f15164600d739
[2] 
https://www.reddit.com/r/emacs/comments/fg71cw/orgctags_failed_to_create_tags/
[3] That look like <>.  See https://orgmode.org/manual/Internal-Links.html

-- 
Best regards,
Martin Marshall



[PATCH] org-ctags: When `ido-mode' is off, use completing-read

2024-02-10 Thread Martin Marshall
>From 24d731457433b333b28845e6140532bad790800e Mon Sep 17 00:00:00 2001
From: Martin Marshall 
Date: Sat, 10 Feb 2024 23:02:34 -0500
Subject: [PATCH] org-ctags: Use `completing-read' if `ido-mode' is off

* org-ctags.el (org-ctags-find-tag-interactive): Only use
`ido-completing-read' if `ido-mode' is enabled, otherwise use
`completing-read'.
---
 lisp/org-ctags.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org-ctags.el b/lisp/org-ctags.el
index 9d9028704..a825bd7cf 100644
--- a/lisp/org-ctags.el
+++ b/lisp/org-ctags.el
@@ -510,7 +510,8 @@ Uses `ido-mode' if available.
 If the user enters a string that does not match an existing tag, create
 a new topic."
   (interactive)
-  (let* ((tag (ido-completing-read "Topic: " org-ctags-tag-list
+  (let* ((compfunc (if ido-mode 'ido-completing-read 'completing-read))
+ (tag (funcall compfunc "Topic: " org-ctags-tag-list
nil 'confirm nil 'org-ctags-find-tag-history)))
 (when tag
   (cond
-- 
2.39.2


Here's another patch for org-ctags.el.

`org-ctags-find-tag-interactive' uses `ido-completing-read' for
selecting and jumping to a target.

This patch makes it use `completing-read' instead, unless the user
enabled `ido-mode'.

-- 
Best regards,
Martin Marshall


[PATCH] org-ctags: Fix regexp to not break radio targets

2024-02-11 Thread Martin Marshall
>From 9b9e8ead6c175c76e4f37273a4e4f29b8e41b4f9 Mon Sep 17 00:00:00 2001
From: Martin Marshall 
Date: Sun, 11 Feb 2024 12:36:46 -0500
Subject: [PATCH] org-ctags: Fix regexp to not break radio-target links

* org-ctags.el (org-ctags-tag-regexp): Add left angle-bracket to
excluded characters for tag text.
---
 lisp/org-ctags.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-ctags.el b/lisp/org-ctags.el
index e56ed9cd8..6431a2765 100644
--- a/lisp/org-ctags.el
+++ b/lisp/org-ctags.el
@@ -149,7 +149,7 @@
 (defvar org-ctags-enabled-p t
   "Activate ctags support in org mode?")
 
-(defvar org-ctags-tag-regexp "/<<([^>]+)>>/\\1/d,definition/"
+(defvar org-ctags-tag-regexp "/<<([^<>]+)>>/\\1/d,definition/"
   "Regexp expression used by ctags external program.
 The regexp matches tag destinations in Org files.
 Format is: /REGEXP/TAGNAME/FLAGS,TAGTYPE/
-- 
2.39.2

This updates `org-ctags-tag-regexp' to avoid adding broken entries for
radio targets in the TAGS file.

With the old regexp, org-ctags would add radio targets to the TAGS file
with an extra angle bracket at the beginning.  So a target of
"<<>>" would be entered in the TAGS file as
"

Re: [PATCH] org-ctags: Fix regexp to not break radio targets

2024-02-12 Thread Martin Marshall
Ihor Radchenko  writes:

> Applied, onto main, with amendments to the commit message.
> I added a TINYCHANGE cookie and linked to this thread.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=38dd88268

Thanks!  I just noticed that org-ctags breaks CUSTOM_ID property links
in the same way.  So I might submit a patch for that as well soon.

-- 
Best regards,
Martin Marshall



Re: [PATCH] org-ctags: Fix regexp to not break radio targets

2024-02-12 Thread Martin Marshall
Ihor Radchenko  writes:
> I also see that you submitted a number of patches recently.
> For now, your contribution size is fairly small, but if you plan to
> contribute a lot more, please consider signing FSF copyright assignment.
> See https://orgmode.org/worg/org-contribute.html#copyright

Thanks, I submitted a copyright assignment a year or two ago with
respect to a pull-request submitted for the which-key package.  Not sure
if it's project-specific, or if I'll need to submit a separate one
(which I'm happy to do of course).

-- 
Best regards,
Martin Marshall



Re: [PATCH] org-ctags: Fix regexp to not break radio targets

2024-02-12 Thread Martin Marshall
Ihor Radchenko  writes:

> If your assignment has "GNU Emacs" in it, you are good to go.

Just found the scanned copy.  It refers to "GNU EMACS (herein called
the Program)" in paragraph 1.(a).  :-D

Also, in case it helps locate it, there is "RT:1798288" under my name on
the first page.  And the date of my signature is "January 29, 2022".
This copy doesn't have the Deputy Director's signature.

-- 
Best regards,
Martin Marshall



Re: [BUG] Unable to use Completions buffer with org-goto-interface set to outline-path-completion [9.7.25 (9.7.25-bdf9f94 @ /home/martin/emacs-work/elpa/org-9.7.25/)]

2025-03-16 Thread Martin Marshall
Ihor Radchenko  writes:

> Fixed, on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6daeb5da62

Confirmed.  Thank you, Ihor!

-Martin



[BUG] Unable to use Completions buffer with org-goto-interface set to outline-path-completion [9.7.25 (9.7.25-bdf9f94 @ /home/martin/emacs-work/elpa/org-9.7.25/)]

2025-03-15 Thread Martin Marshall
Hello, I'm noticing a problem with the `org-goto` command when used with
`org-goto-interface` set to `outline-path-completion`.

I use the standard "*Completions*" buffer for completion, so I would
like to leave the setting of `org-outline-path-complete-in-steps` at its
default (t).

But I've found that I'm unable to complete with `org-goto` if I select
an item in the Completions buffer.  This is because as soon as I
select a heading in the Completions buffer, the text that I entered
in the minibuffer is duplicated, so the Completion doesn't match.

Steps to reproduce:
1. Start Emacs with "emacs -Q"
2. In the scratch buffer, evaluate:
   (setopt org-goto-interface 'outline-path-completion)
3. Open an Org-mode file that has multiple headings with the same
   starting character(s).
4. Enter "C-c C-j" to invoke `org-goto`
5. Enter some text that matches multiple headings, and press "TAB"
6. Attempt to complete from the Completions buffer with "M-"
7. Notice that as soon as you highlight any of the headings listed in
   the Completions buffer, the text you typed in the minibuffer
   appears twice.

For example, if you type "Emacs", press TAB and attempt to select the
heading "Emacs Usage" in the Completions buffer by pressing
"M-", the text after the minibuffer prompt will be
"EmacsEmacs Usage", which doesn't match any headings.

You will not be able to complete without manually deleting the
duplicated text.

With warm regards and gratitude,
Martin Marshall





Emacs  : GNU Emacs 30.1 (build 2, x86_64-pc-linux-gnu, X toolkit,
cairo version 1.16.0, Xaw3d scroll bars)
 of 2025-02-27, modified by Debian
Package: Org mode version 9.7.25 (9.7.25-bdf9f94 @
/home/martin/emacs-work/elpa/org-9.7.25/)

current state:
==
(setq
 org-special-ctrl-a/e '(reversed . t)
 org-yank-image-file-name-function 'org-yank-image-autogen-filename
 org-persist-before-write-hook '(org-element--cache-persist-before-write)
 org-log-into-drawer t
 org-list-demote-modify-bullet '(("-" . "+") ("+" . "*") ("*" . "-")
("a." . "1.") ("1." . "A.") ("A." . "a.") ("a)" . "1)") ("1)" . "A)")
("A)" . "a)"))
 org-speed-command-hook '(org-speed-command-activate
org-babel-speed-command-activate)
 org-persist-after-read-hook '(org-element--cache-persist-after-read)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-log-done 'time
 org-blank-before-new-entry '((heading) (plain-list-item))
 org-mode-hook '(org-tempo-setup
 #[0
   "\305\306
 >\203\0\307\n\310\311#\210\307 \312\313#\210\307 \314\315#\210\306
 >\203,\0\307\n\316\317#\210\307\n\320\321#\210\322
 >\203>\0\307 \323\324#\210\307 \325\324#\210\326
 >\203P\0\307\n\327\317#\210\307\n\330\321#\210\331
 >\203_\0\332\311\f\333BC\334#\210\335
 >\203k\0\332\311\336\334#\210\337
 >\203w\0\332\311\340\334#\210\341\342\343\344#\207"

 [org-mouse-context-menu-function
  org-mouse-features org-mouse-map org-mode-map org-outline-regexp
 org-mouse-context-menu context-menu org-defkey [mouse-3] nil
 [mouse-3]
  org-mouse-show-context-menu [down-mouse-1] org-mouse-down-mouse
 [C-drag-mouse-1] org-mouse-move-tree [C-down-mouse-1]
 org-mouse-move-tree-start yank-link
  [S-mouse-2] org-mouse-yank-link [drag-mouse-3] move-tree
 [drag-mouse-3] [down-mouse-3] activate-stars font-lock-add-keywords
  (0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
 'prepend) t activate-bullets
  (("^[ ]*\\([-+*]\\|[0-9]+[.)]\\) +" (1 `(face org-link
 keymap ,org-mouse-map mouse-face highlight) 'prepend)))
 activate-checkboxes
  (("^[ ]*\\(?:[-+*]\\|[0-9]+[.)]\\)[
 ]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][   ]*\\)?\\(\\[[- X]\\]\\)"
(1 `(face nil keymap ,org-mouse-map mouse-face highlight)
 prepend))
   )
  advice-add org-open-at-point :around org--mouse-open-at-point] 4]
 #[0 "\300\301\302\303\304$\207" [add-hook
  change-major-mode-hook org-fold-show-all append local] 5]
 #[0 "\300\301\302\303\304$\207" [add-hook
  change-major-mode-hook org-babel-show-result-all append local] 5]
  org-babel-result-hide-spec
 org-babel-hide-all-hashes variable-pitch-mode
abbrev-mode flyspell-mode)
 org-hide-emphasis-markers t
 org-use-speed-commands t
 org-support-shift-select 'always
 org-refile-targets '((org-agenda-files :maxlevel . 2))
 org-confirm-shell-link-function 'yes-or-no-p
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-blocker-hook '(org-block-todo-from-children-or-siblings-or-parent)
 o