From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id GIwJOTydFWbuUAEAe85BDQ:P1 (envelope-from ) for ; Tue, 09 Apr 2024 21:55:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id GIwJOTydFWbuUAEAe85BDQ (envelope-from ) for ; Tue, 09 Apr 2024 21:55:41 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c0RLTy07; 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-Seal: i=1; s=key1; d=yhetil.org; t=1712692540; a=rsa-sha256; cv=none; b=aWpDbXjx/kW4P/BCgfsvXEAWnokyPRVt4Zkz7Shgpv6PRPEHBPVMytbf92ZDBrhFCjkzW+ ESOLrOWb/KMufA0OGqxoORY1tk2NVBUfm4SnZLrzvPJw7RfBr3iwuwAp9tsVwVoY0dgJ1y qigibV4TtrQW+SYpiVo7Shq5yqlcp8XSRRzB2Cy1CCQVPw4gQ/CUUJQtPR1gWSc27VyVop YeJMOWfgdRxZOqUmUHh26yRZQjIRRslkPP8J/BRrwBQ5XjMNPue7BE+AOyLFfoAhJuM5+e F9e8XPYv+YDTjYZfza4GFP9TUETClhQ9JX5FXdOGJuYZkTjB4D8tMXE3z5dijw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=c0RLTy07; 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=1712692540; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=9MAKNoeLgLMHgXi2p7yGv0Y+sXP1E+36iueLtKf0yhg=; b=ZDJe+cBDa8281dXZCdpDkISgHknvG23r4xybErPgB24HuA/MiO4ot2eTYdfQ5HRU8OJ0lP 6NWM0dp44MK0EVrUQTjpys3fTnKhR7Ku7TfAtekMdNRHlmXcDTSqOObKF0wDx7h08tnc+7 Nztk9Pbv4StSzxngBSz2snczTkfhlHGr0yWh8BhnN9oMe2rcLeP8aqa9f33pQRQVBvIQVc oLXMZEX7reOhA7j2tzgBjFiapzS/KSqGh4BJ9MPLwuo443oDxCEHBWWWmr8JPZf+6FVLjf VsNKsz5jhoza7fc3/a5+53sCU+cXYXoCHkzcRykqKASwj/Z+eD+/PAzfk2mfFA== 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 7CA18E330 for ; Tue, 9 Apr 2024 21:55:40 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ruHHI-00015X-8q; Tue, 09 Apr 2024 15:37:09 -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 1ruHHF-00014P-2M for emacs-orgmode@gnu.org; Tue, 09 Apr 2024 15:37:05 -0400 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ruHH9-0004ia-4l for emacs-orgmode@gnu.org; Tue, 09 Apr 2024 15:37:04 -0400 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-22a96054726so5201428fac.0 for ; Tue, 09 Apr 2024 12:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712691416; x=1713296216; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=9MAKNoeLgLMHgXi2p7yGv0Y+sXP1E+36iueLtKf0yhg=; b=c0RLTy07woECqPE4gW0rfUbeg1vd+XcH9q8+AGOEBwaCAy0ksj9U8yd5JA3pLHDhtp iJJhL0Lt9bYHBxItXMOukHP5uiIvbPCzKjSHJJeePRtBes1guQEUlU9s+T7VQcxgbyZ/ n8mgU/mSj/j1RBlMeeOl7d5nRmIosuEUmt1mt8eZyd1KgdXMMJYvpHjsHqooKfIXoV3H b0qV9P+IlOJBBWhfG1qpMG+L9DdHqFPmfDwF50vtr0eEcHc74A9eEnqfk+fMEgInAggB yVbQAN12Q8DIPk9f15wi05eS/bOpwIK4WWbXAghywTiBBZJswq1pbLN1NRId0pOvojR9 GNTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712691416; x=1713296216; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9MAKNoeLgLMHgXi2p7yGv0Y+sXP1E+36iueLtKf0yhg=; b=uBEmg1Avis54G/L/+zDS25ss7JQXBL4ZtgI56nZpI9iVQtYBmQz4U+dZOU8KH0driB RLDGSBvshZ3q/XblKwYLB5oTQuE4/FXzagNe2xqq5pqrL5EHgoD8iOSAa2AIbWta7+V8 1gv81Vk8XHbDE7tjagdc0BYwCmCIzQtcqO/UKZS7a9pIR19+VZ82u78Mj/RM8YqIUVeJ /jOQaUVxKUNX1/lqOFzNdGnqreZyfDgABwo3fsUllZRfDDF4P6tg66dYAebRElohDjBG 6RZ+A6H0+SenLM+Jwr8DRD+HQLfIOv1/+aNAggWo5bSPFt5FZMPAZzZc5xVvQ0o33x19 A2IA== X-Gm-Message-State: AOJu0Yy7GNCDEvMSlMnmZZtNoizlqpzAGyTk831d4KpgeMmvhSLS2rO1 g8kkYBhNPJEAgtoIMBFy0ng7xYrmXKga5i1IWKICFCFduvhuX/Wb X-Google-Smtp-Source: AGHT+IH1AcZTxzVEA2zsFWAf8ncDoqlKZgbbf4Uu4qEWrHKGVJmXblD3pyhpsAy0TzDl9f5z8CZd9g== X-Received: by 2002:a05:6870:1584:b0:21e:df09:fbb6 with SMTP id j4-20020a056870158400b0021edf09fbb6mr607117oab.41.1712691416249; Tue, 09 Apr 2024 12:36:56 -0700 (PDT) Received: from localhost (169-231-142-28.wireless.ucsb.edu. [169.231.142.28]) by smtp.gmail.com with ESMTPSA id gu24-20020a056a004e5800b006ecfc3a5f2dsm8748646pfb.46.2024.04.09.12.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 12:36:55 -0700 (PDT) From: Karthik Chikmagalur To: Ihor Radchenko , Rudi C Cc: emacs-orgmode@gnu.org Subject: Re: [Q] startup hook: How do I detect if the current buffer has been opened programmatically? In-Reply-To: <87msq2397e.fsf@localhost> References: <87msq2397e.fsf@localhost> Date: Tue, 09 Apr 2024 12:36:54 -0700 Message-ID: <875xwq49bd.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2001:4860:4864:20::2b; envelope-from=karthikchikmagalur@gmail.com; helo=mail-oa1-x2b.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_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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-Flow: FLOW_IN X-Migadu-Country: US X-Spam-Score: -5.67 X-Migadu-Queue-Id: 7CA18E330 X-Migadu-Spam-Score: -5.67 X-Migadu-Scanner: mx10.migadu.com X-TUID: 9Iw/e9jqsx6P >> Org-mode occasionally opens files automatically, for instance, when >> inserting or opening ID links, or during certain searches. I need to >> determine if a buffer was opened programmatically or manually by the user >> within the startup hooks. This distinction is important because, e.g., I >> want to automatically preview all LaTeX fragments if the buffer was opened >> by the user, but not if it was opened programmatically. > > AFAIK, there is no reliable way to do this. > You may play around with `find-file-hook'. See `org-with-file-buffer' > macro in org-macs.el (on main). A heuristic I use is to check if the window is visible. It's not perfect but good enough for my use (which includes previewing LaTeX fragments): (defun my/latex-preview-maybe () (when (window-live-p (get-buffer-window (current-buffer))) (org-latex-preview 'buffer) (org-latex-preview-auto-mode 1))) (add-hook 'org-mode-hook #'my/latex-preview-maybe) Karthik