Strip out #+title in #+include

2024-06-14 Thread Risto Stevcev
There doesn't seem to be a way to strip out the `#+title` from an
`#+include`d org file. As a result, for complex org documents, if you end
up `#+include`ing multiple org files that have `#+title`s, it ends up
appending them all, which can often not be what you want, which is true in
my case.

There's this solution I found, but it strips out the title entirely, rather
than controlling which `#+title`s get exported, such as only the title of
the root doc:
https://emacs.stackexchange.com/questions/18420/unwanted-concatenation-of-multiple-title-and-author-when-using-include


org-element--cache: Added org-data parent to non-headline element

2024-06-14 Thread martyhiatt

hi org-mode,

i'm encountering an error repeatedly in my work. (i know elisp but not org 
well, i also don't know how to report bugs, so apologies if i'm doing it wrong.

how i encounter it:

- working in an org file, i call clone-indirect-buffer-other-window.
- i narrow parent buffer to a subtree, and cloned buffer i open in another frame
- in cloned buffer, i move some headings or list items around, and at some 
point the org parsing breaks. so eg if i move a heading, it doesn't correctly 
calculate the end of the subtree but moves part of the next subtree with it (it 
splits it in the middle for example).

- i get an warning like so:

#+begin_example
⛔ Warning (org-element): org-element--cache: Added org-data parent to non-headline element: (item (:standard-properties [6 6 22232 22238 22238 0 (:tag) item element t (61 . 6) nil nil nil # nil ((5 0 "- 
" nil "[ ]" nil 22237) (22237 0 "- " nil "[X]" nil 22251) (22251 0 "- " nil "[ ]" nil 22273) (22273 0 "- " nil "[ ]" nil 22285) (22285 0 "- " nil "[ ]" nil 22317) 
(22317 0 "- " nil "[ ]" nil 22344) (22344 0 "- " nil "[X]" nil 22366)) (headline (:standard-properties [22195 22195 1 22367 22367 0 (:title) nil element nil (61 . 22194) 3 22367 1 # [org-element-deferred org-element--headline-deferred nil t] nil (org-data (:standard-properties [1 1 2 95144 95144 0 nil org-data nil t nil 4 95144 nil # [org-element-deferred 
org-element--get-global-node-properties nil t] nil nil] :path "/path/to/my-org-file.org" :fragile-cache nil))] :pre-blank 0 :raw-value [org-element-deferred org-element--headline-raw-value (0 0) nil] :title [org-element-deferred 
org-element-property-2 (:raw-value) nil] :level 0 :priority nil :tags nil :todo-keyword nil :todo-type nil :footnote-section-p [org-element-deferred org-element--headline-footnote-section-p nil nil] :archivedp [org-element-deferred 
org-element--headline-archivedp nil nil] :commentedp nil :fragile-cache nil))] :bullet "- " :checkbox off :counter nil :pre-blank 0 :tag nil))
If this warning appears regularly, please report the warning text to Org mode 
mailing list (M-x org-submit-bug-report).
#+end_example

- i think the actual parsing mess ups vary, sometimes the paragraph indent will 
be lost, or rich text markup doesn't work properly any more, but i figure 
they're all derivative of the same error.

- i have to restart the file to continue working.

- i tried it also in emacs -q, same file, same cloning/narrowing, and i got a 
different error:

#+begin_example
Warning (org-element-cache): org-element--cache: Org parser error in 
my-org-file.org<2>::2131. Resetting.
The error was: (wrong-type-argument integer-or-marker-p nil)
Backtrace:
nil
Please report this to Org mode mailing list (M-x org-submit-bug-report).
#+end_example

i'm running emacs 30.0.50, gtk, cairo, daemon mode.
i'm running org 9.7-pre, installed via straight/use-package

NB: when i run in emacs -q, it runs emacs built-in version, 9.6.9.
would it be helpful to try to reproduce with emacs -q plus my own org config 
(it's a lot)?

i'm currently not able to upgrade to next org version as i don't want my config 
to break while working on this project.

thanks,
marty


[BUG] Invalid search bound [9.6.24 (9.6.24-??-5bdfc02 @ /Users/forsil/.config/emacs/.local/straight/build-29.2/org/)]

2024-06-14 Thread Yang Forsil



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.

Warning (org-element-cache): org-element--cache: Org parser error in 
zui-you-jie-ren-sheng.org::#. 
Resetting.
The error was: (error "Invalid search bound (wrong side of point)")
Backtrace:
nil


Emacs  : GNU Emacs 29.2 (build 2, aarch64-apple-darwin22.6.0, NS appkit-2299.70 
Version 13.6.2 (Build 22G320))
of 2024-02-05
Package: Org mode version 9.6.24 (9.6.24-??-5bdfc02 @ 
/Users/forsil/.config/emacs/.local/straight/build-29.2/org/)

current state:
==
(setq
org-link-elisp-confirm-function nil
org-directory "~/org/"
org-after-refile-insert-hook '(save-buffer)
org-indirect-buffer-display 'current-window
org-crypt-key nil
org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn 
ENTRY)"]
org-num-skip-tags '("noexport" "nonum")
org-load-hook '(+org-init-org-directory-h +org-init-appearance-h 
+org-init-agenda-h +org-init-attachments-h
 +org-init-babel-h +org-init-babel-lazy-loader-h 
+org-init-capture-defaults-h
 +org-init-capture-frame-h +org-init-custom-links-h 
+org-init-export-h +org-init-habit-h
 +org-init-hacks-h +org-init-keybinds-h +org-init-popup-rules-h 
+org-init-smartparens-h)
org-num-face '(:inherit org-special-keyword :underline nil :weight bold)
org-startup-folded t
org-babel-after-execute-hook '(+org-redisplay-inline-images-in-babel-result-h)
org-link-abbrev-alist '(("doomdir" . "/Users/forsil/.config/doom/%s")
 ("emacsdir" . "/Users/forsil/.config/emacs/%s")
 ("doom-repo" . 
"https://github.com/doomemacs/doomemacs/%s";)
 ("wolfram" . "https://wolframalpha.com/input/?i=%s";)
 ("wikipedia" . "https://en.wikipedia.org/wiki/%s";)
 ("duckduckgo" . "https://duckduckgo.com/?q=%s";) 
("kagi" . "https://kagi.com/search?q=%s";)
 ("gmap" . "https://maps.google.com/maps?q=%s";)
 ("gimages" . "https://google.com/images?q=%s";) 
("google" . "https://google.com/search?q=";)
 ("youtube" . "https://youtube.com/watch?v=%s";) 
