[PATCH] New: auto display inline images under subtree when `org-cycle'.

2022-09-11 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> When I put it on beginning of org document, then preview inline images, but 
>>> those global attributes
>>> not affected. The inline images still display in actual image size. I want 
>>> to specify image size
>>> under headline properties. Is it possible to do this?
>>
>> I implemented this feature by written a hook. Hope this can be helpful
>> for someone who also has this needs. Here is the code:
>
> This looks useful.
> Would you be interested to write a patch?

The is the new patch which updated the defcustom variable docstring has correct 
description.

From 4f66d9d10de5593b863da605ddc375d8f2e06456 Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Mon, 12 Sep 2022 09:45:09 +0800
Subject: [PATCH] org.el: Add hook function to auto display inline images of
 subtree

* lisp/org.el (org-display-subtree-with-inline-images): Add an option
and hook function to auto display of inline images under current
expanded visible subtree.
---
 lisp/org.el | 58 +
 1 file changed, 58 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 6e6c437d5..92086704e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1108,6 +1108,13 @@ the following lines anywhere in the buffer:
   :version "24.1"
   :type 'boolean)
 
+(defcustom org-cycle-display-inline-images nil
+  "Non-nil means auto display inline images under subtree when `org-cycle'
+by the function `org-display-subtree-with-inline-images' on hook `org-cycle-hook'."
+  :group 'org-startup
+  :version "24.1"
+  :type 'boolean)
+
 (defcustom org-startup-with-latex-preview nil
   "Non-nil means preview LaTeX fragments when loading a new Org file.
 
@@ -16284,6 +16291,57 @@ buffer boundaries with possible narrowing."
   (mapc #'delete-overlay org-inline-image-overlays)
   (setq org-inline-image-overlays nil))
 
+(defun org-display-subtree-with-inline-images (&optional state)
+  "Toggle the display of inline images under current expanded visible subtree.
+This hook function will auto display or hide inline images after `org-cycle'.
+It is used to hook on `org-cycle-hook'.
+The function behavior is controlled by `org-cycle-display-inline-images'."
+  (interactive)
+  ;; (not (memq state '(overview folded contents))) ; global state change
+  (when org-cycle-display-inline-images
+(let ((display-inline-images-local
+   (lambda (beg end)
+ (org-display-inline-images t t beg end)
+ ;; display number of inline images which is intersection of two image overlays lists.
+ ;; (message "%d images displayed inline"
+ ;;  (length (cl-intersection org-inline-image-overlays (overlays-in beg end
+ ))
+  (hide-inline-images-local
+   (lambda ()
+ (setq org-inline-image-overlays nil) ; (org-remove-inline-images)
+ (message "Inline image display turned off")))
+  (inline-image-width-override; get headline property value as inline image width.
+   (lambda ()
+ ;; The property "INLINE-IMAGE-WIDTH" value should be integer. Reference `org-display-inline-image--width'.
+ (let* ((property-value (ignore-errors (org-property-or-variable-value 'INLINE-IMAGE-WIDTH)))
+(width-integer (or (and property-value
+(if (numberp property-value) property-value (string-to-number property-value)))
+   (- (/ (window-width (selected-window) t) 2) 100
+   (setq-local org-image-actual-width width-integer)
+  (pcase state
+('children
+ (save-excursion
+   (save-restriction
+ (org-narrow-to-subtree)
+ ;; If has nested headlines, beg,end only from parent headline
+ ;; to first child headline which reference to upper let-binding
+ ;; `org-next-visible-heading'.
+ (funcall display-inline-images-local (point-min) (progn (org-next-visible-heading 1) (point))
+('subtree
+ (save-excursion
+   (save-restriction
+ (org-narrow-to-subtree)
+ (funcall inline-image-width-override)
+ ;; If has nested headlines, also inline display images under all sub-headlines.
+ (funcall display-inline-images-local (point-min) (point-max)
+('folded
+ (funcall hide-inline-images-local))
+('nil (funcall 'org-toggle-inline-images))
+
+(add-hook 'org-cycle-hook #'org-display-subtree-with-inline-images)
+
+(add-to-list 'org-default-properties "INLINE-IMAGE-WIDTH")
+
 (defvar org-self-insert-command-undo-counter 0)
 (defvar org-speed-command nil)
 
-- 
2.37.2


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiv

[PATCH] Re: [SOLVED] Re: [QUESTION] How to specific image size attributes under headline scope?

2022-09-11 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> When I put it on beginning of org document, then preview inline images, but 
>>> those global attributes
>>> not affected. The inline images still display in actual image size. I want 
>>> to specify image size
>>> under headline properties. Is it possible to do this?
>>
>> I implemented this feature by written a hook. Hope this can be helpful
>> for someone who also has this needs. Here is the code:
>
> This looks useful.
> Would you be interested to write a patch?

From 2ba9c048dd2609eb22a3924dd15f041b648ef859 Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Mon, 12 Sep 2022 09:45:09 +0800
Subject: [PATCH] org.el: Add hook function to auto display inline images of
 subtree

* lisp/org.el (org-display-subtree-with-inline-images): Add an option
and hook function to auto display of inline images under current
expanded visible subtree.
---
 lisp/org.el | 59 +
 1 file changed, 59 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 6e6c437d5..594006551 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1108,6 +1108,14 @@ the following lines anywhere in the buffer:
   :version "24.1"
   :type 'boolean)
 
+(defcustom org-cycle-display-inline-images nil
+  "Non-nil means show inline images when `org-cycle'.
+When this is t, org-mode will add function
+`org-display-subtree-with-inline-images' on hook `org-cycle-hook'."
+  :group 'org-startup
+  :version "24.1"
+  :type 'boolean)
+
 (defcustom org-startup-with-latex-preview nil
   "Non-nil means preview LaTeX fragments when loading a new Org file.
 
@@ -16284,6 +16292,57 @@ buffer boundaries with possible narrowing."
   (mapc #'delete-overlay org-inline-image-overlays)
   (setq org-inline-image-overlays nil))
 
+(defun org-display-subtree-with-inline-images (&optional state)
+  "Toggle the display of inline images under current expanded visible subtree.
+This hook function will auto display or hide inline images after `org-cycle'.
+It is used to hook on `org-cycle-hook'.
+The function behavior is controlled by `org-cycle-display-inline-images'."
+  (interactive)
+  ;; (not (memq state '(overview folded contents))) ; global state change
+  (when org-cycle-display-inline-images
+(let ((display-inline-images-local
+   (lambda (beg end)
+ (org-display-inline-images t t beg end)
+ ;; display number of inline images which is intersection of two image overlays lists.
+ ;; (message "%d images displayed inline"
+ ;;  (length (cl-intersection org-inline-image-overlays (overlays-in beg end
+ ))
+  (hide-inline-images-local
+   (lambda ()
+ (setq org-inline-image-overlays nil) ; (org-remove-inline-images)
+ (message "Inline image display turned off")))
+  (inline-image-width-override; get headline property value as inline image width.
+   (lambda ()
+ ;; The property "INLINE-IMAGE-WIDTH" value should be integer. Reference `org-display-inline-image--width'.
+ (let* ((property-value (ignore-errors (org-property-or-variable-value 'INLINE-IMAGE-WIDTH)))
+(width-integer (or (and property-value
+(if (numberp property-value) property-value (string-to-number property-value)))
+   (- (/ (window-width (selected-window) t) 2) 100
+   (setq-local org-image-actual-width width-integer)
+  (pcase state
+('children
+ (save-excursion
+   (save-restriction
+ (org-narrow-to-subtree)
+ ;; If has nested headlines, beg,end only from parent headline
+ ;; to first child headline which reference to upper let-binding
+ ;; `org-next-visible-heading'.
+ (funcall display-inline-images-local (point-min) (progn (org-next-visible-heading 1) (point))
+('subtree
+ (save-excursion
+   (save-restriction
+ (org-narrow-to-subtree)
+ (funcall inline-image-width-override)
+ ;; If has nested headlines, also inline display images under all sub-headlines.
+ (funcall display-inline-images-local (point-min) (point-max)
+('folded
+ (funcall hide-inline-images-local))
+('nil (funcall 'org-toggle-inline-images))
+
+(add-hook 'org-cycle-hook #'org-display-subtree-with-inline-images)
+
+(add-to-list 'org-default-properties "INLINE-IMAGE-WIDTH")
+
 (defvar org-self-insert-command-undo-counter 0)
 (defvar org-speed-command nil)
 
-- 
2.37.2


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP sign

Re: Images in org-mode

2022-09-11 Thread Colin Baxter
> Mark Barton  writes:

>> On Sep 10, 2022, at 12:03 PM, Colin Baxter  wrote:
>> 
>> 
>> I seem to remember that the option
>> 
>> #+ATTR_ORG: :width 100
>> 
>> could scale the display of an image in an org-mode file. This no
>> longer works - perhaps it never did. How should I scale an image
>> display in an org-mode file (not exported)?
>> 
>> Best wishes,
>> 
>> Colin Baxter.
>> 
>> 

> Check the value set for org-image-actual-width. Mine defaulted to
> t, so I changed it. There is some documentation if you use: C-h v
> org-image-actual-width

Yes, org-image-actual-width is the variable I need. It was set to 't'
and I've now changed to a number. With the #+ATTR setting it works as
per the documentation.

I should have gone through the list of variables more carefully before
posting. Thanks you all for your help.

Best wishes,

Colin.



Re: [BUG] org-table-blank-field keybinding [9.5.4 (N/A @ /gnu/store/sry9khwisaq1jnrjbfnhx6ki8qy2z0db-emacs-org-9.5.4/share/emacs/site-lisp/org-9.5.4/)]

2022-09-11 Thread André A . Gomes
Ihor Radchenko  writes:

> André A. Gomes  writes:
>
 Also, it might be worth mentioning in the manual that this command works
 when a region is selected.
>>>
>>> Indeed M-x  does work when region is selected. Just
>>> as documented.
>>
>> I meant in the manual, not in the docstring.  But perhaps it does
>> suffice as it is.
>
> Would you mind making a patch for the manual?
> See https://orgmode.org/worg/org-contribute.html

Please find the patch attached.  Thanks.


-- 
André A. Gomes
"You cannot even find the ruins..."
>From 98b17ef4055d957ebf67d575515d69a53c077570 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20A=2E=20Gomes?= 
Date: Tue, 5 Oct 2021 22:21:11 +0300
Subject: [PATCH 01/76] Fix documentation (manuals and card).

---
 doc/Documentation_Standards.org |   2 +-
 doc/org-guide.org   | 120 +++---
 doc/org-manual.org  | 666 
 doc/orgcard.tex |   8 +-
 4 files changed, 398 insertions(+), 398 deletions(-)

diff --git a/doc/Documentation_Standards.org b/doc/Documentation_Standards.org
index c4dd862db..2f18ab11f 100644
--- a/doc/Documentation_Standards.org
+++ b/doc/Documentation_Standards.org
@@ -112,7 +112,7 @@ version of the manual.
 
 - Use example blocks for Org syntax instead of "begin_src org".
 
-- Internal links to headlines always start with a star.
+- Internal links to headings always start with a star.
 
 - Tags, node properties, are not shown with the surrounding colons.
 
diff --git a/doc/org-guide.org b/doc/org-guide.org
index aa793f11a..bb110f812 100644
--- a/doc/org-guide.org
+++ b/doc/org-guide.org
@@ -107,31 +107,31 @@ worked on.  Org greatly simplifies the use of outlines by compressing
 the entire show and hide functionalities into a single command,
 ~org-cycle~, which is bound to the {{{kbd(TAB)}}} key.
 
-** Headlines
+** Headings
 :PROPERTIES:
 :DESCRIPTION: How to typeset Org tree nodes.
 :END:
 
-Headlines define the structure of an outline tree.  The headlines in
+Headings define the structure of an outline tree.  The headings in
 Org start on the left margin[fn:1] with one or more stars followed by
 a space.  For example:
 
 #+begin_example
-,* Top level headline
+,* Top level heading
 ,** Second level
 ,*** Third level
 some text
 ,*** Third level
 more text
-,* Another top level headline
+,* Another top level heading
 #+end_example
 
-Note that a headline named after ~org-footnote-section~, which
+Note that a heading named after ~org-footnote-section~, which
 defaults to =Footnotes=, is considered as special.  A subtree with
-this headline will be silently ignored by exporting functions.
+this heading will be silently ignored by exporting functions.
 
 Some people find the many stars too noisy and would prefer an outline
-that has whitespace followed by a single star as headline starters.
+that has whitespace followed by a single star as heading starters.
 See [[*Miscellaneous]] for a setup to realize this.
 
 ** Visibility Cycling
@@ -166,7 +166,7 @@ Org uses just two commands, bound to {{{kbd(TAB)}}} and
   Show all, including drawers.
 
 When Emacs first visits an Org file, the global state is set to
-OVERVIEW, i.e., only the top level headlines are visible.  This can be
+OVERVIEW, i.e., only the top level headings are visible.  This can be
 configured through the variable ~org-startup-folded~, or on a per-file
 basis by adding a =STARTUP= keyword to =overview=, =content=,
 =showall=, =showeverything= or =showlevels= (n = 2..5) like this:
@@ -175,10 +175,10 @@ basis by adding a =STARTUP= keyword to =overview=, =content=,
 
 ** Motion
 :PROPERTIES:
-:DESCRIPTION: Jumping to other headlines.
+:DESCRIPTION: Jumping to other headings.
 :END:
 
-The following commands jump to other headlines in the buffer.
+The following commands jump to other headings in the buffer.
 
 - {{{kbd(C-c C-n)}}} :: Next heading.
 
@@ -192,7 +192,7 @@ The following commands jump to other headlines in the buffer.
 
 ** Structure Editing
 :PROPERTIES:
-:DESCRIPTION: Changing sequence and level of headlines.
+:DESCRIPTION: Changing sequence and level of headings.
 :END:
 
 #+attr_texinfo: :sep ,
@@ -201,7 +201,7 @@ The following commands jump to other headlines in the buffer.
   Insert new heading with same level as current.  If point is in
   a plain list item, a new item is created (see [[Plain Lists]]).  When
   this command is used in the middle of a line, the line is split and
-  the rest of the line becomes the new headline[fn:2].
+  the rest of the line becomes the new heading[fn:2].
 
 - {{{kbd(M-S-RET)}}} ::
 
@@ -231,7 +231,7 @@ The following commands jump to other headlines in the buffer.
   Narrow buffer to current subtree and widen it again.
 
 When there is an active region (Transient Mark mode), promotion and
-demotion work on all headlines in the region.
+demotion work on all headings in the region.
 
 ** Sparse Trees
 :PROPERTIES:
@@ -241,7 +241,7 @@ demotion work on all headlines in the reg

Re: Images in org-mode

2022-09-11 Thread Max Nikulin

On 11/09/2022 02:03, Colin Baxter wrote:


I seem to remember that the option

#+ATTR_ORG: :width 100

could scale the display of an image in an org-mode file. This no longer
works - perhaps it never did. How should I scale an image display in an
org-mode file (not exported)?


You have not specified version of Org. E.g. the outcome of the following 
thread is likely not included into the release version:


Matt Huszagh. [PATCH] Fix regex for determining image width from 
attribute. Sun, 21 Nov 2021 11:08:54 -0800. 
https://list.orgmode.org/87czmtuy0p@gmail.com


See also the docstring for `org-display-inline-image--width'




Re: Why do org-agenda-switch-to and org-agenda-goto put the point in different spots in the target buffer?

2022-09-11 Thread Max Nikulin

On 10/09/2022 03:00, Rohit Patnaik wrote:


sometimes the match would appear at the very top of the screen and I'd have to
scroll up manually to see the heading.


From my point of view, "have to scroll up manually" sounds too dramatic 
for the C-l (`recenter-top-bottom') keystroke. On the other hand I can 
not say that I believe that current position in the window after various 
jumps is optimal, but I can not describe what I would like to have in 
each case, so C-l is a rescue.





Re: [PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-09-11 Thread Max Nikulin

On 14/08/2022 16:53, Max Nikulin wrote:

On 13/08/2022 12:01, Ihor Radchenko wrote:

See the updated version of the patch attached. It works on my side.

--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1577,10 +1577,8 @@ (defun org-store-link (arg &optional interactive?)
   t
 (setq link (plist-get org-store-link-plist :link))
 ;; If store function actually set `:description' property, use
-    ;; it, even if it is nil.  Otherwise, fallback to link value.
-    (setq desc (if (plist-member org-store-link-plist :description)
-   (plist-get org-store-link-plist :description)
- link)))
+    ;; it, even if it is nil.  Otherwise, fallback to nil (ask 
user).

+    (setq desc (plist-get org-store-link-plist :description)))


I can not say that I understand design of `org-store-link` and 
`org-insert-link' pair, but I suspect that you might try to fix the 
issue in a wrong place.


It seems the same :link and :description value were set for purpose, see 
`org-insert-link' code:


     (dolist (l org-stored-links)
   (when (equal link (cadr l))
     (setq link (car l))
     (setq auto-desc t)))


Ihor, I beg you pardon. I was wrong writing that you are trying to fix 
the issue in a wrong place. I figured out that the purpose of this 
snippet is completion by link description, not detecting of the case of 
identical link target and description. You have just committed the patch 
from the following thread where I provided more details:
Max Nikulin. ido, org-insert-link, and completion based on link 
description. Tue, 6 Sep 2022 21:34:12 +0700. 
https://list.orgmode.org/tf7lp4$5ha$1...@ciao.gmane.io


Now I believe that your change is an improvement. I do not see any real 
reason to store the same description as the target. 
"~/Desktop/Org/captures.org::target" for <> as default value of 
the description prompt might be a hint to the user for which link their 
should write description, but I hope, there is a better way to do the 
same. I have seen a mention that some export backend may create perhaps 
invisible links if description is omitted, but if it is still an issue, 
it should be fixed in affected backends.


Unfortunately, your patch does not fix the real issue. The title (not 
nil) should be saved for link description when the heading contains the 
CUSTOM_ID property. I tried to address it in the following patches:


Max Nikulin. Re: Bug: org-store-link uses CUSTOM_ID instead of target 
point. Sat, 6 Nov 2021 19:51:29 +0700. 
https://list.orgmode.org/e2c807a7-1924-6f08-9e63-4f70aee9d...@gmail.com





Re: [SOLVED] Re: [QUESTION] How to specific image size attributes under headline scope?

2022-09-11 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> When I put it on beginning of org document, then preview inline images, but 
>> those global attributes
>> not affected. The inline images still display in actual image size. I want 
>> to specify image size
>> under headline properties. Is it possible to do this?
>
> I implemented this feature by written a hook. Hope this can be helpful
> for someone who also has this needs. Here is the code:

This looks useful.
Would you be interested to write a patch?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: [PATCH] ol.el: Restore complete by description for insert link

2022-09-11 Thread Ihor Radchenko
Tim Cross  writes:

> You don't appear to be getting a lot of feedback on this. However, I
> think it is important work your doing. I suspect the lack of feedback is
> partially due to Emacs' completion infrastructure being somewhat
> confusing, combined with references to ido, which I suspect is one of
> the less popular completion frameworks these days. .

Not necessarily Emacs infrastructure. Org completion functions are
fairly confusing as well, which makes it difficult to provide
constructive feedback. We should really work towards (1) documenting the
expected features in Org completion functions; (2) unifying and
de-duplicating completion code across Org, like in
https://orgmode.org/list/87zgisvuu5.fsf@localhost

> My take on this, which might be completely wrong, is that org-mode
> should not cater for or support any specific completion
> framework. Things like ido, icomplete, fido, vertico, corfu, et. al. are
> something which should be supported in a generic and abstract manner
> i.e. we just provide minimal necessary code to generate the candidates
> these systems use. From your description, I think this is what your
> doing. Perhaps the requirements might become clearer if you also tried
> other completion frameworks, like fido, icomplete and vertico.

I'd say that we may still do it. At least, for the most common completion
frameworks. However, we should do everything to reduce the maintenance
overheads of such support.

If some non-standard completion framework offer extra functionality
compared to built-in, we can provide Org's framework that extends
completion-read to support the extra functionality.

What I have in mind is something like

(org-completing-read normal-args extra-args)

with extra-args only playing out when more featureful completion
framework is active.

However, it is critical not to require the normal Org code to account
for non-standard frameworks. All the frameword-specific handling should
be done in a separate localized function/library.

Feel free to refute.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: [PATCH] ol.el: Restore complete by description for insert link

2022-09-11 Thread Ihor Radchenko
Max Nikulin  writes:

> I believe that descriptions as completion options were removed because 
> ido signals an error when nil is passed inside completion list. I 
> consider it as a bug in ido (at least in Emacs-27), but even when 
> `completing-read-default' is used, it causes appearance of undesired 
> "nil" option. No description is a frequent case for links.

This sounds reasonable.

In general, there should be no need to care which completion backend is
used by Emacs - they should all plug into `completing-read' without
anything special to be done on Org side.

The only exception is possible not-yet-fixed bugs in earlier Emacs
versions. However, workaround for such issues should be clearly marked
by a comment in the code and removed once the problematic Emacs version
support is dropped.

> So I am attaching a patch to restore completion of link targets by their 
> description, nil descriptions are filtered out.

Thanks!
Applied onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=0432f4fe6ba9b07c17ac555beab1527d8f844234

> The change is caused by the auto-desc local variable in 
> `org-insert-link', its usage is rather strange and confusing currently. 
>   Despite with this patch descriptions are restored, I believe that 
> logic related to auto-desc should be removed, anyway it was broken for 
> 10 years. I am unsure in which thread the next change should be discussed.

To be frank, org-insert-link should be eventually refactored or at least
better commented. This is one of the "old" functions in Org mode and its
code style is not ideal.

I think that the best approach to fix this and similar functions will be
discussing/documenting the overall design of the Org link
storage/completion. We can then work towards removing inconsistencies
and subtle bugs in the code.

Now, even not all the functionality of org-insert-link is described in
its docstring (like re-using selected region).

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: Fwd: errors when using org-agenda

2022-09-11 Thread Ihor Radchenko
Max Nikulin  writes:

>> Yes, but unfortunately it does not handle early Org loading correctly.
>> 
>> Try the following init.el:
>> 
>> (require 'org)
>> (add-to-list 'load-path (expand-file-name "/path/to/newest/org-mode/lisp"))
>> 
>> Then run emacs -Q -l /path/to/init.el
>> 
>> M-x org-version does not report anything suspicious even though
>> M-x org-mode will error on current main because old 'org is trying to
>> load files from the new load-path.
>
> You are right, `org-version' can not catch such case. However 
> improvements of mixed install detection should be incorporated into 
> `org-submit-bug-report'. I would not mind to have more prominent warning 
> in the message body, maybe even with the link to the FAQ entry.

I think that after
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=e81a094383a2e06a80e6dfb5ed0ca1ece44026f2
we do not need to do anything about `org-submit-bug-report'. Org will
simply refuse to load and show warning if user tries to load mixed Org
files.

I consider this thread completed.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: per-file (or, really, per buffer) allowing/disallowing code block execution

2022-09-11 Thread Ihor Radchenko
Fedja Beader  writes:

>> As Tomas pointed out, Emacs has a concept of safe and non-safe
>> file-local variables. org-confirm-babel-evaluate in particular is only
>> safe when it is set to t (query execution). If your downloaded file
>> attempts to set org-confirm-babel-evaluate to nil, Emacs will show a
>> warning and ask you whether you want to use this unsafe nil value.
>
> Can this mechanism be relied upon? I see in
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Safe-File-Variables.html
> that user may press ! to mark everything safe. This is less effort than
> the explicit "yes" required for executing a block on C-c C-c.

While I agree with you, most people appear to prefer a single char. In
fact, it is very popular to replace _all_ the yes/no prompts in Emacs
with y/n prompts.

If you have an interest to change single-char prompt for buffer-local
variables, feel free to file a bug report to Emacs. AFAIK, there is
currently no way to customize this prompt.

>> Note that Org mode already has a large number of customizations, which
>> is why we are trying to not introduce unnecessary customizations. Too
>> many options is not always a good thing.
>
> This makes me wonder how many of us have a custom init.el for
> the purpose discussed here. Surely I am not alone, and surely
> having such customisation maintained in org-mode itself would
> be better.

I personally rarely use org-babel-execute-buffer and thus changed
org-confirm-babel-evaluate to nil + added default export :eval no-export
header arg. Since I run src blocks using C-c C-c, I always see what I am
about to execute.

>> Yes-for-all/No-for-all may be implemented in multiple ways:
>> - During the current org-babel-execute-buffer call
>
> If the user determined that it is safe to execute all blocks
> once, then why would it not be safe to execute them again?

Consider a code in Org file that makes dangerous things. It may be
useful to keep a query about execution just to stop and think for a
moment if you really want to do it. Not for every block in buffer, but
once.

>> - From now until the buffer is closed
>
> This option is probably closest to what I want.
>
>> - Forever for this file path
>
> Also fine. But
> 1) then this would have to be stored somewhere outside
>of the file, else the user would still be asked if they
>want to load that unsafe local variable. Meaning that in
>that case babel could just ask the user directly.
> 2) As I learn to use Emacs, the number of restarts
>decreases, meaning that the session just lives forever.
>In that case the once per open nagging of babel
>is acceptable.

The second option is a bit more consistent with file-local variable
handling and, more importantly, with `org--confirm-resource-safe' - the
approach we use to download remote #+SETUPFILE.

>> - Forever for this file path until the file contents is changed
>
> What would change the file if not the user, and if the user
> already approved the existing code, why would the user
> not approve their own additions to it?
>
>> - For some period of time
>
> Same response as above.

I was mostly thinking about a file being replaced by a new downloaded
version. This is probably an overkill though.

>> Moreover, the above may apply for all the src blocks in buffer or just a
> particular src block.
>
> Going through blocks one by one and whitelisting, then executing them
> seems like a reasonable course of action, so why not.
> However, it might be a bit difficult to implement?
> How would babel determine that a block is the same
> one, even if it changes? Position in file?

We can use the same approach with :cache header argument. However, I
feel that it is also an overkill and will rarely be needed.

>> I doubt that all the options should be implemented in practice. We may
>> probably just allow yes-for-all when running org-babel-execute-buffer
>> but not individual C-c C-c on src blocks. I can see valid reasons to
>> allow (1) in current org-babel-execute-buffer-call; (2) until the buffer
>> is closed; (3) until the file contents is changed + limited by time.
>> However, 3 possible options in the dialogue may be disorienting:
>
> I would like the option to mark whole file as
> trusted without having to execute all blocks in it.

If we use the approach similar to `org--confirm-resource-safe' and
`org-safe-remote-resources', the safe files will be accumulated into a
custom variable. That custom variable can be modified by user just as
any other custom variable.

>> yes/no (each src block)
>> Yes/No (all src blocks in current org-babel-execute-buffer cal)
>
> all/none? always/never?
>
>> * (until the buffer is closed)
>
> allfornow? alluntilclose?
>
>> ! (until the buffer is closed and in the next 30 days, as long as the
>>  buffer contents is not changed)
>
> I'd prefer having to type full words,
> so that it is obvious what the user meant.

I also prefer full words, though it will be slightly inconsistent with
file-local v