emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Visuwesh <visuweshm@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [BUG] org-id-find might change the major-mode of a buffer [9.8-pre (release_9.7.8-713-g62cbac @ /home/viz/lib/emacs/straight/build/org/)]
Date: Thu, 19 Sep 2024 20:44:14 +0530	[thread overview]
Message-ID: <871q1fhe0p.fsf@gmail.com> (raw)
In-Reply-To: <87ikuuwmz4.fsf@gmail.com> (Visuwesh's message of "Tue, 17 Sep 2024 16:44:55 +0530")

[செவ்வாய் செப்டம்பர் 17, 2024] Visuwesh wrote:

> Remember to cover the basics, that is, what you expected to happen and
> what in fact did happen.  You don't know how to make a good report?  See
>
>      https://orgmode.org/manual/Feedback.html#Feedback
>
> Your bug report will be posted to the Org mailing list.
> ------------------------------------------------------------------------
>
> Hello,
>
> I have code in my init that calls org-id-find to get the entry ID refers
> to.  When the ID is non-existent, the function unintentionally changes
> the major-mode of the current buffer.
> [ This almost caused me to lose a PDF file, but thankfully I could
>   recover it because of Emacs backup.  Admittedly this happened because
>   I was half-panicking and half-confused.  ]
>
> To reproduce,
>
>     1. emacs -Q
>     2. M-: (require 'org-id)
>     3. Visit any file (M-x find-library RET org-id RET)
>     4. M-: (org-id-find "non-existent")
>     5. Witness the major-mode change
>
> This all happens in org-id-find-id-in-file where when VISITING is
> non-nil, the buffer is (re)used whether or not it was originally in
> org-mode.  The problem is complicated by the use of find-file-noselect
> when MARKERP argument to org-id-find is non-nil.  Perhaps,
> org-id-find-id-file should check if the current-buffer is derived from
> org-mode before returning the buffer-file-name. WDYT?

The patch below is what I had in mind.  With it, I can no longer
reproduce the recipe above.

diff --git a/lisp/org-id.el b/lisp/org-id.el
index e247fab1d..17568ab31 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -705,8 +705,9 @@ (defun org-id-find-id-file (id)
 	   (hash-table-p org-id-locations)
 	   (gethash id org-id-locations))
       ;; Fall back on current buffer
-      (buffer-file-name (or (buffer-base-buffer (current-buffer))
-			    (current-buffer)))))
+      (when (derived-mode-p 'org-mode)
+        (buffer-file-name (or (buffer-base-buffer (current-buffer))
+			      (current-buffer))))))
 
 (defun org-id-find-id-in-file (id file &optional markerp)
   "Return the position of the entry ID in FILE.


  reply	other threads:[~2024-09-19 15:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17 11:14 [BUG] org-id-find might change the major-mode of a buffer [9.8-pre (release_9.7.8-713-g62cbac @ /home/viz/lib/emacs/straight/build/org/)] Visuwesh
2024-09-19 15:14 ` Visuwesh [this message]
2024-09-22  8:01   ` Ihor Radchenko
2024-09-22  9:09     ` Visuwesh
2024-09-22 10:42       ` Ihor Radchenko
2024-09-22 11:13         ` Visuwesh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871q1fhe0p.fsf@gmail.com \
    --to=visuweshm@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).