("github" . "https://github.com/%s";))
org-agenda-files '("~/org/")
org-capture-templates '(("t" "Personal todo" entry (file+headline 
+org-capture-todo-file "Inbox")
  "* [ ] %?\n%i\n%a" :prepend t)
 ("n" "Personal notes" entry (file+headline 
+org-capture-notes-file "Inbox")
  "* %u %?\n%i\n%a" :prepend t)
 ("j" "Journal" entry (file+olp+datetree 
+org-capture-journal-file) "* %U %?\n%i\n%a"
  :prepend t)
 ("p" "Templates for projects")
 ("pt" "Project-local todo" entry (file+headline 
+org-capture-project-todo-file "Inbox")
  "* TODO %?\n%i\n%a" :prepend t)
 ("pn" "Project-local notes" entry (file+headline 
+org-capture-project-notes-file "Inbox")
  "* %U %?\n%i\n%a" :prepend t)
 ("pc" "Project-local changelog" entry
  (file+headline +org-capture-project-changelog-file 
"Unreleased") "* %U %?\n%i\n%a"
  :prepend t)
 ("o" "Centralized templates for projects")
 ("ot" "Project todo" entry 
#'+org-capture-central-project-todo-file "* TODO %?\n %i\n %a"
  :heading "Tasks" :prepend nil)
 ("on" "Project notes" entry 
#'+org-capture-central-project-notes-file "* %U %?\n %i\n %a"
  :heading "Notes" :prepend t)
 ("oc" "Project changelog" entry 
#'+org-capture-central-project-changelog-file
  "* %U %?\n %i\n %a" :heading "Changelog" :prepend t)
 )
org-persist-after-read-hook '(org-element--cache-persist-after-read)
org-refile-targets '((nil :maxlevel . 3) (org-agenda-files :maxlevel . 3))
org-export-before-parsing-hook '(org-attach-expand-links)
org-cycle-tab-first-hook '(+org-yas-expand-maybe-h +org-indent-maybe-h 
org-babel-hide-result-toggle-maybe
org-babel-header-arg-expand)
org-default-notes-file "/Users/forsil/org/notes.org"
org-refile-use-outline-path 'file
org-publish-timestamp-directory 
"/Users/forsil/.config/emacs/.local/cache/org/timestamps/"
org-archive-hook '(org-attach-archive-delete-maybe)
org-file-apps '((remote . emacs) (auto-mode . emacs) (directory . emacs) 
("\\.mm\\'" . default)
 ("\\.x?html?\\'" . default) ("\\.pdf\\'" . default))
org-odt-fo

Re: [BUG] Invalid search bound [9.6.24 (9.6.24-??-5bdfc02 @ /Users/forsil/.config/emacs/.local/straight/build-29.2/org/)]

2024-06-14 Thread Ihor Radchenko
Yang Forsil  writes:

> Warning (org-element-cache): org-element--cache: Org parser error in 
> zui-you-jie-ren-sheng.org::#. 
> Resetting.
> The error was: (error "Invalid search bound (wrong side of point)")
> Backtrace:
> nil

Thanks for reporting!
May you upgrade Org mode to Org 9.7 and let us know if you still see the
warning?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: org-element--cache: Added org-data parent to non-headline element

2024-06-14 Thread Ihor Radchenko
martyhi...@riseup.net writes:

> i'm encountering an error repeatedly in my work. (i know elisp but not org 
> well, i also don't know how to report bugs, so apologies if i'm doing it 
> wrong.
>
> how i encounter it:
>
> - working in an org file, i call clone-indirect-buffer-other-window.
> - i narrow parent buffer to a subtree, and cloned buffer i open in another 
> frame
> - in cloned buffer, i move some headings or list items around, and at some 
> point the org parsing breaks. so eg if i move a heading, it doesn't correctly 
> calculate the end of the subtree but moves part of the next subtree with it 
> (it splits it in the middle for example).
>
> - i get an warning like so:
>
> #+begin_example
> ⛔ Warning (org-element): org-element--cache: Added org-data parent to
> non-headline element...

I have addressed some edge cases with indirect buffers on Org 9.7.
When you finish with urgent work, may your please try upgrading?

> ...
> i'm currently not able to upgrade to next org version as i don't want my 
> config to break while working on this project.

