Re: [PATCH] ob-sqlite: Use a transient in-memory database by default

2023-08-03 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> As Max described, it might be a potential issue.

How about (1) we merge the patch, and then
(2) we add the lint warning if/when someone
has the [hypothesized] problem?

Rudy
-- 
"One can begin to reason only when a clear picture has been formed in
the imagination."
-- Walter Warwick Sawyer, Mathematician's Delight, 1943

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [ANN] lisp/ob-tangle-sync.el

2023-08-03 Thread Mehmet Tekman
> You dropped mailing list from the CC. Was it intentional?

Whoops, no. Still figuring out an email solution in emacs.

> If I understand your concern correctly, you may simply let-bind
> `org-babel-common-header-args-
> w-values' in the tests to make sure that
> your new parameter merging code is working.

Okay, I will try this



Re: [ANN] lisp/ob-tangle-sync.el

2023-08-03 Thread Ihor Radchenko
Mehmet Tekman  writes:

>> setq unexplained-params (delete-dups unexplained-params))
>
> The help mentions that it stores the result in the list, and it looks
> like it works
>
> #+BEGIN_SRC elisp
> (let ((x '(1 2 1 2 3))) (delete-dups x) x)
> #+END_SRC

This is just implementation detail.
As a general good practice, destructive list manipulation commands
should follow (setq foo (command foo)) pattern.

>> Instead, we should use
>> (mapcar #'org-babel-read (org-babel-balanced-split "yes \"my file with 
>> quotes\"" ?\s))
>
> See my next patch, it implements a quote aware string splitting
> function which is used just for the tangle headers. Is my
> implementation there enough, without having to use text
> properties?

We already have `org-babel-balanced-split'. Your patch will be a code
duplication.

Also, your patch will not handle
#+begin_src lang :tangle "tangle yes file"
vs.
#+begin_src lang :tangle tangle yes file

>> > -(tangle  . ((tangle yes no :any)))
>> > +(tangle  . ((tangle yes no :any)
>> > +  (import export skip sync)))
>>
>> We should not yet change this before the code using the new tangle
>> values is in place.
>
> This is a big source of confusion for me, since I don't really
> know how to implement this extra merging behaviour *without*
> first having tangle headers implemented, since no other element
>  in `org-babel-common-header-args-w-values' has multiple
>  exclusion groups where at least one has `:any'

The new merging behavior does not have be used just yet.
We first implement the capability to handle exclusive groups with :any
and later, in another patch, make use of the new capability.
Does it make sense?

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



Re: [ANN] lisp/ob-tangle-sync.el

2023-08-03 Thread Mehmet Tekman
Thanks for the review!

> setq unexplained-params (delete-dups unexplained-params))

The help mentions that it stores the result in the list, and it looks
like it works

