From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id GI31IxhH7GY+igAA62LTzQ:P1 (envelope-from ) for ; Thu, 19 Sep 2024 15:45:28 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id GI31IxhH7GY+igAA62LTzQ (envelope-from ) for ; Thu, 19 Sep 2024 17:45:28 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DsWvwFgR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1726760728; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=RxMSvgp8CFeCQJ06O4HrETh273wqMxhZjlhgsO2if5k=; b=a7phaN2KZZB1I454C4DYBDEtoLm/WCl6yr0ytiFDYI8H4GuK3zuxJ4TPO+sQVk+zkRwjUX vEjOOMwLO7vEsV1t12Tl0esYgR612HnmL8oGBM4WXib8Uy9LBxvOXGwIVVVhh75WV+/IJi JbafUqZmDY5Bx+nq3T6rGbrNx3ky0iwZRXuO/2BiiG78Emr1BHHe1oJUfh19yyVw8DRrqK y/OArmRNvVhwK1G2wJGL5Y9hov7TGTMHpJsqdAuCn+pxQM5+IxzeS0hFzStluoZK4236Qk LM+T4VXdFdW14DTT0NpAKj9h3L7T4NQd8NYyiRIGBnMmdAr/l7McPj41vm1kdA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1726760728; a=rsa-sha256; cv=none; b=hWtyXo5eErml8g2uhG4Jtqpg6JsUguIn0rp7KWykYAaIQ+9HEhMp8s48Dmon/kpRvsoGZ/ P5x4qaM2/RwFiPEFvU+ud2M3v1gwxJhI9smM7/W3mwkArtXeihwWqmoc+K22Glg3yDA+a6 2mEl7VKYf4XOr/BdngIuhdizkhn1gi9X/8KC7NsKgmQIEE5/3Y6aiJPC0ZXSVPltoPejfh ChO37jYO982yoGjFlQn0lsV2EVWsiYiybiqqXRc94DOjLB5g5Ybi7YgTXu6L56HgV1uHNw qfsPm7X4WyG0RvXfGwxB5yPjJz6xryH0tKC1LKJNUVd9aaVCpubEakDGKOPy0A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DsWvwFgR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 49FF913D4A for ; Thu, 19 Sep 2024 17:45:28 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srIrV-0005uc-Og; Thu, 19 Sep 2024 11:14:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srIrU-0005p2-AB for emacs-orgmode@gnu.org; Thu, 19 Sep 2024 11:14:28 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1srIrS-00009z-LK for emacs-orgmode@gnu.org; Thu, 19 Sep 2024 11:14:28 -0400 Received: by mail-pj1-x1043.google.com with SMTP id 98e67ed59e1d1-2d889ba25f7so754977a91.0 for ; Thu, 19 Sep 2024 08:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726758864; x=1727363664; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RxMSvgp8CFeCQJ06O4HrETh273wqMxhZjlhgsO2if5k=; b=DsWvwFgRxZbqjtHNepCP5DHTXwlIWWyXCGYzIIfVzkibncp7fP+74WZTGJGk3SerYe iEbgD3JMPgSvo31Tqa1DEbhEGcrY0RNEj0ngS2u+e/oH632HWn/AqhkL22X7epyYzzr6 8DnJ4cFtJEtzY7PoQyK0/WKW8EBF7ivcTJpzSJ+1FfjlaTRqli9MosGGshVCdNLVWRiQ 0m6YlyT1xVR635yl8gE9R1An7xLq0GIJLDdQJCgdieIQgpzVCparwDaRlF/isjuovRA4 eJ98ejgkWhK54QclhsMblC6t4UjuRTCdusfeMK+iupB9S8GoDje1m7R0DnWwN04rUOIl kr0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758864; x=1727363664; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:to:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=RxMSvgp8CFeCQJ06O4HrETh273wqMxhZjlhgsO2if5k=; b=t+29/VE9pe++QBBMN5ZjLTHiPWiZ0oCiqLz1AdoGkymml4q4dGCBZGhfNTpybu+h60 1RJHdYKK7CXCE9dGUShx+0bMnhrL7RvbKSk5g2Cnx6M+oSWjqgwk6+y3wgA06fHgcCN6 +rlOB+K32UmQ3rJFFjjFmn5RCkCarmDwsMUyt+j3SsmjwEZiX0AJFS7AXfs8MKDED/7P xDKeTmVn4exCsptvY7qYTw3v3+G55XjhGi3djnBl1wrswQO3l9be+znMAiUnDjcb0BxS hWRIoid7qj2wtXSSZsysnkVGK/UCMvgsi0bdPRYM29bqN3AKALkI1ehmXxbmefx4YjGN DI8w== X-Gm-Message-State: AOJu0Yyp6EkCCs22xyR5xtp/Jkn2gfUjjPHxhJhUedDPDhVwYv5SbU9r VyAg8kCeJOswE7KJ5kRo/mrUMfoIFklWV6wpJX+mEMn+EmIExTxltSCAEZxW X-Google-Smtp-Source: AGHT+IHMcNeMHWbce1fj242fVsZZ48GcRKl6vsE9nbZ3F55J0PKEqq/gz1YAbKuqOTq1Z/ooEtB7+Q== X-Received: by 2002:a17:90a:c784:b0:2c8:e888:26a2 with SMTP id 98e67ed59e1d1-2dbb9df174dmr26916682a91.13.1726758864391; Thu, 19 Sep 2024 08:14:24 -0700 (PDT) Received: from localhost ([115.240.90.130]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dd6eeeae7csm1970575a91.44.2024.09.19.08.14.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:14:23 -0700 (PDT) From: Visuwesh 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/)] In-Reply-To: <87ikuuwmz4.fsf@gmail.com> (Visuwesh's message of "Tue, 17 Sep 2024 16:44:55 +0530") References: <87ikuuwmz4.fsf@gmail.com> Date: Thu, 19 Sep 2024 20:44:14 +0530 Message-ID: <871q1fhe0p.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=visuweshm@gmail.com; helo=mail-pj1-x1043.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -5.61 X-Spam-Score: -5.61 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Queue-Id: 49FF913D4A X-TUID: jClJ8m7a0eHw [=E0=AE=9A=E0=AF=86=E0=AE=B5=E0=AF=8D=E0=AE=B5=E0=AE=BE=E0=AE=AF=E0=AF=8D = =E0=AE=9A=E0=AF=86=E0=AE=AA=E0=AF=8D=E0=AE=9F=E0=AE=AE=E0=AF=8D=E0=AE=AA=E0= =AE=B0=E0=AF=8D 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)))))) =20 (defun org-id-find-id-in-file (id file &optional markerp) "Return the position of the entry ID in FILE.