Meanwhile, you can set `org-element-use-cache' to nil. This will disable
the cache and get rid of the error for the time being.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: imenu vs. refile goto (was Re: [PATCH] lisp/org-compat.el: Allow using imenu to visit non-leaf headlines)

2024-06-14 Thread Morgan Smith
Samuel Wales  writes:

> how does imenu compare against completion systems like ido combined with org
> refile set to goto?  when would you use imenu vs. other completion?

For my specific use case, all I want is a simple minibuffer completion
that offers me all the headings in the current buffer and allows me to
jump to the one I select.  Something which sounds easy, but in practice
I haven't found a good solution yet.

I assume you are suggesting `C-u M-x org-refile'.  This is a solution I
haven't seen before.  Being the refile command doesn't make it an
intuitive solution and I wonder if users would be able to find this
easily (I wasn't able to).

In order to get completion for subheadings I had to add this to my
configuration file:
`(setopt org-refile-targets '((nil . (:maxlevel . 5'

I'm actually quite pleased with this interface and it is really nice.
It is exactly what I'm trying to get from imenu.

My only gripe is that it is org specific whereas imenu isn't.  If I get
imenu working the way I like, then I'll benefit in other modes as well.



Re: [BUG] Attachments not resolved correctly from symlinked Org files

2024-06-14 Thread Ihor Radchenko
Ihor Radchenko  writes:

> Ihor Radchenko  writes:
>
>> What about the approach we already use in
>> `org-attach-id-to-path-function-list' - check if an attachment directory
>> already exists, generated using any rule, and only if not, create a new?
>>
>> Similarly, in `org-attach-dir', we can first check local attachment
>> directory and return it if it exists. Then, we check attachment
>> directory for the symlink source, and return it when it exists.
>> If none exists, create attachment locally or relative to the symlink
>> source, according to some customization. The default will be creating
>> locally, to follow the existing behavior.
>
> See the attached tentative patch.

Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=1686b6f3b

As for creating attachment directories in the symlink source dir, I
suggest posting a feature request. Then, we will see if such a feature
would be useful for people.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] Broken read-multiple-choice help in DND local file handler [9.7.2 (release_9.7.2-8-gde0df5)]

2024-06-14 Thread Ihor Radchenko
Johann Klähn  writes:

> When I drag a file onto a buffer and use `?' at the resulting
> `read-multiple-choice' prompt to open the help buffer,
> a `(wrong-type-argument char-or-string-p attach)' error occurs.
> Ultimately, `org--dnd-local-file-handler' passes a symbol where
> `read-multiple-choice' expects a “description” string: the optional
> third entry of each “choice”.  Cf. the documentation string of 
> `read-multiple-choice':
>
>> CHOICES should be a list of the form (KEY NAME [DESCRIPTION]).
>> KEY is a character the user should type to select the entry.
>> NAME is a short name for the entry to be displayed while prompting
>> (if there’s no room, it might be shortened).
>> DESCRIPTION is an optional longer description of the entry; it will
>> be displayed in a help buffer if the user requests more help.
>
> I hope that helps.
> Thanks for the useful feature and the great 9.7 release. 🙃

Thanks for reporting!
Fixed, on bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=2347eac66

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] Broken read-multiple-choice help in DND local file handler [9.7.2 (release_9.7.2-8-gde0df5)]

2024-06-14 Thread Ihor Radchenko
Johann Klähn  writes:

> When I drag a file onto a buffer and use `?' at the resulting
> `read-multiple-choice' prompt to open the help buffer,
> a `(wrong-type-argument char-or-string-p attach)' error occurs.
> Ultimately, `org--dnd-local-file-handler' passes a symbol where
> `read-multiple-choice' expects a “description” string: the optional
> third entry of each “choice”.  Cf. the documentation string of 
> `read-multiple-choice':

Duplicate of https://list.orgmode.org/orgmode/87ikyhg9qi@jklaehn.de/
Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Please document the caching and its user options

2024-06-14 Thread Ihor Radchenko
Eli Zaretskii  writes:

> I needed to visit org.org, the Org manual, today, and to my surprise
> saw Emacs writing some data files into the ~/.cache/org-persist/
> directory.  What's more, Emacs popped a buffer out of the blue telling
> me that it could not safely encode the data written to (I presume)
> some of those files, and asked me to select a safe coding-system.
>
> By randomly poking here and there, I've succeeded to figure out that
> this is due to org-element's caching of data from parsing Org files.
> It seems this caching is turned on by default, but is not documented
> in the Org manual, and in particular there's nothing in the manual
> about turning off the caching.
>
> Please document the caching features of Org in the manual, including
> how to turn that off.  (I also question the wisdom of turning this on
> by default without as much as a single request for confirmation from
> the user.)

Hmm. What aspect of caching do you want us to document?
FYI, Org mode has been doing various forms of caching since
forever. Recently, we just employed a bit more regular API and
introduced one more kind of caching - parser cache. In addition to the
previously existing image cache, publishing cache, ID cache, clock
cache, etc.

> Please also make sure that the code which actually writes the data to
> the cache files makes a point of binding coding-system-for-write to a
> proper value (probably utf-8-unix), or forces
> buffer-file-coding-system of the buffer from which it writes to have
> such a safe value, to avoid annoying and unexpected prompting of the
> user to select a proper encoding.  Lisp programs that write files in
> the background cannot fail to set a proper encoding, because the call
> to select-safe-coding-system is not supposed to be triggered by Lisp
> programs unless they run as a direct result of a user-invoked command.

I believe that this particular problem has been solved in
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c8f88589c
It is a part of Org 9.7.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] Clock malfunction -- Cannot process task file after update [9.7.2 (release_N/A-N/A-88dd2c @ /home/rknyman/.emacs.d/elpa/org-9.7.2/)]

2024-06-14 Thread Ihor Radchenko
Ihor Radchenko  writes:

> The culprit is
>
> CLOCK: [2023-06-01 Thu 21rr:07]--[2023-06-01 Thu 22:08] =>  1:01
>
> The timestamp is malformed there, which leads to error.
>
> It is still a bug in Org mode that such problem is not handled
> gracefully.
> Confirmed.

Fixed, on bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=fd8ddf287

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Please document the caching and its user options

2024-06-14 Thread Eli Zaretskii
> From: Ihor Radchenko 
> Cc: emacs-orgmode@gnu.org
> Date: Fri, 14 Jun 2024 13:12:42 +
> 
> Eli Zaretskii  writes:
> 
> > I needed to visit org.org, the Org manual, today, and to my surprise
> > saw Emacs writing some data files into the ~/.cache/org-persist/
> > directory.  What's more, Emacs popped a buffer out of the blue telling
> > me that it could not safely encode the data written to (I presume)
> > some of those files, and asked me to select a safe coding-system.
> >
> > By randomly poking here and there, I've succeeded to figure out that
> > this is due to org-element's caching of data from parsing Org files.
> > It seems this caching is turned on by default, but is not documented
> > in the Org manual, and in particular there's nothing in the manual
> > about turning off the caching.
> >
> > Please document the caching features of Org in the manual, including
> > how to turn that off.  (I also question the wisdom of turning this on
> > by default without as much as a single request for confirmation from
> > the user.)
> 
> Hmm. What aspect of caching do you want us to document?

First and foremost, that it exists, and is turned on by default.  The
manual is currently completely silent about it.

Next, please document the user options that control this caching, and
especially those options which can be used to turn this caching off or
direct it to a different place.

> FYI, Org mode has been doing various forms of caching since
> forever. Recently, we just employed a bit more regular API and
> introduced one more kind of caching - parser cache. In addition to the
> previously existing image cache, publishing cache, ID cache, clock
> cache, etc.

I'm not a heavy user of Org, but I do have several Org files that I
visit from time to time.  This was the first time I got prompted about
anything related to this caching.  Moreover, I think this was the
first time the Org file I visited was parsed by Org and the results
cached: I have a feature on my system that prominently indicates when
the machine is heavily loaded, and I was surprised to see it in action
when I visited org.org.  I never had this activated before just by
visiting an Org file.  I presumed the high load was due to the
parsing.  So either this is very new, or maybe my Org files are much
simpler than doc/misc/org.org, and so the parsing I triggered before
was much less expensive.

I hope you now understand why I wrote this report now and not before,
and why I was surprised: this caching was never so explicitly and
prominently into my face, so I could have completely missed its
existence.

> > Please also make sure that the code which actually writes the data to
> > the cache files makes a point of binding coding-system-for-write to a
> > proper value (probably utf-8-unix), or forces
> > buffer-file-coding-system of the buffer from which it writes to have
> > such a safe value, to avoid annoying and unexpected prompting of the
> > user to select a proper encoding.  Lisp programs that write files in
> > the background cannot fail to set a proper encoding, because the call
> > to select-safe-coding-system is not supposed to be triggered by Lisp
> > programs unless they run as a direct result of a user-invoked command.
> 
> I believe that this particular problem has been solved in
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c8f88589c
> It is a part of Org 9.7.

Maybe.  Try visiting org.org on a system whose locale is set to, say,
Latin-1, and see if you get the warnings about a safe coding-system.

But why do you use utf-8 there and not utf-8-unix?  Come to think
about it, why not emacs-internal?  Those files are used internally by
Org, so they should be able to encode any characters supported by
Emacs, not just those which have UTF-8 encoding.  And using native EOL
convention is not needed, and will get in the way if the user shares
these files between systems.



Re: [BUG/FR] org-plot: replot on resize [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-14 Thread Ihor Radchenko
Visuwesh  writes:

>>> This is more of a FR than a bug but it would be nice to have working
>>> replot-on-resize when the gnuplot terminal is qt, x11, etc.  To have
>>> this functional, the data-file needs to be not deleted.
>>
>> It should be doable.
>> We can simply use `org-babel-temp-stable-file' and leave cleaning up to
>> `org-babel-remove-temporary-stable-directory'.
>
> The data writing functions themselves require a filename so the file
> content cannot be used as DATA to org-babel-temp-stable-file.  What
> should be DATA instead? (list table params)?

All the things that contribute to what is written to the data file:

;; Dump table to datafile
  (let ((dump-func (plist-get type :data-dump)))
(if dump-func
(funcall dump-func table data-file num-cols params)
  (org-plot/gnuplot-to-data table data-file params)))

So, you can set DATA to (list (or dump-func 'org-plot/gnuplot-to-data) table 
num-cols params)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] Clock malfunction -- Cannot process task file after update [9.7.2 (release_N/A-N/A-88dd2c @ /home/rknyman/.emacs.d/elpa/org-9.7.2/)]

2024-06-14 Thread Ihor Radchenko
Ihor Radchenko  writes:

> Robert Nyman  writes:
>
>> When I run "org-lint" again, I get an empty "Line Trust Warning" buffer.
>
> It does not catch all the typos in your file, unfortunately.
> Look for "rr" and "r" in clock lines - they are not all caught.

I now added a linter for CLOCK: lines. On main (not for current
release).
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=9f0a9ec34

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Please document the caching and its user options

2024-06-14 Thread Jens Lechtenboerger
On 2024-06-14, Ihor Radchenko wrote:

> Eli Zaretskii  writes:
>
>> Please document the caching features of Org in the manual, including
>> how to turn that off.  (I also question the wisdom of turning this on
>> by default without as much as a single request for confirmation from
>> the user.)
>
> Hmm. What aspect of caching do you want us to document?
> FYI, Org mode has been doing various forms of caching since
> forever. Recently, we just employed a bit more regular API and
> introduced one more kind of caching - parser cache. In addition to the
> previously existing image cache, publishing cache, ID cache, clock
> cache, etc.

Jumping in here, I do not understand the publishing cache.  Some of
my org documents are re-published every time, while others are only
re-published after changes.  What is checked where?

Best wishes,
Jens


smime.p7s
Description: S/MIME cryptographic signature


Re: [BUG] Trailing dash is not included in link [9.7.3 (9.7.3-2f1844 @ /home/mwillcock/.emacs.d/elpa/org-9.7.3/)]

2024-06-14 Thread Ihor Radchenko
Morgan Willcock  writes:

> When web links are inserted into an org buffer, if the link ends in a
> trailing dash this seems to be omitted from the link target.
>
> i.e. Inserting "https://domain/test-"; into the buffer will create a
> clickable link for "https://domain/test";.
>
> These types of links will likely be encountered for sites where anchor
> targets are automatically generated from documentation headings which
> are questions.

This makes sense.
I improved the heuristics we use to detect plain links.
Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=73da6beb5

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: org-babel-execute-src-block filters characters from :session *shell* output

2024-06-14 Thread Ihor Radchenko
"Cook, Malcolm"  writes:

> Let me walk you through the issue:
>
> #+begin_src sh
> printf 'a\nb\nc\n>d\n #+end_src
>
> #+RESULTS:
> : a
> : b
> : c
> : >d
> : 
> Results look as expected. So far so good.
>
> Now create a shell buffer (which will be named "*shell*")
>
> #+begin_src elisp
> (shell)
> #+end_src
>
> and try it again
>
> #+begin_src sh
> printf 'a\nb\nc\n>d\n #+end_src
>
> #+RESULTS:
> : a
> : b
> : c
> : d
> : 
> Huh? what happened to the ">" before the "d"?

I cannot reproduce.
May it be that you are setting global :session header argument?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



RE: org-babel-execute-src-block filters characters from :session *shell* output

2024-06-14 Thread Cook, Malcolm


>"Cook, Malcolm"  writes:
>
>> Let me walk you through the issue:
>>
>> #+begin_src sh
>> printf 'a\nb\nc\n>d\n> #+end_src
>>
>> #+RESULTS:
>> : a
>> : b
>> : c
>> : >d
>> : >
>> Results look as expected. So far so good.
>>
>> Now create a shell buffer (which will be named "*shell*")
>>
>> #+begin_src elisp
>> (shell)
>> #+end_src
>>
>> and try it again
>>
>> #+begin_src sh
>> printf 'a\nb\nc\n>d\n> #+end_src
>>
>> #+RESULTS:
>> : a
>> : b
>> : c
>> : d
>> : >
>> Huh? what happened to the ">" before the "d"?
>
>I cannot reproduce.
>May it be that you are setting global :session header argument?

Yes, of course, so sorry, there is

#+PROPERTY: header-args:sh :session *shell* :results output

You should now be able to reproduce.

Thanks, please let me know if you have a fix, workaround, or lesson for me.

~Malcolm




Publishing cache (was: Please document the caching and its user options)

2024-06-14 Thread Ihor Radchenko
Jens Lechtenboerger  writes:

> Jumping in here, I do not understand the publishing cache.  Some of
> my org documents are re-published every time, while others are only
> re-published after changes.  What is checked where?

See "14.4 Triggering Publication" section of Org mode manual:

   Org uses timestamps to track when a file has changed.  The above
functions normally only publish changed files.  You can override this
and force publishing of all files by giving a prefix argument to any of
the commands above, or by customizing the variable
‘org-publish-use-timestamps-flag’.  This may be necessary in particular
if files include other files via ‘SETUPFILE’ or ‘INCLUDE’ keywords.

Apart from caching "timestamps" (a combination of modification time and
file hash), ox-publish stores information about generated link anchors,
so that they remain stable upon repeated publications (by default Org
mode export generates random anchors, unless they are specified in Org
mode source).

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] Export does not read .dir-locals.el [9.7.3 (release_9.7.3 @ /usr/local/share/emacs/30.0.50/lisp/org/)]

2024-06-14 Thread Ihor Radchenko
Protesilaos Stavrou  writes:

> I have noticed that the export mechanism does not read the local
> variables of a file when those come from a .dir-locals.el.

It is expected - export happens in a separate buffer that only inherits
Org mode settings, but nothing else.

Not a bug.
Canceled.

> ...
> Perhaps there is some user option to let the export mechanism read those
> local variables?

You can make use of #+bind functionality.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Please document the caching and its user options

2024-06-14 Thread Ihor Radchenko
Eli Zaretskii  writes:

>> Hmm. What aspect of caching do you want us to document?
>
> First and foremost, that it exists, and is turned on by default.  The
> manual is currently completely silent about it.
>
> Next, please document the user options that control this caching, and
> especially those options which can be used to turn this caching off or
> direct it to a different place.

I am not convinced that we have to do it.

Firstly, it is not clear if you are asking to document caching parser
state specifically or all kinds of caching Org mode does.

Secondly, I am not sure if we have to document the details of caching at
all in the manual. We do not document all the custom options in the
manual; just the most important/useful.

Emacs user manual does not document `multisession-directory' - something
very close to how we implement Org caches.  So, apparently, customizing
`multisession-directory' and even the very multisession feature
existence is not deemed necessary inside Emacs manual. Why would it be
different for Org mode manual?

> I'm not a heavy user of Org, but I do have several Org files that I
> visit from time to time.  This was the first time I got prompted about
> anything related to this caching.

The prompt you saw is indeed a bug.

> ...  Moreover, I think this was the
> first time the Org file I visited was parsed by Org and the results
> cached: I have a feature on my system that prominently indicates when
> the machine is heavily loaded, and I was surprised to see it in action
> when I visited org.org.  I never had this activated before just by
> visiting an Org file.  I presumed the high load was due to the
> parsing.  So either this is very new, or maybe my Org files are much
> simpler than doc/misc/org.org, and so the parsing I triggered before
> was much less expensive.

Org mode uses parser since long time ago. Previously, the parser was
invoked without any caching, even in-memory. Since Org 9.6, we
implemented in-memory and on-disk caches for the parser. This allowed us
to utilize the parser more frequently, without relying upon
half-accurate regexp matches. Overall, it decreased CPU loads, but there
are different scenarios; sometimes CPU load is larger momentarily.

>> I believe that this particular problem has been solved in
>> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c8f88589c
>> It is a part of Org 9.7.
>
> Maybe.  Try visiting org.org on a system whose locale is set to, say,
> Latin-1, and see if you get the warnings about a safe coding-system.
>
> But why do you use utf-8 there and not utf-8-unix?  Come to think
> about it, why not emacs-internal?  Those files are used internally by
> Org, so they should be able to encode any characters supported by
> Emacs, not just those which have UTF-8 encoding.  And using native EOL
> convention is not needed, and will get in the way if the user shares
> these files between systems.

Mostly because we chose whatever looked reasonable. I am not 100% sure
what is the practical difference between `utf-8' and `utf-8-unix' and
why the latter should be considered better.

As for `emacs-internal', we try to make files readable if at all
possible. In particular, index.eld file is even pretty-printed for user
convenience. The idea is to keep things in plain text and not in binary
formats, following the overall spirit how Emacs usually stores data. (I
think you may recall people raising their voice about plain text
vs. binary during the discussion of multisession feature and the use of
sqlite database).

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[FR] Support sessions in ob-emacs-lisp via IELM

2024-06-14 Thread Ihor Radchenko
Suhail Singh  writes:

> IELM (M-x ielm) derives from comint-mode and provides a convenient
> interactive environment for evaluating lisp expressions.  Some of the
> conveniences such as automatically evaluating expressions can make
> iterative development easier.
>
> Currently, ob-emacs-lisp does not support sessions.  It would be nice if
> support of sessions was added to ob-emacs-lisp such that the session
> buffer is an ielm-mode buffer.

Patches welcome!

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] worg: Prefer HTTPS to GIT for anonymous git access

2024-06-14 Thread Ihor Radchenko
Stefan Kangas  writes:

> I think using HTTPS makes more sense for anonymous git access, for the
> usual security and privacy reasons.
>
> Please see the attached worg patch.

Thanks!
Applied.
https://git.sr.ht/~bzg/worg/commit/87104b9f

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] lisp/org-compat.el: Allow using imenu to visit non-leaf headlines

2024-06-14 Thread Ihor Radchenko
Morgan Smith  writes:

> With a file like this:
>
> * headline 1
> ** headline 2
>
> We currently produce an imenu tree that looks like this:
>
> '(("headline 1" ("headline 2" . marker-2)))
>
> imenu has no clue where "headline 1" is located and thus the user
> can't navigate to it.  With this patch installed imenu knows where
> non-leaf headlines are as the tree will now look like this:
>
> '(("headline 1" . marker-1)
>   ("headline 1" ("headline 2" . marker-2)))

Thanks!
This makes sense.

> Quirks:
>
> With the default `imenu-flatten' value of nil, it is still impossible
> to visit non-leaf headlines and no change is perceived.

But no regressions, right? Especially in older Emacs versions with
`imenu-flatten' not yet available.

> Setting `imenu-flatten' to 'group works as expected with the quirk
> that top level headlines don't end up in the group.

We may add a top-level group, can't we?

> Ex:
> * Headline 1
> Group is "*"
> Setting the group to "Headline 1" somehow might be nice but would
> require upstream changes in imenu.
> ** Headline 2
> Group is "Headline 1"
> *** Headline 3
> Group is "Headline 1:Headline 2"
>
> Everything seems to work as expected when `imenu-flatten' is set to
> 'prefix or 'annotation.

We may also consider changing the default value of `imenu-flatten' in
Org buffers to non-nil. But what would be the best default?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Please document the caching and its user options

2024-06-14 Thread Eli Zaretskii
> From: Ihor Radchenko 
> Cc: emacs-orgmode@gnu.org
> Date: Fri, 14 Jun 2024 15:31:28 +
> 
> Eli Zaretskii  writes:
> 
> >> Hmm. What aspect of caching do you want us to document?
> >
> > First and foremost, that it exists, and is turned on by default.  The
> > manual is currently completely silent about it.
> >
> > Next, please document the user options that control this caching, and
> > especially those options which can be used to turn this caching off or
> > direct it to a different place.
> 
> I am not convinced that we have to do it.

That's too bad.  When a user finds out about this caching, how do you
propose that he/she looks for the information about it?  I wanted to
know what is being cached, why, and in what file/directory.  It took
me quite some time to find the answers, since Org is a very large
package, and there's no org-cache.el file or similar to serve as the
immediate suspect.  Surely, such a basic functionality should be at
least hinted in the documentation, so that users new which options to
look at and where?

> Firstly, it is not clear if you are asking to document caching parser
> state specifically or all kinds of caching Org mode does.

All of them.

> Secondly, I am not sure if we have to document the details of caching at
> all in the manual. We do not document all the custom options in the
> manual; just the most important/useful.

I submit that at least the options which control where the cache is
and how to disable it are important enough to be in the manual.  Given
their names, users can use apropos or customize-group to find other
relevant options.

> Emacs user manual does not document `multisession-directory' - something
> very close to how we implement Org caches.  So, apparently, customizing
> `multisession-directory' and even the very multisession feature
> existence is not deemed necessary inside Emacs manual. Why would it be
> different for Org mode manual?

multisession is an optional package, it is neither preloaded nor
turned on by default in Emacs.  And even if Emacs makes a mistake of
not documenting anything it is not a valid argument to make the same
mistake elsewhere.

> > But why do you use utf-8 there and not utf-8-unix?  Come to think
> > about it, why not emacs-internal?  Those files are used internally by
> > Org, so they should be able to encode any characters supported by
> > Emacs, not just those which have UTF-8 encoding.  And using native EOL
> > convention is not needed, and will get in the way if the user shares
> > these files between systems.
> 
> Mostly because we chose whatever looked reasonable. I am not 100% sure
> what is the practical difference between `utf-8' and `utf-8-unix' and
> why the latter should be considered better.
> 
> As for `emacs-internal', we try to make files readable if at all
> possible. In particular, index.eld file is even pretty-printed for user
> convenience. The idea is to keep things in plain text and not in binary
> formats, following the overall spirit how Emacs usually stores data. (I
> think you may recall people raising their voice about plain text
> vs. binary during the discussion of multisession feature and the use of
> sqlite database).

The emacs-internal encoding is not binary.  In almost all the cases it
is indistinguishable from utf-8-unix.  It differs where a buffer
includes characters outside of the Unicode codespace.  The usual
practice in Emacs is that files holding internal data use
emacs-internal to make sure all the characters are saved correctly and
can be later restored correctly.



[BUG] orgalist send bug

2024-06-14 Thread Rustom Mody
This is regarding the separate package orgalist by Nicolas Goaziou.
https://elpa.gnu.org/packages/orgalist.html

I installed orgalist with package install.
Open the file orgalist.txt which contains the example from orgalist shown below
M-x orgalist-mode
M-x orgalist-send-list

I get a warning
Warning (org-element): ‘org-element-at-point’ cannot be used in
non-Org buffer # (text-mode)

Also: The receiving site gets the latex version but the list
disappears from the sending site

--orgalist.txt --
% BEGIN RECEIVE ORGLST to-buy
% END RECEIVE ORGLST to-buy
\begin{comment}

#+ORGLST: SEND to-buy org-list-to-latex
- a new house
- a new computer
  + a new keyboard
  + a new mouse
- a new life
\end{comment}



Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Rudolf Adamkovič
Rudolf Adamkovič  writes:

> I will continue working on this patch soon.

All right, here I am, at last!

In the attached patchset, I address all the problems discussed in this
thread, plus some more I found:

1. Escape double quote characters in results [as discussed]
2. Sort tabular results [to fix flaky tests]
3. Remove half-baked session support [as discussed]
4. Improve documentation strings and commentary [bonus]

Rudy

>From 6dcca348337c05d33d62da6eeb1f4193b73f4d6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
Date: Fri, 14 Jun 2024 16:55:24 +0200
Subject: [PATCH 1/4] ob-lua: Escape double quote characters in results

* lisp/ob-lua.el (org-babel-lua-wrapper-method): Escape all double
quote characters in Lua before giving them to Org Babel.
* testing/lisp/test-ob-lua.el (test-ob-lua/escaping-quotes): Test
automatic escaping of double quote characters.

Reported-by: Max Nikulin 
Link: https://list.orgmode.org/216278dc-075c-47d1-94dc-f5bde8346...@gmail.com/
---
 lisp/ob-lua.el  | 2 +-
 testing/lisp/test-ob-lua.el | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 041abfabc..0168bc070 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -283,7 +283,7 @@ function dump(it, indent)
   end
   return result
else
-  return tostring(it)
+  return string.gsub(tostring(it), '\"', '\\\"')
end
 end
 
diff --git a/testing/lisp/test-ob-lua.el b/testing/lisp/test-ob-lua.el
index 0a60c68ca..ff69f5411 100644
--- a/testing/lisp/test-ob-lua.el
+++ b/testing/lisp/test-ob-lua.el
@@ -176,6 +176,12 @@ return x
 (org-test-with-temp-text "src_lua{return 1, 2, 3}"
   (org-babel-execute-src-block))
 
+(ert-deftest test-ob-lua/escaping-quotes ()
+  (should
+   (equal "A \" B"
+  (org-test-with-temp-text "src_lua{return 'A \" B'}"
+(org-babel-execute-src-block)
+
 (provide 'test-ob-lua)
 
 ;;; test-ob-lua.el ends here
-- 
2.39.3 (Apple Git-146)

>From 3a2fc3f052ea2d36f51ae4fd9d0078fb8a08e522 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
Date: Fri, 14 Jun 2024 16:59:37 +0200
Subject: [PATCH 2/4] ob-lua: Sort tabular results

`test-ob-lua/colnames-yes-header-argument-pp' fails intermittently due
to tabular results being returned from Lua to Emacs Lisp in different
order than expected.  We fix the problem by sorting all tabular
results before returning them.

* lisp/ob-lua.el (org-babel-lua-wrapper-method): Sort all tabular
results, recursively, before returning them from Lua to Emacs Lisp.
---
 lisp/ob-lua.el | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 0168bc070..5790073b6 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -270,7 +270,13 @@ function dump(it, indent)
   if #indent ~= 0 then
  result = result .. '\\n'
   end
-  for key, value in pairs(it) do
+  local keys = {}
+  for key in pairs(it) do
+table.insert(keys, key)
+  end
+  table.sort(keys)
+  for _, key in ipairs(keys) do
+ local value = it[key]
  result = result
 .. indent
 .. dump(key)
-- 
2.39.3 (Apple Git-146)

>From da489d577fa714f6ce00fec5beb464f86823c4fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
Date: Fri, 14 Jun 2024 17:36:19 +0200
Subject: [PATCH 3/4] ob-lua: Remove half-baked session support

* lisp/ob-lua.el (org-babel-execute:lua):
(org-babel-prep-session:lua):
(org-babel-load-session:lua):
(org-babel-lua-session-buffer):
(org-babel-lua-with-earmuffs):
(org-babel-session-buffer:lua):
(org-babel-lua-without-earmuffs):
(lua-default-interpreter):
(lua-which-bufname):
(lua-shell-buffer-name):
(org-babel-lua-initiate-session-by-key):
(org-babel-lua-initiate-session):
(org-babel-lua-evaluate):
(org-babel-lua-evaluate-external-process):
(org-babel-lua-evaluate-session):
(org-babel-lua-read-string): Remove all unfinished Lua and Emacs Lisp
code related to sessions and emit a user error when a Lua session is
requested.
* testing/lisp/test-ob-lua.el (test-ob-lua/no-sessions): Test the user
error emitted when requesting a Lua session.

Link: https://list.orgmode.org/87y192etb4.fsf@localhost/
---
 lisp/ob-lua.el  | 205 +---
 testing/lisp/test-ob-lua.el |   9 ++
 2 files changed, 14 insertions(+), 200 deletions(-)

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 5790073b6..f36c726df 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -25,15 +25,6 @@
 
 ;; Org-Babel support for evaluating lua source code.
 
-;; Requirements:
-;; for session support, lua-mode is needed.
-;; lua-mode is not part of GNU Emacs/orgmode, but can be obtained
-;; from marmalade or melpa.
-;; The source repository is here:
-;; https://github.com/immerrr/lua-mode
-
-;; However, sessions are not yet working.
-
 ;;; Code:
 
 (require 'org-macs)
@@ -90,11 +81,10 @@ This will typically b

Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Rudolf Adamkovič
Rudolf Adamkovič  writes:

> In the attached patchset, I address [...]

Oh, wait.  I forgot about the big patch I already sent to you.  Ha-ha!
Hold your horses, then; I will resolve all conflicts and send a patchset
that can be applied cleanly, end-to-end.

#StillCooking :)

Rudy
-- 
"It is far better to have a question that can't be answered than an answer that
can't be questioned."
--- Carl Sagan

Rudolf Adamkovič  [he/him]
http://adamkovic.org



Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> Rudolf Adamkovič  writes:
>
>> In the attached patchset, I address [...]
>
> Oh, wait.  I forgot about the big patch I already sent to you.  Ha-ha!
> Hold your horses, then; I will resolve all conflicts and send a patchset
> that can be applied cleanly, end-to-end.

Ok. So be it ...
git branch -d piem/ra/ob-lua-escape-double-quoteJun14

:)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] lisp/org-compat.el: Allow using imenu to visit non-leaf headlines

