From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id yOMDBV3huWb6fwAAe85BDQ:P1 (envelope-from ) for ; Mon, 12 Aug 2024 10:18:05 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id yOMDBV3huWb6fwAAe85BDQ (envelope-from ) for ; Mon, 12 Aug 2024 12:18:05 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Q65hXf7v; dmarc=pass (policy=none) header.from=posteo.net; 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=1723457884; 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=LuDlvresCWunfU9bnckrqkb3lqMXxI+h6EFMfKZwqqU=; b=oA/SDlo1in6Lrqlt+9Lxht++dz+sJl+oMB1Iemt/DLGmG4l9vYVWEZkzt0cBsAU3gukLP1 dJF/OCR9XRTiLsdzVMwFt5cpmf6tLW6e0Kkvdfb9YKdVRJKjSCofIVsdPg+O1C9KTM915D m+dJkc2ssHjmlM6cuw6kpk+hje0VIiD0LYBQeMMD3v5cZtkmKMD2q7kpQ1m+NCyeGkfC/Q 71zSrMjOn7I1Lh9rd6XtunfVtv9gV1JvVSN8os0q1GCmFIf+f18WN+c8aD3EPslsPpIKKL MDuxmGo1hUaojacGIyBkgokVYpAaylHCCs1lHdCeksIp3vtPoy5mm7NFmRUGzQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1723457884; a=rsa-sha256; cv=none; b=s/axeuwHmXZbLL2yRiCMt4CQ1ukAOHDpXRlHosm8nDNq9GDkwdkM2PD0JbA4wQwdCiqI2P MOUweV1so8AAplRKD9fEKfwi81k3l2Yfhr73KNzo2nCPejkMArloYAzHdkz4FYwEwSO+An yQTTSPiVSWJNsmk923kfWqu5ir7l+7sn2Oi7FZx990dQ66rdWl7KzTOI9ZdyYhL9mpvCpj xk7ExeHWh20pfh9Wd0B9wpw5PpiupFkS+hh90HO7H1s8omk7fMkCeJsW4hZP44ZCzyj45I PuqOQq0PMDX0vOv92v28sbcn1CV+apMpfEbnaXsVTxQNUzvedRKugrB3xSueEA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Q65hXf7v; dmarc=pass (policy=none) header.from=posteo.net; 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 C4A1B3B0EE for ; Mon, 12 Aug 2024 12:18:04 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sdS6x-0008Ex-7c; Mon, 12 Aug 2024 06:17:11 -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 1sdS6w-0008Ej-1z for emacs-orgmode@gnu.org; Mon, 12 Aug 2024 06:17:10 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sdS6t-0001lp-0C for emacs-orgmode@gnu.org; Mon, 12 Aug 2024 06:17:09 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 30511240028 for ; Mon, 12 Aug 2024 12:17:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1723457824; bh=74cRo6kPrI8MFitrJaPbyufRFrgH3XpuYkFWCerDlTo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=Q65hXf7vQUSnKGC5VyDHhjoO2z3VXMR5XgCQQPt1HiehdLELErPbhjdlZmD8A7aW2 foqIt/d/b5UvyayOae94fKDarcqZbS6NfqWbe83HnnNxtVNABlOt32MjqEsQ/YDjLI UNRnFChKPAyIc3kGKgrOkVca5Pcd4ZDax7Mtjb+TSJjyDZmh77q74v0UsVdzTw3RKY 4JvBaE/kjXUbwOijz+lUynWdEzqbzZhtWpdggqhX5euJbT84HNAIhPmfS30MNDKNYb BLZ1mVxs3MDpWtQKOXa3o65xYckwIt3mC+aEfxqZLUmsvrYScy/IJU8Xy+/2KEooDF Jb/fWngF4gaJw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Wj9Rg2Lnvz6tys; Mon, 12 Aug 2024 12:17:03 +0200 (CEST) From: Ihor Radchenko To: "Christopher M. Miles" Cc: Org mode Subject: Re: [PATCH v4.0] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer In-Reply-To: <66a8b73b.170a0220.383476.996e@mx.google.com> References: <6461a84b.a70a0220.b6d36.5d00@mx.google.com> <87sfbxhmxe.fsf@localhost> <64623c09.170a0220.52bf9.9437@mx.google.com> <87y1lo4ou1.fsf@localhost> <646379fc.620a0220.c0ae4.9fb2@mx.google.com> <87zg3l1rgb.fsf@localhost> <64c8a313.a70a0220.93ee0.14fb@mx.google.com> <87il9zgpdp.fsf@localhost> <64c905d7.170a0220.f434a.fddb@mx.google.com> <87o7jpoqfl.fsf@localhost> <64cc9b8a.170a0220.dfa99.2e18@mx.google.com> <87msz7kym0.fsf@localhost> <669882e5.050a0220.8ff6d.33c6@mx.google.com> <871q3logb9.fsf@localhost> <66a8b73b.170a0220.383476.996e@mx.google.com> Date: Mon, 12 Aug 2024 10:18:13 +0000 Message-ID: <87o75yhwnu.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-Migadu-Spam-Score: -6.67 X-Spam-Score: -6.67 X-Migadu-Queue-Id: C4A1B3B0EE X-Migadu-Scanner: mx11.migadu.com X-TUID: Xqyb1uxryrIt --=-=-= Content-Type: text/plain "Christopher M. Miles" writes: >> What about the following treatment of ARG: >> >> 1. No argument, no region selected :: toggle (display or hide dwim) images in current section >> 2. No argument, region selected: toggle images in region >> 3. C-u argument :: toggle images in the whole buffer >> 4. C-u C-u argument, no region selected :: unconditionally hide images in the buffer >> 5. M-1 argument, no region selected :: display images in current section with INCLUDE-LINKED >> 6. M-1 argument, region selected :: ... in region ... >> 7. M-11 argument :: ... in the whole buffer ... >> 8. Any other argument :: treat as INCLUDE-LINKED = t >> >> And please document all the new arguments in the manual and etc/ORG-NEWS file. > > I followed you upper 8 conditions to re-write my patch. > Except the 8. condition I'm not sure I understand correctly. > And I extend 1. condition to support the inline image link at point toggle displaying. > ... I do not like the code repetitions in the patch and relying upon `use-region-p' even for non-interactive use. I am attaching a complete rewrite of your idea. Please let me know if my patch does everything you want to include into the command. Note that I went with a new idea of introducing a branch new function instead of changing `org-toggle-inline-images'. This way, existing users of `org-toggle-inline-images' will not be affected at all. We are just changing the default C-c C-x C-v binding. This way, the breakage is a little as possible. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-toggle-inline-images-command-New-command-for-C-c.patch >From 0a7b2a8850013be3ca916f4e5c67ac68b94feb25 Mon Sep 17 00:00:00 2001 Message-ID: <0a7b2a8850013be3ca916f4e5c67ac68b94feb25.1723457647.git.yantar92@posteo.net> From: Ihor Radchenko Date: Mon, 12 Aug 2024 12:11:17 +0200 Subject: [PATCH] org-toggle-inline-images-command: New command for C-c C-x C-v binding * lisp/org.el (org-toggle-inline-images-command): New command to toggle images. Unlike the old `org-toggle-inline-image', it is more flexible and default to toggling images at point/current entry. * lisp/org-keys.el (org-mode-map): Bind C-c C-x C-v to the new command. * doc/org-manual.org (Images): Update the manual describing the new command behaviour. * etc/ORG-NEWS (=C-c C-x C-v= command toggling inline image display has been reworked): Document the breaking change. Link: https://list.orgmode.org/6461a84b.a70a0220.b6d36.5d00@mx.google.com/ --- doc/org-manual.org | 17 +++++++--- etc/ORG-NEWS | 31 ++++++++++++++++++ lisp/org-keys.el | 4 +-- lisp/org.el | 82 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 126 insertions(+), 8 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 6cf51ebcac..9365c66b10 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -11806,14 +11806,21 @@ ** Images Such images can be displayed within the buffer with the following command: -- {{{kbd(C-c C-x C-v)}}} (~org-toggle-inline-images~) :: +- {{{kbd(C-c C-x C-v)}}} (~org-toggle-inline-images-command~) :: #+kindex: C-c C-x C-v - #+findex: org-toggle-inline-images + #+findex: org-toggle-inline-images-command + Toggle the inline display of linked images in current section or at + point. With a prefix argument, toggle inline images in the whole + buffer. With double prefix argument, hide all the images in buffer. + + By default, only the image links without description are displayed. + You can force displaying all the images using numeric argument to + toggle all the images in current section (~1~ argument) or the whole + buffer (~11~ argument). + #+vindex: org-startup-with-inline-images - Toggle the inline display of linked images. When called with a - prefix argument, also display images that do have a link - description. You can ask for inline images to be displayed at + You can ask for inline images to be displayed at startup by configuring the variable ~org-startup-with-inline-images~[fn:: The variable ~org-startup-with-inline-images~ can be set within a buffer with the diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 6f858f3ca7..533965311a 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -18,6 +18,37 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. # require user action for most Org mode users. # Sorted from most important to least important. +*** =C-c C-x C-v= command toggling inline image display has been reworked + +Previously, =C-c C-x C-v= always toggled image display in the whole +buffer (or narrowed part of the buffer). With prefix argument, it +also forced displaying image links with description. + +Now, =C-c C-x C-v= is bound to a new command +~org-toggle-inline-images-command~, which uses different defaults: + +1. By default, it toggles image at point or, if there is no image at + point, images in current entry + +2. When region is active, it is honored + +3. =C-u= argument changed its meaning. Now, it forces toggling images + in the whole buffer + +4. =C-u C-u= argument unconditionally hides all the images in buffer + +5. Displaying images over links with description can be forced using + numeric argument: + - ~C-u 1~ for toggling all images at point/current entry + - ~C-u 11~ for toggling all images in buffer + +The old ~org-toggle-inline-images~ command is still available. You +can bind it back to =C-c C-x C-v= by adding the following to you config: +#+begin_src emacs-lisp +(eval-after-load 'org-keys + (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)) +#+end_src + *** Org mode may throw an error when attempting to include remote unsafe resource noninteractively Previously, when ~org-resource-download-policy~ is ~ask~ (default), diff --git a/lisp/org-keys.el b/lisp/org-keys.el index edd4059fc6..1daedaae8c 100644 --- a/lisp/org-keys.el +++ b/lisp/org-keys.el @@ -218,7 +218,7 @@ (declare-function org-toggle-checkbox "org" (&optional toggle-presence)) (declare-function org-toggle-radio-button "org" (&optional arg)) (declare-function org-toggle-comment "org" ()) (declare-function org-toggle-fixed-width "org" ()) -(declare-function org-toggle-inline-images "org" (&optional include-linked beg end)) +(declare-function org-toggle-inline-images-command "org" (&optional arg beg end)) (declare-function org-latex-preview "org" (&optional arg)) (declare-function org-toggle-narrow-to-subtree "org" ()) (declare-function org-toggle-ordered-property "org" ()) @@ -618,7 +618,7 @@ (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display) (org-defkey org-mode-map (kbd "C-c C-x x") #'org-dynamic-block-insert-dblock) (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update) (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-latex-preview) -(org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images) +(org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images-command) (org-defkey org-mode-map (kbd "C-c C-x C-M-v") #'org-redisplay-inline-images) (org-defkey org-mode-map (kbd "C-c C-x \\") #'org-toggle-pretty-entities) (org-defkey org-mode-map (kbd "C-c C-x C-b") #'org-toggle-checkbox) diff --git a/lisp/org.el b/lisp/org.el index bcab7ca860..39167c656f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16654,7 +16654,8 @@ (defun org-normalize-color (value) (defvar-local org-inline-image-overlays nil) ;; Preserve when switching modes or when restarting Org. ;; If we clear the overlay list and later enable Or mode, the existing -;; image overlays will never be cleared by `org-toggle-inline-images'. +;; image overlays will never be cleared by `org-toggle-inline-images' +;; and `org-toggle-inline-images-command'. (put 'org-inline-image-overlays 'permanent-local t) (defun org--inline-image-overlays (&optional beg end) @@ -16667,6 +16668,85 @@ (defun org--inline-image-overlays (&optional beg end) (when (memq ov org-inline-image-overlays) (push ov result))))) +(defun org-toggle-inline-images-command (&optional arg beg end) + "Toggle display of inline images without description at point. + +When point is at an image link, toggle displaying that image. +Otherwise, toggle displaying images in current entry. + +When region BEG..END is active, toggle displaying images in the +region. + +With numeric prefix ARG 1, display images with description as well. + +With prefix ARG `\\[universal-argument]', toggle displaying images in +the accessible portion of the buffer. With numeric prefix ARG 11, do +the same, but include images with description. + +With prefix ARG `\\[universal-argument] \\[universal-argument]', hide +all the images in accessible portion of the buffer. + +This command is designed for interactive use. From Elisp, you can +also use `org-toggle-inline-images'." + (interactive (cons current-prefix-arg + (when (use-region-p) + (list (region-beginning) (region-end))))) + (let* ((include-linked + (cond + ((member arg '(nil (4) (16)) ) nil) + ((member arg '(1 11)) 'include-linked) + (t 'include-linked))) + (interactive? (called-interactively-p 'any)) + (toggle-images + (lambda (&optional beg end scope force-remove) + (let* ((beg (or beg (point-min))) + (end (or end (point-max))) + (old (org--inline-image-overlays beg end)) + (scope (or scope (format "%d:%d" beg end)))) + (if (or old force-remove) + (progn + (org-remove-inline-images beg end) + (when interactive? + (message + "[%s] Inline image display turned off (removed %d images)" + scope (length old)))) + (org-display-inline-images include-linked t beg end) + (when interactive? + (let ((new (org--inline-image-overlays beg end))) + (message + (if new + (format "[%s] %d images displayed inline %s" + scope (length new) + (if include-linked "(including images with description)" + "")) + (format "[%s] No images to display inline" scope)))))))))) + (cond + ((not (display-graphic-p)) + (message "Your Emacs does not support displaying images!")) + ;; Region selected :: toggle images in region. + ((and beg end) (funcall toggle-images beg end "region")) + ;; C-u or C-11 argument :: toggle images in the whole buffer. + ((member arg '(11 (4))) (funcall toggle-images nil nil "buffer")) + ;; C-u C-u argument :: unconditionally hide images in the buffer. + ((equal arg '(16)) (funcall toggle-images nil nil "buffer" 'remove)) + ;; Argument nil or 1, no region selected :: toggle (display or hide + ;; dwim) images in current section or image link at point. + ((and (member arg '(nil 1)) (null beg) (null end)) + (let ((context (org-element-context))) + ;; toggle display of inline image link at point. + (if (org-element-type-p context 'link) + (funcall toggle-images + (org-element-begin context) + (org-element-end context) + "image at point") + (let ((beg (if (org-before-first-heading-p) (point-min) + (save-excursion + (org-with-limited-levels (org-back-to-heading t) (point))))) + (end (org-with-limited-levels (org-entry-end-position)))) + (funcall toggle-images beg end "current section"))))) + ;; Any other non-nil argument. + ((not (null arg)) (funcall toggle-images beg end "region"))))) + (defun org-toggle-inline-images (&optional include-linked beg end) "Toggle the display of inline images. INCLUDE-LINKED is passed to `org-display-inline-images'." -- 2.45.2 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--