org-element: headline's :title is sometimes string, sometimes list

2023-08-22 Thread Hraban Luyat
Hi all.

I'll let the code speak:

 (with-temp-buffer
   (org-mode)
   (insert "* Hello")
   (cl-flet ((say-type (prefix hl)
   (message "Headline title from %s is of type: %s"
prefix
(type-of (org-element-property :title hl)
 (org-element-map (org-element-parse-buffer) 'headline
   (lambda (hl) (say-type "map" hl)))
 (goto-char (point-min))
 (say-type "context" (org-element-context))
 (say-type "at-point" (org-element-at-point

I expect: "string" everywhere.

I get:

 Headline title from map is of type: cons
 Headline title from context is of type: string
 Headline title from at-point is of type: string

Question 1: Do you know what that `cons' structure is? Where is it 
documented, how would I go about figuring this out myself? The 
org-element API documentation is daunting.

Question 2: how do I reliably get the title as a string? Properties are 
fine, I don't mind, but that weird list structure is awkward to handle.

Thank you

Hraban




Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots

2023-08-22 Thread Jack Kamm
Jack Kamm  writes:

> Liu Hui  writes:
>
>> I think these objects need to be shown in a single column rather than
>> two. Besides, if the python code becomes too complex finally, I think
>> maintaining the python code outside the ob-python.el, as suggested by
>> Ihor, is a good idea.
>
> Thanks for reporting these misbehaving examples. I think the root of the
> problem is `org-babel-script-escape', which is too aggressive in
> recursively converting strings to lists. We may need to rewrite our own
> implementation for ob-python.
>
> Also, I agree that moving the python code to an external file will be
> helpful in handling these more complex cases.
>
> I may leave these tasks for future patches. In the meantime, we may have
> to recommend ":results verbatim" for these more complex cases that
> ":results table" doesn't fully handle yet.

Pushed the patch now, with one final change: I decided to leave dict as
string by default, converting to table only when ":results table" is
explicitly set. I think it's better this way for now, because of the
misbehaving examples you pointed out -- table conversion is not yet
fully robust for complex dict's containing complicated objects or
structures.



Re: [PATCH] ob-python results handling for dicts, dataframes, arrays, and plots

2023-08-22 Thread Jack Kamm
Ihor Radchenko  writes:

> +1
> Don't forget to update
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html
> (note how the docs already have an example of org formatting from python)

Thanks! Done now:
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=579e8c572345c42ad581d3ddf0f484567d55a787

And updated Worg as well:
https://git.sr.ht/~bzg/worg/commit/7c7d352be72271ae73f31ddffa0f48d225b34259



w3m rclick menu, regular rclick menu, org capture

2023-08-22 Thread Samuel Wales
long ago i set up emacs to pop up global menu.  this allows me to e.g.
copy text when i do not use keyboard.

(define-key global-map (kbd "") 'alpha-menu)
(defun alpha-menu ()
  (interactive)
  (menu-bar-open)
  '(call-interactively 'mouse-popup-menubar))

this works in many modes including org but not w3m.

i also do other stuff with spectacular results:

;;   right fringe is vertical scrolling with clicks
;;   right fringe is horizontal scrolling with wheel
;;   left fringe is placement and one window with clicks
;;   left fringe /could be/ something useful with wheel
;;  buffers same mode?
;;  horiz scrolling to a schelling point like bol?
;;   mode line is buffers with wheel
;;   could be mode-line is copy or paste with click
;;   mode line is same mode buffer with click
;;   mode line is any mode buffer with wheel
;;   i think there is nothing special about the basename part
;; do i mean the buffer name part of modeline here?

these work with probably every mode.  i'm pretty sure there is no top
fringe in emacs unfortunately, and header line is not common, so there
is nothing to provide an affordance at the top of the emacs windown.
but fringe and mode line are gret.

i rely on org-mouse for org which doesn't seem to particularly
interfere in either direction.  i.e. i can do org-mouse and the other
stuff.

my questions are:

1.  i'd like to include org-capture in global menu
2.  i'd like to include global menu in w3m and other menus

thanks.

-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com



Re: org-cite: how to force a reparsing of the .bib file

2023-08-22 Thread Leo Butler
On Tue, Aug 22 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I am struggling with org-cite at the moment. One problem: it is not
>> re-parsing my .bib file, so it is not picking up changes. How can I
>> force it to pick up changes?
>
> Please, provide more details.
> org-cite should already monitor .bib file contents and re-parse it as
> necessary.

Does org-cite monitor contents or the timestamp?
I am using a symlink to the bib file.

Leo


[BUG] Bulk scattering breaks when logging rescheduling [9.7 (9.7-??-6eb773053 @ /home/shortcut/.emacs.d/.local/straight/build-28.1/org/)]

2023-08-22 Thread spookygostee
Bulk scattering agenda items when the user wants to log reschedules does not 
work. 

Steps to reproduce: 
1. Set `org-log-reschedule' to the value `"time"'

   Alternatively, customize “Org Log Reschedule” to “Record timestamp with 
note”.

2. Add an org mode file with the following contents to the agenda file list
   ┌
   │ Testing scatter 1
   │ SCHEDULED: <2023-08-22 Tue>
   │ Testing scatter 2
   │ SCHEDULED: <2023-08-22 Tue>
   │ Testing scatter 3
   │ SCHEDULED: <2023-08-22 Tue>
   └
   (As in previous reports, I can’t paste these as actual headings. Their 
structure is irrelevant.)

3. Mark all of previous headings for bulk action in the agenda

4. Bulk scatter the marked headings (`B S', by default)

5. Fill out the prompted note with anything and hit `C-c C-c' to finish

You will note Emacs reports that only `Testing scatter 1' has been rescheduled, 
has a note, and all headings remain marked. Emacs will also /not/ prompt you 
for notes for the other headings or reschedule them- the process terminates 
here. This issue does not occur when `org-log-reschedule' is set to its default 
value: “No logging”.

The expected behavior is that either Emacs will prompt me for more notes for 
the remaining headings, or at the very least will scatter them.

I have written and attached a rudimentary patch which “solves” this problem by 
storing `org-log-reschedule'’s value, scattering with “No logging” set, and 
then restoring it. I think it is up for debate whether or not the logging 
behavior in the case of a bulk scatter should respect the user’s settings, or 
prompt just once at the beginning for a note (copying it to all subsequent 
scattered headlines), or if it should be ignored entirely (as in my patch).


Emacs  : GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, 
cairo version 1.16.0)
 of 2022-05-31
Package: Org mode version 9.7 (9.7-??-6eb773053 @ 
/home/shortcut/.emacs.d/.local/straight/build-28.1/org/)

-/shortcut/
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index bafd8b7f8..609d59a4c 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -11201,8 +11201,12 @@ The prefix arg is passed through to the command if possible."
 		   (let* ((date (calendar-gregorian-from-absolute
  (+ (org-today) distance)))
 			  (time (org-encode-time
- 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date
-			 (org-agenda-schedule nil time
+ 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))
+  (log-state org-log-reschedule))
+ (setq org-log-reschedule nil)
+			 (org-agenda-schedule nil time)
+ (setq org-log-reschedule log-state)
+ )))
 
 	(?f
 	 (setq cmd


Re: org-cite: how to force a reparsing of the .bib file

2023-08-22 Thread Ihor Radchenko
Leo Butler  writes:

> I am struggling with org-cite at the moment. One problem: it is not
> re-parsing my .bib file, so it is not picking up changes. How can I
> force it to pick up changes?

Please, provide more details.
org-cite should already monitor .bib file contents and re-parse it as
necessary.

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



org-cite: how to force a reparsing of the .bib file

2023-08-22 Thread Leo Butler
Hello,

I am struggling with org-cite at the moment. One problem: it is not
re-parsing my .bib file, so it is not picking up changes. How can I
force it to pick up changes?

TIA,
Leo

ps: (insert (format "\n%s\nOrg: %s" (emacs-version) (org-version)))
GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo 
version 1.16.0)
 of 2023-05-13, modified by Debian
Org: 9.6.7


Re: [BUG] Warning when creating preview

2023-08-22 Thread Edgar Lux
On Aug 18, 2023 at 6:04 PM, Ihor Radchenko  wrote:

> May you try to install the latest stable Org first, following
> https://orgmode.org/manual/Installation.html? You should get M-x
> org-version printing Org 9.6.7.

> Then, let us know if the warning keeps appearing.

* What happens

When I type some equations and get the preview, I get this warning

* Steps to reproduce

1. Type this equation

   #+begin_quote
   \begin{gather}
   t = 0
   \end{gather}
   #+end_quote

2. Ask for preview =C-c C-x C-l= with point on the equation

3. Ask to remove preview (without moving point) =C-c C-x C-l=

4. You get the message (below)

If you repeat 1--3, the message is gone. It comes back if you remove the 
=./ltximg/.svg=

* My "system"

#+begin_src emacs-lisp
  (setq org-latex-pdf-process
'("xelatex -file-line-error -no-pdf -interaction nonstopmode 
-shell-escape -output-directory %o %f"
  ;; Check this too: https://tex.stackexchange.com/a/455164
  "[[ -f %o/%b.idx ]] && texindy %o/%b.idx"
  ;; https://stackoverflow.com/a/57734531
  ;; "latexmk -pdfxe -bibtex %F") ; gives issues with silly errors
  "latexmk -shell-escape -f -pdfxe -bibtex %F")

;; https://emacs.stackexchange.com/a/33172
org-preview-latex-process-alist
(quote ((dvisvgm :programs ("xelatex" "dvisvgm")
:description "dvi > svg"
:message ((concat
  "you need to install the programs: "
  "xelatex and dvisvgm."))
:use-xcolor t
:image-input-type "xdv"
:image-output-type "svg"
:image-size-adjust (1.3 . 1.5)
:latex-compiler ("xelatex -no-pdf -interaction nonstopmode 
-output-directory %o %f")
:image-converter ("dvisvgm %o%b.xdv -n -b min -c %S -o %O"))
))

org-preview-latex-default-process 'dvisvgm)
#+end_src

#+begin_src emacs-lisp
  (format "%s\n%s"
  (org-version)
  (emacs-version))
#+end_src

#+RESULTS:
: 9.7-pre
: GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo 
version 1.17.6)
:  of 2023-01-03

Org commit: 3cbd9f423385bf725dc964a5cff573bba17db3ff

* The message

#+begin_example
  Warning (org-element-cache): org-element--cache: Org parser error in 
t.org::189. Resetting.
   The error was: (error "Invalid search bound (wrong side of point)")
   Backtrace:
  "  backtrace-to-string(nil)
org-element-at-point()
org-element-context()
org-latex-preview(nil)
funcall-interactively(org-latex-preview nil)
call-interactively(org-latex-preview nil nil)
command-execute(org-latex-preview)
  "
   Please report this to Org mode mailing list (M-x org-submit-bug-report). 
Disable showing Disable logging
#+end_example


-- 
Sent with https://mailfence.com  
Secure and private email



Re: ob-lilypond fontification

2023-08-22 Thread Ihor Radchenko
Henrik Frisk  writes:

> So I grabbed the file ob-lilypond from another inactive install of Emacs
> 29.1 and linked to it in my init file. Everythin appears to work fine
> except I dont get syntax highlightning unless I hit C-c '

I recommend installing Org mode from ELPA to make sure that you are
using the latest version.

Also, there were possibly relevant changes on development branch. So you
might need ELPA devel version.

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



ob-lilypond fontification

2023-08-22 Thread Henrik Frisk
Hi,

Embarressed but happy that I realised I dont have to keep updating the
twelve year old version of ob-lilypond that I have been using I ran into a
problem. First of all, ob-lilypond is not part of the precompiled version
of emacs that I just switched to :
https://github.com/railwaycat/homebrew-emacsmacport/releases

So I grabbed the file ob-lilypond from another inactive install of Emacs
29.1 and linked to it in my init file. Everythin appears to work fine
except I dont get syntax highlightning unless I hit C-c '

The error I get is:

Org mode fontification error in #

Any suggestions?

/Henrik


Re: [POLL] Should we accept breaking changes to get rid of Org libraries that perform side effects when loading?

2023-08-22 Thread Russell Adams
On Mon, Aug 14, 2023 at 01:19:07PM +, Fraga, Eric wrote:
> I'll chime in regarding inlinetasks: I used to use these *a lot* but I
> found that drawers do what I needed in almost all cases very
> effectively (for my use cases).

Can you give an example?

I always hear the meeting notes with a short tasklist example. That
plain list checkboxes aren't enough, the extra metadata is desired.

--
Russell Adamsrlad...@adamsinfoserv.com
https://www.adamsinfoserv.com/



Re: [POLL] Should we accept breaking changes to get rid of Org libraries that perform side effects when loading?

2023-08-22 Thread Bastien Guerry
"Fraga, Eric"  writes:

> I'll chime in regarding inlinetasks: I used to use these *a lot* but I
> found that drawers do what I needed in almost all cases very
> effectively (for my use cases).

It resonates with my experience too and I suspect (and kinda hope)
many inlinetasks users will feel the same once they use drawers.

-- 
 Bastien Guerry



Re: [MAINTENANCE] Org orphanage?

2023-08-22 Thread Bastien Guerry
Hi Jonas,

Jonas Bernoulli  writes:

> IMO it would be a good idea if Bastien and/or Ihor joined the
> emacsorphanage and explicitly added themselves to these packages as
> admins.
>
> I think I would have to make you owners of emacsorphanage to allow you
> to do this and other useful things on your own.  I would happily give
> you those rights.  You will know better than me who else should get
> write access or even admin rights.  But I would ask you to not *delete*
> any repositories before consulting with me.  Also, ping me after adding
> a new repository.  How does that sound?

Sounds good to me too, I'm "bzg" on GitHub.  Thanks!

-- 
 Bastien Guerry



Re: [patch] Fix inner smart quotes in French

2023-08-22 Thread Bastien Guerry
Ihor Radchenko  writes:

> Bastien Guerry  writes:
>
> Are you referring to `org-export-smart-quotes-alist'? It is a defconst.

 Ah, indeed.  I'd say using a defcustom here would be useful.
>>>
>>> Is changing defconst to defcustom ok for bugfix?
>>
>> Nope, it's more an "evolution" than a bugfix.
>
> Ok. I changed it to defcustom on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=570cdacdb
>
> Note, however, that we have `org-export-dictionary' as a constant.
> Also, language names are not standardized across
> `org-export-dictionary', `org-export-default-language',
> `org-clock-clocktable-language-setup', `org-export-smart-quotes-alist',
> and `org-latex-language-alist'.

>From a quick look, I cannot find two conflicting language names (that
is, two strings like "fr" that refer to two distinct languages from
the variable you mention).

>From the same quick look, I believe `org-export-dictionary' contains
more entries than other variables--we could use languages names from 
this variable.

WDYT?

-- 
 Bastien Guerry



Re: C-RET and empty lines

2023-08-22 Thread Juergen Fenn



Am 22.08.23 um 13:38 Uhr schrieb Ihor Radchenko:

>> Could you please advise how to configure the variable in your init file
>> to have it produce a blank line before _every_ new entry?
>
> (setf (alist-get 'heading org-blank-before-new-entry) t)

Thanks, again. Works fine for me. :)

Best Regards,
Jürgen.




[BUG] bug fix with inline figure generated by org-octave [9.7-pre (release_9.6.7-662-gb89bc5)]

2023-08-22 Thread Shervin Safavi
Hi there,

First, thanks for maintaining this awesome tool.

In "ob-octave.el" line 94, instead of

(format "print -dpng %S\nans=%S" gfx-file gfx-file))

should be

(format "print -dpng %s" gfx-file))

otherwise, the figure is not saved (and thus an empty inline figure will
appear).

I already test it with MATLAB and can confirm it.

By the way, it is my first bug report/fix for org-mode, so apologies if
I miss something in my report.

Best wishes,
Shervin

Emacs  : GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo version 1.16.0)
 of 2023-08-16
Package: Org mode version 9.7-pre (release_9.6.7-662-gb89bc5 @
/home/ssafavi/.ssemacs.d/classicemacs/straight/build/org/)

current state:
==
(setq
 org-archive-location "archive/%s_archive::"
 org-noter--doc-goto-location-hook '(org-noter-djvu--goto-location
org-noter-nov--goto-location
org-noter-pdf--goto-location)
 org-link-elisp-confirm-function nil
 org-ref-cite-onclick-function '(closure (t) (_)
(org-ref-citation-hydra/body))
 org-bibtex-headline-format-function 'org-bibtex-headline-format-default
 org-export-with-sub-superscripts '{}
 org-ref-insert-cite-function 'org-ref-cite-insert-ivy
 org-log-done 'time

 org-babel-after-execute-hook '(scimax-align-result-table
org-display-inline-images
scimax-rm-backslashes scimax-jupyter-ansi)
 org-agenda-skip-scheduled-if-done t
 org-persist-after-read-hook '(org-element--cache-persist-after-read)
 org-ctrl-c-ctrl-c-hook '(scimax-org-image-toggle-image-CcCc
scimax-radio-CcCc)
 org-link-make-description-function '(lambda (link desc)
 (plist-get org-store-link-plist :description))
 org-ref-open-pdf-function 'my/org-ref-open-pdf-at-point
 org-export-before-parsing-hook '(org-attach-expand-links
 org-babel-jupyter-strip-ansi-escapes)
 org-cycle-tab-first-hook '(org-babel-hide-result-toggle-maybe
org-babel-header-arg-expand)
 org-latex-title-command ""
 org-ref-bibtex-assoc-pdf-with-entry-move-function 'rename-file
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-speed-commands '(("Outline Navigation")
 ("n" org-speed-move-safe 'org-next-visible-heading)
 ("p" org-speed-move-safe 'org-previous-visible-heading)
 ("f" org-speed-move-safe 'org-forward-heading-same-level)
 ("b" org-speed-move-safe 'org-backward-heading-same-level)
 ("F" . org-next-block) ("B" . org-previous-block)
 ("u" org-speed-move-safe 'outline-up-heading) ("j" . org-goto)
 ("g" org-refile '(4)) ("Outline Visibility") ("c" . org-cycle)
 ("C" . org-shifttab) (" " . org-display-outline-path)
 ("s" . org-toggle-narrow-to-subtree) ("k" . org-cut-subtree)
 ("=" . org-columns) ("Outline Structure Editing") ("U" . org-metaup)
 ("D" . org-metadown) ("r" . org-metaright) ("l" . org-metaleft)
 ("R" . org-shiftmetaright) ("L" . org-shiftmetaleft)
 ("i" progn (forward-char 1)
  (call-interactively 'org-insert-heading-respect-content))
 ("^" . org-sort) ("w" . org-refile)
 ("a" . org-archive-subtree-default-with-confirmation)
 ("@" . org-mark-subtree) ("#" . org-toggle-comment)
 ("Clock Commands") ("I" . org-clock-in) ("O" . org-clock-out)
 ("Meta Data Editing") ("t" . org-todo) ("," org-priority)
 ("0" org-priority 32) ("1" org-priority 65) ("2" org-priority 66)
 ("3" org-priority 67) (":" . org-set-tags-command)
 ("e" . org-set-effort) ("E" . org-inc-effort)
 ("W" lambda (m) (interactive "sMinutes before warning: ")
  (org-entry-put (point) "APPT_WARNTIME" m))
 ("Agenda Views etc") ("v" . org-agenda) ("/" . org-sparse-tree)
 ("Misc") ("o" . org-open-at-point) ("?" . org-speed-command-help)
 ("<" org-agenda-set-restriction-lock 'subtree)
 (">" org-agenda-remove-restriction-lock) ("P" . org-set-property)
 ("d" . org-deadline) ("m" . org-mark-subtree) ("S" . widen)
 ("k" . scimax-org-kill-subtree) ("q" . scimax-avy-org-headline)
 ("T" . org-teleport))
 org-noter--pretty-print-location-for-title-hook
'(org-noter-djvu--pretty-print-location
  org-noter-nov--pretty-print-location
  org-noter-pdf--pretty-print-location-for-title)


Re: C-RET and empty lines

2023-08-22 Thread Ihor Radchenko
Juergen Fenn  writes:

> Could you please advise how to configure the variable in your init file
> to have it produce a blank line before _every_ new entry?

(setf (alist-get 'heading org-blank-before-new-entry) t)

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



Re: C-RET and empty lines

2023-08-22 Thread Juergen Fenn



Am 22.08.23 um 11:52 Uhr schrieb Ihor Radchenko:
> This behaviour is customizable. See `org-blank-before-new-entry'.

Thank you for this hint. That was new to me as well.

M-x describe-variable RET org-blank-before-new-entry RET says:

> Should ‘org-insert-heading’ leave a blank line before new heading/item?
> The value is an alist, with ‘heading’ and ‘plain-list-item’ as CAR,
> and a boolean flag as CDR.  The cdr may also be the symbol ‘auto’, in
> which case Org will look at the surrounding headings/items and try to
> make an intelligent decision whether to insert a blank line or not.


Could you please advise how to configure the variable in your init file
to have it produce a blank line before _every_ new entry?

Thanks, and best regards,
Jürgen.



Re: C-RET and empty lines

2023-08-22 Thread Ihor Radchenko
Max Nikulin  writes:

> A couple of recent threads reminded me about quite peculiar behavior 
> when a new heading is added by C-RET. I prefer to have an empty line 
> before headings. Sometimes such empty lines disappear. Is such behavior 
> (highly dependent of context) intentional? From my point of view it is 
> confusing.

Yes, it is intentional. Org follows the blank lines of the current
heading when you press C-RET, by default.

This behaviour is customizable. See `org-blank-before-new-entry'.

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



Re: [BUG][SECURITY] ob-sqlite header args allows execution of arbitrary shell commands

2023-08-22 Thread Ihor Radchenko
Max Nikulin  writes:

> On 21/08/2023 14:04, Ihor Radchenko wrote:
>> +(defconst org-shell-arg-literal (gensym "literal")
>
> (opinion) Perhaps a better name exists. Maybe 
> org-shell-arg-tag-unescaped (or unquoted)
> ...

See the updated version of the patches attached.

>From 6909d6165df11bbc256a334488d37ce0ef98523e Mon Sep 17 00:00:00 2001
Message-ID: <6909d6165df11bbc256a334488d37ce0ef98523e.1692697539.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Mon, 21 Aug 2023 09:57:50 +0300
Subject: [PATCH 1/2] org-macs: New common API function to quote shell
 arguments

* lisp/org-macs.el (org-shell-arg-literal): New auxiliary constant.
(org-make-shell-command): New function that returns shell command
built from individual shell arguments, escaping them to prevent
malicious code execution.

Link: https://orgmode.org/list/ub549k$q11$1...@ciao.gmane.io
---
 lisp/org-macs.el | 40 
 1 file changed, 40 insertions(+)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 907e8bed7..73f8b59f9 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -1593,6 +1593,46 @@ (defun org-sxhash-safe (obj  counter)
 	  (puthash hash obj org-sxhash-objects)
 	  (puthash obj hash org-sxhash-hashes)
 
+(defconst org-shell-arg-tag-unescaped (gensym "literal")
+  "Symbol to be used to mark shell arguments that should not be escaped.
+See `org-make-shell-command'.")
+(defun org-make-shell-command (command  args)
+  "Build safe shell command string to run COMMAND with ARGS.
+
+The resulting shell command is safe against malicious shell expansion.
+
+This function is used to avoid unexpected shell expansion when
+building shell command using header arguments from Org babel blocks.
+
+ARGS can be nil, strings, `(,org-shell-arg-tag-unescaped STRING), or a
+list of such elements.  For example,
+
+ (let ((files '(\"a.txt\" \"b.txt\" nil \"$HOME.txt\")))
+  `(org-make-shell-command \"command\" \"-l\"
+  \"value with spaces\"
+  (,org-shell-arg-tag-unescaped \"$HOME\")
+  (mapcar #'identity files)))
+
+will shell-escape \"-l\", \"value with spaces\", and each non-nil member of
+FILES list, but leave \"$HOME\" to be expanded."
+  (concat
+   command (when command " ")
+   (mapconcat
+#'identity
+(delq
+ nil
+ (mapcar
+  (lambda (str-def)
+(pcase str-def
+  (`nil nil)
+  ((pred stringp) (shell-quote-argument str-def))
+  (`(,(pred (eq org-shell-arg-tag-unescaped)) ,(and (pred stringp) str))
+   str)
+  ((pred listp) (apply #'org-make-shell-command nil str-def))
+  (_ (error "Unknown ARG specification: %S" str-def
+  args))
+" ")))
+
 (defun org-compile-file (source process ext  err-msg log-buf spec)
   "Compile a SOURCE file using PROCESS.
 
-- 
2.41.0

>From db0300d18b7d2986eddd4869b73f5702fb429e93 Mon Sep 17 00:00:00 2001
Message-ID: 
In-Reply-To: <6909d6165df11bbc256a334488d37ce0ef98523e.1692697539.git.yanta...@posteo.net>
References: <6909d6165df11bbc256a334488d37ce0ef98523e.1692697539.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Mon, 21 Aug 2023 09:59:12 +0300
Subject: [PATCH 2/2] org-babel-execute:sqlite: Fix shell arg expansion
 vulnerability

* lisp/ob-sqlite.el (org-babel-execute:sqlite): Use
`org-make-shell-command' to escape the strings taken from Org file.
This will prevent abusing shell expansion.

Reported-by: Max Nikulin 
Link: https://orgmode.org/list/ub549k$q11$1...@ciao.gmane.io
---
 lisp/ob-sqlite.el | 34 ++
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index 7510e5158..027f0a72d 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -77,26 +77,20 @@ (defun org-babel-execute:sqlite (body params)
 (with-temp-buffer
   (insert
(org-babel-eval
-	(org-fill-template
-	 "%cmd %header %separator %nullvalue %others %csv %db "
-	 (list
-	  (cons "cmd" org-babel-sqlite3-command)
-	  (cons "header" (if headers-p "-header" "-noheader"))
-	  (cons "separator"
-		(if separator (format "-separator %s" separator) ""))
-	  (cons "nullvalue"
-		(if nullvalue (format "-nullvalue %s" nullvalue) ""))
-	  (cons "others"
-		(mapconcat
-		 (lambda (arg) (format "-%s" (substring (symbol-name arg) 1)))
-		 others " "))
-	  ;; for easy table parsing, default header type should be -csv
-	  (cons "csv" (if (or (member :csv others) (member :column others)
-			  (member :line others) (member :list others)
-			  (member :html others) separator)
-			  ""
-			"-csv"))
-  (cons "db" (or db ""
+(org-make-shell-command
+ org-babel-sqlite3-command
+ (if headers-p "-header" "-noheader")
+ (when separator (list "-separator" separator))
+ (when nullvalue (list "-nullvalue" nullvalue))
+ (mapcar
+	  (lambda (arg) (format "-%s" (substring (symbol-name arg) 1)))
+	  others)
+ ;; for easy table parsing, default header type should be 

Re: Clarification on blank lines following list items

2023-08-22 Thread Ihor Radchenko
Ihor Radchenko  writes:

>> I am seeing dual-ownership of the post-blank in the examples below, but at 
>> the same time if I put a plain-list inside a footnote definition, the 
>> footnote definition ends up with sole custody of the post-blank.
>
> It is a bug in the list parser.

Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=53c9d91d3

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



Re: Clarification on blank lines following list items

2023-08-22 Thread Ihor Radchenko
"Tom Alexander"  writes:

> 1. Is the following statement true? "Two elements can count the same 
> character in their post-blank?"

This statement ought to be false.

> I am seeing dual-ownership of the post-blank in the examples below, but at 
> the same time if I put a plain-list inside a footnote definition, the 
> footnote definition ends up with sole custody of the post-blank.

It is a bug in the list parser.

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