2024-06-14 Thread Morgan Smith
Ihor Radchenko  writes:

> Morgan Smith  writes:
>
>> Quirks:
>>
>> With the default `imenu-flatten' value of nil, it is still impossible
>> to visit non-leaf headlines and no change is perceived.
>
> But no regressions, right? Especially in older Emacs versions with
> `imenu-flatten' not yet available.
>

No regressions that I can tell from my testing.  Both emacs 29.3 (before
imenu-flatten) and emacs-master show no change whatsoever (from what I
can tell) when imenu-flatten is nil.

>> Setting `imenu-flatten' to 'group works as expected with the quirk
>> that top level headlines don't end up in the group.
>
> We may add a top-level group, can't we?
>

This does not seem to be a feature.  You can confirm this yourself by
reading the comment in `imenu--flatten-index-alist' that says "PREFIX is
for internal use only".

> We may also consider changing the default value of `imenu-flatten' in
> Org buffers to non-nil.

In my opinion this is not a good idea.  While the UI of imenu is better
when `imenu-flatten' is set, that's not a decision we should make for
users.

The inability for imenu to visit non-leaf nodes with the default UI is
probably something that should be fixed in emacs core.

> But what would be the best default?

IMO that would be 'prefix.  Which is equivalent to setting it to `t'.



Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> :)