#+BEGIN_SRC elisp
(let ((x '(1 2 1 2 3))) (delete-dups x) x)
#+END_SRC

>
> What we can do it make `org-babel-read' assign a text property to the
> resulting string when it is a string with quotes:
>
> (org-babel-read "my file with quotes") ; => "my file with quotes"
> (org-babel-read "\"my file with quotes\"") ; => #("my file with quotes" 0 19 
> (org-babel-quote t))
>
> Then, we can later use this information in `org-babel-merge-params'.
> We will not call `split-string', when 'org-babel-quote text property is
> present.
> Also, `split-string' won't work when we have something like
>
> "yes \"my file with quotes\""
>
> Instead, we should use
> (mapcar #'org-babel-read (org-babel-balanced-split "yes \"my file with 
> quotes\"" ?\s))

See my next patch, it implements a quote aware string splitting
function which is used just for the tangle headers. Is my
implementation there enough, without having to use text
properties?


> > -(tangle  . ((tangle yes no :any)))
> > +(tangle  . ((tangle yes no :any)
> > +  (import export skip sync)))
>
> We should not yet change this before the code using the new tangle
> values is in place.

This is a big source of confusion for me, since I don't really
know how to implement this extra merging behaviour *without*
first having tangle headers implemented, since no other element
 in `org-babel-common-header-args-w-values' has multiple
 exclusion groups where at least one has `:any'



[PATCH] org-manual: Add references to LaTeX docs (was: New Orgmode LaTex Document Class ?)

2023-08-03 Thread Ihor Radchenko
David Masterson  writes:

> I think begin.html is a good starting point.  Mentioning 'texdoc latex'
> is also simple (and more LaTeX specific) and most likely to work.  You
> could include a parenthetical note that, if it doesn't work, try the
> URL.  After that, new users can dig through the documentation.

See the attached tentative patch.

>From 659d79484fcd280b0ec8d57282588386aa626b21 Mon Sep 17 00:00:00 2001
Message-ID: <659d79484fcd280b0ec8d57282588386aa626b21.1691049428.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Thu, 3 Aug 2023 10:56:07 +0300
Subject: [PATCH] doc/org-manual.org: Refer to LaTeX docs for general
 terminology

* doc/org-manual.org (LaTeX Export): Add links to online and offline
LaTeX docs.
(Quoting LaTeX code): Clarify that direct LaTeX can be used for
fine-tuning.

Link: https://orgmode.org/list/sj0pr03mb5455b2712fa85ba945dff441a2...@sj0pr03mb5455.namprd03.prod.outlook.com
---
 doc/org-manual.org | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 16fbb268f..c3a4e47bc 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -13703,6 +13703,13 @@ ** LaTeX Export
 blank lines in the Org document.  That's because LaTeX itself depends
 on blank lines to tell apart syntactical elements, such as paragraphs.
 
+The following sections expect users to be familiar with common LaTeX
+terminology.  You may refer to https://tug.org/begin.html to get
+familiar with LaTeX basics.  Users with LaTeX installed may also run
+=texinfo latex= from terminal to open LaTeX introduction [fn:: The
+command will open PDF file, which is also available for download from
+http://mirrors.ctan.org/info/latex-doc-ptr/latex-doc-ptr.pdf]
+
 *** LaTeX/PDF export commands
 :PROPERTIES:
 :DESCRIPTION: For producing @LaTeX{} and PDF documents.
@@ -13979,9 +13986,10 @@ *** Quoting LaTeX code
 :DESCRIPTION: Incorporating literal @LaTeX{} code.
 :END:
 
-The LaTeX export backend can insert any arbitrary LaTeX code, see
-[[*Embedded LaTeX]].  There are three ways to embed such code in the Org
-file and they all use different quoting syntax.
+When the available LaTeX export customizations are not sufficient to
+fine-tune the desired output, it is possible to insert any arbitrary
+LaTeX code (see [[*Embedded LaTeX]]).  There are three ways to embed such
+code in the Org file and they all use different quoting syntax.
 
 #+cindex: inline, in @LaTeX{} export
 Inserting in-line quoted with @ symbols:
-- 
2.41.0


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


Re: [ANN] lisp/ob-tangle-sync.el

2023-08-03 Thread Ihor Radchenko
Mehmet Tekman  writes:

>It's a big patch mostly, because there were no intermediate commits
>in which the org framework wouldn't be broken. Hope that's okay!

Sure it is.

> ** Problems
>
> It seems to work well for most tests, except for the "file with
> spaces.txt" which I'm not sure how to proceed with. I feel like
> patching at the level `org-babel--merge-params' is the wrong way to
> go, and that I should patch it further upstream.
>
> That upstream leads to `org-babel-read' which currently chomps the
> quotes off anything it gets:
>
> #+begin_src elisp
>   (org-babel-read " \"my file with quotes\" ")
> #+end_src

> I don't know if this is the expected behaviour for quoted strings with
> spaces, so before I proceed trying to patch this I thought I would
> check in with you and ask whether I should start patching here or not.

This is indeed a problem.
Org cannot distinguish between

#+begin_src lang :foo value with spaces
and
#+begin_src lang :foo "value with spaces"

What we can do it make `org-babel-read' assign a text property to the
resulting string when it is a string with quotes:

(org-babel-read "my file with quotes") ; => "my file with quotes"
(org-babel-read "\"my file with quotes\"") ; => #("my file with quotes" 0 19 
(org-babel-quote t))

Then, we can later use this information in `org-babel-merge-params'.
We will not call `split-string', when 'org-babel-quote text property is
present.
Also, `split-string' won't work when we have something like

"yes \"my file with quotes\""

Instead, we should use
(mapcar #'org-babel-read (org-babel-balanced-split "yes \"my file with 
quotes\"" ?\s))

> -(tangle  . ((tangle yes no :any)))
> +(tangle  . ((tangle yes no :any)
> +  (import export skip sync)))

We should not yet change this before the code using the new tangle
values is in place.

> +(defun org-babel--merge-headers (exclusive-groups  result-params)
> +  "Maintain exclusivity of mutually exclusive parameters, as defined
> +in EXCLUSIVE-GROUPS while merging lists in RESULT-PARAMS."

Please update the docstring, following conventions:
1. First line should be a short full sentence explaining what function
does briefly.
2. Each argument should be explained - what it is and what is the
   structure.

Also, RESULT-PARAMS is confusing because it is no longer just used for
:results. Please rename.

> +  (cl-flet ((alist-append (alist key val)
> +  (let ((existing (cdr (assoc key alist
> +(if existing
> +(setcdr (assoc key alist) (append existing (list val)))
> +  (setq alist (cons (cons key (list val)) alist)))
> +alist)))

Can simply
(push val (alist-get key alist nil nil #'equal))

> +;; Problem: Having an :any keyword in an exclusion group means
> +;;  that a parameter of "yes" could match to an exclusion
> +;;  group that contains both "yes" AND ":any".
> +;; Solution: For each parameter, build a list of exclusion groups
> +;;   it could belong to. If a parameter belongs to two
> +;;   groups, eliminate it from the group that contains the
> +;;   ":any" keyword.
> +;;
> +;;  Details: Exclusion groups (e.g.'("tangle" "yes" "no" ":any") )
> +;;   are referenced to by their car ("tangle"), acting as
> +;;   a key for the entire group.
> +;;

This is not a "problem" - just something to consider. You can omit
"Problem:", "Solution:", and "Details:" converting into ordinary
paragraphs.

> +;; Assumption: The order of RESULT-PARAMS dictate the hierarchy of
> +;; the cascading headers.

The expected function parameters should be described in the docstring,
not in a comment.

> +(let ((any-group-key   ;; exclusion group key for group with :any 
> keyword
> +   (caar (cl-remove-if-not (lambda (x) (member ":any" x)) 
> exclusive-groups)))

`cl-find' will be simpler.

> +  (delete-dups unexplained-params)

Should be
(setq unexplained-params (delete-dups unexplained-params))

`delete-dups' _returns_ the modified list, which may or may not preserve
the initial pointer to the first cons cell.

> +;; Set values in the same order that the exclusion groups are defined
> +(let ((group-key-order (mapcar #'car exclusive-groups)))
> +  (setq group-alist (cl-remove-if-not #'identity

Or just delq nil

> +  (mapcar (lambda (x) (car 
> (alist-get x group-alist)))
> +  group-key-order

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



Re: [ANN] lisp/ob-tangle-sync.el

2023-08-03 Thread Mehmet Tekman
Okay, and now I've patched the related string splitting functions so that
("let's get \"ready to rumble\" now")
is split into:
("let's" "get" "ready to rumble" "now")

All my tests are passing but a few unrelated ones are failing so I'll need
 to dig more into what's going on there. Attached is the 3rd patch

Best
From 3f39671f3ec55e6db076f2b1b5ccad12380eb32a Mon Sep 17 00:00:00 2001
From: Mehmet Tekman 
Date: Thu, 3 Aug 2023 08:22:03 +0200
Subject: [PATCH 3/3] * lisp/ob-core.el (org-babel-merge-params):
 (org-babel--split-str-quoted): Added quotes-aware string split function
 (org-babel-read): patched to add quotes to words with spaces

---
 lisp/ob-core.el | 28 
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 48337406a..0c36bcf00 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2919,6 +2919,21 @@ in EXCLUSIVE-GROUPS while merging lists in RESULT-PARAMS."
 (setq group-alist (append unexplained-params group-alist)))
 group-alist
 
+(defun org-babel--split-str-quoted (str)
+  "Splits a string that may or may not contain quotes"
+  (let (result pos)
+(while (string-match (rx (or (seq "\"" (group (* (not "\""))) "\"")
+ (group (+ (not space)
+ str pos)
+  (let ((match-str1 (match-string 1 str))
+(match-str2 (match-string 2 str)))
+(if match-str1
+(progn
+  (push match-str1 result)
+  (setq pos (1+ (match-end 1
+  (push match-str2 result)
+  (setq pos (match-end 2)
+(nreverse result)))
 
 (defun org-babel-merge-params ( plists)
   "Combine all parameter association lists in PLISTS.
@@ -2994,7 +3009,7 @@ parameters when merging lists."
(setq tangle (org-babel--merge-headers
  tangle-exclusive-groups
  tangle
- (split-string
+ (org-babel--split-str-quoted
   (or value "")
   ((or '(:dir . attach) '(:dir . "'attach"))
(unless (org-attach-dir nil t)
@@ -3319,9 +3334,14 @@ situations in which is it not appropriate."
  ;; FIXME: Arbitrary code evaluation.
 	 (eval (read cell) t))
 	((save-match-data
-   (and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" cell)
-(not (string-match "[^\\]\"" (match-string 1 cell)
- (read cell))
+   (and (string-match (rx bol (* space) "\"" (group (* any)) "\"" (* space) eol)
+  cell)
+(not (string-match (rx (not "\\") "\"") (match-string 1 cell)
+ (let ((res (read cell)))
+   ;; If the matched string contains spaces, surround it in quotes.
+   (if (string-match (rx (+ space)) res)
+   (concat "\"" res "\"")
+ res)))
 	(t (org-no-properties cell
 
 (defun org-babel--string-to-number (string)
-- 
2.41.0