Ihor, after banging my head against the desk for a while, I noticed that
the "separator problem" I am fighting is not Lua-specific:

src_elisp{"a, b"} {{{results(=a\, b=)}}}

Is the escaped comma in the 'results' a bug or a feature?

If it is a feature, let me know, and I will expect it in the tests.  If
not, then I will have to rewrite some of my tests using the verbose
'#+BEGIN_SRC' and '#+END_SRC' blocks instead of using 'src_lua'.

Rudy
-- 
"We shall not cease from exploration
 And the end of all our exploring
 Will be to arrive where we started
 And know the place for the first time"
--- T. S. Eliot, Little Gidding, Four Quarters, 1943

Rudolf Adamkovič  [he/him]
http://adamkovic.org



Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> Ihor, after banging my head against the desk for a while, I noticed that
> the "separator problem" I am fighting is not Lua-specific:
>
> src_elisp{"a, b"} {{{results(=a\, b=)}}}
>
> Is the escaped comma in the 'results' a bug or a feature?

It is not a bug or feature. It is syntax of Org mode macros. Commas
separate macro arguments and must be escaped otherwise.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> It is not a bug or feature. It is syntax of Org mode macros. Commas
> separate macro arguments and must be escaped otherwise.

It transcendents both bugs and features. :)

I will consider it a feature then (as per the traditional terminology,
where a "feature" means "works as specified"), and so I will expect the
commas in my tests.

Thank you, Ihor!

Rudy
-- 
"Music is the mathematics of the sense, mathematics is the music of the reason."
--- James Joseph Sylvester, 1814-1897

Rudolf Adamkovič  [he/him]
http://adamkovic.org



Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-06-14 Thread Rudolf Adamkovič
Rudolf Adamkovič  writes:

> #StillCooking :)

All right, here we go!  5 patches, all based on top of the head
(73da6beb5) of `main' as of today (2024-06-14), in order:

0. [main, as of today]
1. ob-lua: Escape double quote characters in results
2. ob-lua: Sort tabular results
3. ob-lua: Remove half-baked session support
4. ob-lua: Improve documentation strings and commentary
5. ob-lua: Do not confuse list-like strings with lists

Rudy

>From 6dcca348337c05d33d62da6eeb1f4193b73f4d6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
Date: Fri, 14 Jun 2024 16:55:24 +0200
Subject: [PATCH 1/5] ob-lua: Escape double quote characters in results

* lisp/ob-lua.el (org-babel-lua-wrapper-method): Escape all double
quote characters in Lua before giving them to Org Babel.
* testing/lisp/test-ob-lua.el (test-ob-lua/escaping-quotes): Test
automatic escaping of double quote characters.

Reported-by: Max Nikulin 
Link: https://list.orgmode.org/216278dc-075c-47d1-94dc-f5bde8346...@gmail.com/
---
 lisp/ob-lua.el  | 2 +-
 testing/lisp/test-ob-lua.el | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 041abfabc..0168bc070 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -283,7 +283,7 @@ function dump(it, indent)
   end
   return result
else
-  return tostring(it)
+  return string.gsub(tostring(it), '\"', '\\\"')
end
 end
 
diff --git a/testing/lisp/test-ob-lua.el b/testing/lisp/test-ob-lua.el
index 0a60c68ca..ff69f5411 100644
--- a/testing/lisp/test-ob-lua.el
+++ b/testing/lisp/test-ob-lua.el
@@ -176,6 +176,12 @@ return x
 (org-test-with-temp-text "src_lua{return 1, 2, 3}"
   (org-babel-execute-src-block))
 
+(ert-deftest test-ob-lua/escaping-quotes ()
+  (should
+   (equal "A \" B"
+  (org-test-with-temp-text "src_lua{return 'A \" B'}"
+(org-babel-execute-src-block)
+
 (provide 'test-ob-lua)
 
 ;;; test-ob-lua.el ends here
-- 
2.39.3 (Apple Git-146)

>From 93acae0704e873168f27d304901cde8fd9524dd3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
Date: Fri, 14 Jun 2024 16:59:37 +0200
Subject: [PATCH 2/5] ob-lua: Sort tabular results

`test-ob-lua/colnames-yes-header-argument-pp' fails intermittently due
to tabular results being returned from Lua to Emacs Lisp in different
order than expected.  We fix the problem by sorting all tabular
results before returning them.

* lisp/ob-lua.el (org-babel-lua-wrapper-method): Sort all tabular
results, recursively, before returning them from Lua to Emacs Lisp.
---
 lisp/ob-lua.el | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 0168bc070..b2eb46c07 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -270,7 +270,13 @@ function dump(it, indent)
   if #indent ~= 0 then
  result = result .. '\\n'
   end
-  for key, value in pairs(it) do
+  local keys = {}
+  for key in pairs(it) do
+table.insert(keys, key)
+  end
+  table.sort(keys)
+  for _, key in pairs(keys) do
+ local value = it[key]
  result = result
 .. indent
 .. dump(key)
-- 
2.39.3 (Apple Git-146)

>From d7034c49212af85c141391bf1dbb5e891aea30ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
Date: Fri, 14 Jun 2024 17:36:19 +0200
Subject: [PATCH 3/5] ob-lua: Remove half-baked session support

* lisp/ob-lua.el (org-babel-execute:lua):
(org-babel-prep-session:lua):
(org-babel-load-session:lua):
(org-babel-lua-session-buffer):
(org-babel-lua-with-earmuffs):
(org-babel-session-buffer:lua):
(org-babel-lua-without-earmuffs):
(lua-default-interpreter):
(lua-which-bufname):
(lua-shell-buffer-name):
(org-babel-lua-initiate-session-by-key):
(org-babel-lua-initiate-session):
(org-babel-lua-evaluate):
(org-babel-lua-evaluate-external-process):
(org-babel-lua-evaluate-session):
(org-babel-lua-read-string): Remove all unfinished Lua and Emacs Lisp
code related to sessions and emit a user error when a Lua session is
requested.
* testing/lisp/test-ob-lua.el (test-ob-lua/no-sessions): Test the user
error emitted when requesting a Lua session.

Link: https://list.orgmode.org/87y192etb4.fsf@localhost/
---
 lisp/ob-lua.el  | 205 +---
 testing/lisp/test-ob-lua.el |   9 ++
 2 files changed, 14 insertions(+), 200 deletions(-)

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index b2eb46c07..54405f898 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -25,15 +25,6 @@
 
 ;; Org-Babel support for evaluating lua source code.
 
-;; Requirements:
-;; for session support, lua-mode is needed.
-;; lua-mode is not part of GNU Emacs/orgmode, but can be obtained
-;; from marmalade or melpa.
-;; The source repository is here:
-;; https://github.com/immerrr/lua-mode
-
-;; However, sessions are not yet working.
-
 ;;; Code:
 
 (require 'org-macs)
@@ -90,11 +81,10 @@ This will t

Re: [BUG/FR] org-plot: replot on resize [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-14 Thread Visuwesh
[வெள்ளி ஜூன் 14, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
 This is more of a FR than a bug but it would be nice to have working
 replot-on-resize when the gnuplot terminal is qt, x11, etc.  To have
 this functional, the data-file needs to be not deleted.
>>>
>>> It should be doable.
>>> We can simply use `org-babel-temp-stable-file' and leave cleaning up to
>>> `org-babel-remove-temporary-stable-directory'.
>>
>> The data writing functions themselves require a filename so the file
>> content cannot be used as DATA to org-babel-temp-stable-file.  What
>> should be DATA instead? (list table params)?
>
> All the things that contribute to what is written to the data file:
>
> ;; Dump table to datafile
>   (let ((dump-func (plist-get type :data-dump)))
> (if dump-func
>   (funcall dump-func table data-file num-cols params)
> (org-plot/gnuplot-to-data table data-file params)))
>
> So, you can set DATA to (list (or dump-func 'org-plot/gnuplot-to-data) table 
> num-cols params)

Done in the attached patch.

>From 0b81eb9da94cdf311bf54748b03d33a550d431cd Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Sat, 15 Jun 2024 10:25:19 +0530
Subject: [PATCH] org-plot: Make data-file stable for replot-on-resize

* lisp/org-plot.el (org-plot/gnuplot): Use a stable data-file to make
replot-on-resize in GUI terminals work.

Reported-by: Visuwesh 
Link: https://orgmode.org/list/87mso7sl6g@gmail.com
---
 lisp/org-plot.el | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..8adfbc8 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -662,8 +662,7 @@ (defun org-plot/gnuplot (&optional params)
   (looking-at "[[:space:]]*#\\+"))
 (setf params (org-plot/collect-options params
 ;; collect table and table information
-(let* ((data-file (make-temp-file "org-plot"))
-   (table (let ((tbl (save-excursion
+(let* ((table (let ((tbl (save-excursion
(org-plot/goto-nearest-table)
(org-table-to-lisp
 		(when (pcase (plist-get params :transpose)
@@ -681,12 +680,11 @@ (defun org-plot/gnuplot (&optional params)
 			   (nth 0 table
 	   (type (assoc (plist-get params :plot-type)
 			org-plot/preset-plot-types))
-   gnuplot-script)
+   gnuplot-script data-file)
 
   (unless type
 	(user-error "Org-plot type `%s' is undefined" (plist-get params :plot-type)))
 
-  (run-with-idle-timer 0.1 nil #'delete-file data-file)
   (when (eq (cadr table) 'hline)
 	(setf params
 	  (plist-put params :labels (car table))) ; headers to labels
@@ -696,7 +694,11 @@ (defun org-plot/gnuplot (&optional params)
   (looking-at "[[:space:]]*#\\+"))
 			(setf params (org-plot/collect-options params
   ;; Dump table to datafile
-  (let ((dump-func (plist-get type :data-dump)))
+  (let* ((dump-func (plist-get type :data-dump)))
+(setq data-file (org-babel-temp-stable-file
+ (list (or dump-func 'org-plot/gnuplot-to-data)
+   table num-cols params)
+ "org-plot"))
 (if dump-func
 	(funcall dump-func table data-file num-cols params)
 	  (org-plot/gnuplot-to-data table data-file params)))
-- 
2.43.0