Re: Build a menu for an HTML publish

2024-08-13 Thread Bruno Barbier


Hi Sébastien,

Sébastien Gendre  writes:

[...]
> I cannot found a way to define "very-strawbery" value in an Org-mode
> buffer and having it used while I manually export the Org-mode buffer.
>
> I tried with "#+very-strawbery: test123" and "#+OPTIONS: very-strawbery:
> test123", without success.
>
> Someone have an idea ?

IIUC, "BIND" should work.

You put this in the exported file:

#+BIND: a-string "3"
#+BIND: a-number 3

And you can then use these variables directly:

(defun my/preamble-test (info)
   (message "My string: %S" a-string)
   (message "My number: %S" a-number))

This works only if 'org-export-allow-bind-keywords' is t; else Org
ignores the "#+BIND" instructions.

HTH,

Bruno



Re: Pending contents in org documents

2024-08-13 Thread Ihor Radchenko
Bruno Barbier  writes:

>>>   (concat "\\"
>>>   "This content is pending. "
>>>   "\\[org-pending-describe-reglock-at-point]"
>>>   " to know more."
>>
>> You set a similar help-echo string in two places.  It is a good
>> candidate to factor things out into a helper function.
>
> I'm not sure I understand.  The two messages for the user are not the
> same, the keymaps are not the same.  I'll end up with something like this:
>
>   (defun overlay-set-help-with-keys (overlay message)
>  ...)
>
> Is this really what you meant ?

Hmm. Not really. I misread the strings a bit and thought that they are
more similar than they actually are.

Aside: it looks like 'help-echo uses `substitute-command-keys' without a
need to run it manually. So, we don't really need to do it:

33.19.4 Properties with Special Meanings (Elisp manual)

‘help-echo’
 If text has a string as its ‘help-echo’ property, then when you
 move the mouse onto that text, Emacs displays that string in the
 echo area, or in the tooltip window (*note Tooltips::), after
 passing it through ‘substitute-command-keys’.

>>>   ;; Hack to detect if our overlay has been copied into an other
>>>   ;; buffer.
>>>   (overlay-put overlay 'org-pending--owner (overlay-buffer overlay))
>>
>> AFAIU, the sole purpose of this is
>>
>>   > ;; Try to detect and delete overlays that have been wrongly copied
>>   > ;; from other buffers.
>>
>> ... but cloning buffer does not copy its overlays. Or do I miss something?
>
> If the function 'make-indirect-buffer' is called with a non-nil CLONE
> argument (like `org-tree-to-indirect-buffer' does), the buffer initial
> values are copied, and that includes the copy of overlays.
>
> Org-pending overlays work only in the buffer that owns the reglock:
> so, to support indirect buffers, org-pending needs to detect and
> remove such unwanted copies.  Emacs should probably allow us to flag
> our overlays as "not clonable into other buffers".

Then, may you re-iterate what exactly is the problem if we do allow the
overlays to be copied? Maybe we do not really need all the hassle with
text properties?

>>> (defun org-pending--user-cancel-default (reglock)
>>>   "Send a cancel message to REGLOCK to close it.
>>> Default value for `org-pending-reglock-user-cancel-function'."
>>>   (org-pending-send-update
>>>reglock (list :failure (list 'org-pending-user-cancel
>>> "Canceled"
>>
>> What is the purpose of 'org-pending-user-cancel?
>
> `org-pending-user-cancel' is the error/condition symbol, defined using
> 'define-error'.  It's designed so that's easy to "unwrap" a message:
>
>(pcase outcome
>   (`(:failure ,err) (signal (car err) (cdr err)))
>   (`(:success ,v) v))

But I do not see any calls to `signal' in such context. Do I miss something?

> Just in case, don't jump to a detailed code review of my changes in
> ob-core yet, I've some planed changes there.

Sure. That will be after we tidy up the core library.

> Next set of comments about the org-pending library itself is very
> welcome (as it's mostly independent of it's integration with org-babel).

Here it is :)

> (cl-defun org-pending--new-button-like-keymap (&key read-only)
>   "Return a new keymap for use on reglock overlays.
> If READ-ONLY is non-nil, add bindings for read-only text else for
> editable text."
>   (let ((map (make-sparse-keymap)))
> (dolist (k `([touchscreen-down] [mouse-2] [mouse-1]))
>   (define-key map k #'org-pending-describe-reglock-at-point))
> (when read-only
>   (keymap-set map "RET" #'org-pending-describe-reglock-at-point))
> map))

> (defvar org-pending-outcome-keymap
>   (org-pending--new-button-like-keymap :read-only nil)
>   "Keymap for outcome overlays.")

> (defvar org-pending-pending-keymap
>   (org-pending--new-button-like-keymap :read-only t)
>   "Keymap for pending region overlays.")

Maybe we can make `org-pending-pending-keymap' inherit from
`org-pending-outcome-keymap'? This way, if the latter is customized, the
former will automatically update the bindings.

> (defun org-pending--make-overlay (reglock type begin-end)
> ...
> (cl-flet ((make-read-only (ovl)
> "Make the overly OVL read-only."
>(overlay-put ovl 'modification-hooks read-only)
>(overlay-put ovl 'insert-in-front-hooks read-only)
>(overlay-put ovl 'insert-behind-hooks read-only)))

You call `make-read-only' exactly once.  cl-flet is redundant.

>  ...
> (when (memq type '(:success :failure))
>   (let ((bitmap (pcase type
>   (:success 'large-circle)
>   (:failure 'exclamation-mark)))
> (face (pcase type
> (:success 'org-done)
> (:failure 'org-todo)))

Bitmap and fringe face should be customizeable.

>   ( outcome nil
> :documentation
> "The outcome. nil when not known yet. Els

Re: Build a menu for an HTML publish

2024-08-13 Thread Sébastien Gendre

Another reply to myself about this specific part:

Sébastien Gendre  writes:
> But if I set the variable `org-html-preamble` to my custom preamble
> function like this:
>
> (setq org-html-preamble 'my/preamble-test)
>
> I cannot found a way to define "very-strawbery" value in an Org-mode
> buffer and having it used while I manually export the Org-mode buffer.
>
> I tried with "#+very-strawbery: test123" and "#+OPTIONS: very-strawbery:
> test123", without success.
>
> Someone have an idea ?

If I want to define the value of my new option "very-strawbery" in the
level of an Org-mode buffer (or file), I need to add this new option
into the variable `org-export-options-alist` like this:

If I evaluate this:

(add-to-list 'org-export-options-alist
 '(:very-strawbery "VERYSTRAWBERY" nil nil))


To quote the docstring of `org-export-options-alist`:

> Alist between export properties and ways to set them.
> 
> The key of the alist is the property name, and the value is a list
> like (KEYWORD OPTION DEFAULT BEHAVIOR) where:
> 
> KEYWORD is a string representing a buffer keyword, or nil.  Each
>   property defined this way can also be set, during subtree
>   export, through a headline property named after the keyword
>   with the "EXPORT_" prefix (i.e. DATE keyword and EXPORT_DATE
>   property).
> OPTION is a string that could be found in an #+OPTIONS: line.
> DEFAULT is the default value for the property.
> BEHAVIOR determines how Org should handle multiple keywords for
>   the same property.  It is a symbol among:
>   nil   Keep old value and discard the new one.
>   t Replace old value with the new one.
>   ‘space’   Concatenate the values, separating them with a space.
>   ‘newline’ Concatenate the values, separating them with
>   a newline.
>   ‘split’   Split values at white spaces, and cons them to the
>   previous list.
>   ‘parse’   Parse value as a list of strings and Org objects,
> which can then be transcoded with, e.g.,
> ‘org-export-data’.  It implies ‘space’ behavior.
> 
> Values set through KEYWORD and OPTION have precedence over
> DEFAULT.

After adding my new export option, I can use it by writing this on my
Org-mode buffer/file I want to export:

#+VERYSTRAWBERRY: TestTestTest


After exporting my Org-mode buffer/file to HTML, I get a preamble with
the text "TestTestTest".


Note :

* Having a buffer option for "very-strawbery" is useful for export
  but also for publish. I can set a value that will override the
  value set in the Org-publish project settings.

* The variable `org-export-options-alist` is made for options who are
  back-end agnostic. But I didn't found a way to modify export options of
  HTML backend without redefine a new backend.


Best regards

---
Gendre Sébastien



signature.asc
Description: PGP signature


Re: Build a menu for an HTML publish

2024-08-13 Thread Sébastien Gendre

Thank you very much for your reply.

I didn't know the bind part. I will take a look at it.




Bruno Barbier  writes:

> Hi Sébastien,
>
> Sébastien Gendre  writes:
>
> [...]
>> I cannot found a way to define "very-strawbery" value in an Org-mode
>> buffer and having it used while I manually export the Org-mode buffer.
>>
>> I tried with "#+very-strawbery: test123" and "#+OPTIONS: very-strawbery:
>> test123", without success.
>>
>> Someone have an idea ?
>
> IIUC, "BIND" should work.
>
> You put this in the exported file:
>
> #+BIND: a-string "3"
> #+BIND: a-number 3
>
> And you can then use these variables directly:
>
> (defun my/preamble-test (info)
>(message "My string: %S" a-string)
>(message "My number: %S" a-number))
>
> This works only if 'org-export-allow-bind-keywords' is t; else Org
> ignores the "#+BIND" instructions.
>
> HTH,
>
> Bruno


signature.asc
Description: PGP signature


Link between org-publish project options and org-export-options-alist

2024-08-13 Thread Sébastien Gendre
Hello,

I (continue to) develop a custom preamble function. And I try to found
if there is a link between options set in an org-publish project and
options set in variable `org-export-options-alist.

For my function, I have defined one new export option in the variable
`org-export-options-alist`:

(add-to-list 'org-export-options-alist
 '(:html-doc-name-template "HTML_DOC_NAME_TEMPLATE" 
my/org-html-doc-name-template nil))

This options have a default value defined in variable
`my/org-html-doc-name-template`:

(setq my/org-html-doc-name-template "

%n

")


But, when I use org-publish and try to retrieve option 
":html-doc-name-template" from my
custom preamble function like this:

…
(plist-get info :html-doc-name-template)
…

If I do not define the options `:html-doc-name-temple` in my publish
project options, I get the value `nil` and not the value of the variable
`my/org-html-doc-name-template`.

Are the options of org-publish independent of options defined in
`org-export-options-alist` ?


Best regards

---
Gendre Sébastien


signature.asc
Description: PGP signature


[PATCH] org-contrib/babel/intro.org: Delete unnecessary leading commas in some blocks

2024-08-13 Thread shynur .
These commas are confusing.
See .

0001-org-contrib-babel-intro.org-Delete-unnecessary-leadi.patch
Description: 0001-org-contrib-babel-intro.org-Delete-unnecessary-leadi.patch


Re: Org-publish and attachment links

2024-08-13 Thread Ihor Radchenko
Sébastien Gendre  writes:

> It work. Thank you very much.
>
> I didn't know that org-attach have it's own library and that it was not
> loaded with org. I found nothing about it in the Org-attach section of
> the manual.

Right. It is indeed confusing.
I now made export load org-attach by default.

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

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



Re: Adding text/org MIME type to jshttp/mime-db

2024-08-13 Thread Joseph Turner
Ihor Radchenko  writes:

> Joseph Turner  writes:
>
>>> But we also need to link this new page from other places.
>>
>> How about this patch for orgweb?
>
> Thanks!
> Applied, onto master for orgweb and master for worg.
> https://git.sr.ht/~bzg/worg/commit/91954998
> https://git.sr.ht/~bzg/orgweb/commit/d9222e889ed1f5fee0d328490ed731509fd5a398
>
> I added the TINYCHANGE cookie to your orgweb patch, as orgweb is covered
> under FSF copyright requirements.
>
> Do note that your total contribution is ~15LOC at this point. You may
> consider doing FSF paperwork to make more contributions to org-mode and
> orgweb. worg is free from this requirement.

Thanks!  I completed the FSF copyright assignment paperwork in May 2023.

Joseph



Re: Adding text/org MIME type to jshttp/mime-db

2024-08-13 Thread Ihor Radchenko
Joseph Turner  writes:

> Thanks!  I completed the FSF copyright assignment paperwork in May 2023.

Bastien, may you please confirm with FSF records?

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



Re: org-latex-preview, pNiceArray (running latex twice)

2024-08-13 Thread Ihor Radchenko
Uwe Brauer via "General discussions about Org-mode."
 writes:

> Hi 
>
> Look a the following example
> --8<---cut here---start->8---
> \begin{equation*}
> ...
>
> To org-format-latex-header
>"\\usepackage{nicematrix}\12\newcolumntype{C}{c}\12"
>
> In order to obtain a nice result the corresponding latex file
> should run twice, however.
>
> Any this is a problem for org-latex-preview, it seems.

Karthik, may you please check if this is going to work with latex
preview branch?

> Any idea how to make this example work?

You can modify `org-preview-latex-process-alist' to use latexmk.
See `org-babel-latex-process-alist' for an example.

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



Re: [PATCH] org-contrib/babel/intro.org: Delete unnecessary leading commas in some blocks

2024-08-13 Thread Ihor Radchenko
"shynur ."  writes:

> These commas are confusing.
> ...
> #+begin_src org
>,#+begin_src   
> -  ,
> +  

batch replace is easy to mess up, yes.
Thanks for the patch!
Applied.
https://git.sr.ht/~bzg/worg/commit/a27404f5

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



Re: [PATCH v4.0] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer

2024-08-13 Thread stardiviner
I agree with your patch solution. I have tested fine. Thanks for your
re-write.

I have an idea, would you like to add an function in bellowing:

#+begin_src emacs-lisp
(defun org-toggle-inline-images-in-results ()
  "Toggle inline images in babel source block results."
  (save-excursion
;; [C-c C-v C-o] `org-babel-open-src-block-result'
(let ((begin (org-babel-where-is-src-block-result))
  (end (progn
 (end-of-line)
 (skip-chars-forward " \r\t\n")
 (looking-at org-link-bracket-re)
 ;; (org-babel-read-result)
 (point
  (org-toggle-inline-images-command nil begin end

(add-hook 'org-babel-after-execute-hook
'org-toggle-inline-images-in-results)
#+end_src

WDYT? after all I originally propose this patch for this purpose to
improve the babel result inline image toggle displaying performance.


[stardiviner] GPG key ID: 47C32433
IRC(freeenode): stardiviner Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/


On Mon, Aug 12, 2024 at 6:17 PM Ihor Radchenko  wrote:

> "Christopher M. Miles"  writes:
>
> >> What about the following treatment of ARG:
> >>
> >> 1. No argument, no region selected :: toggle (display or hide dwim)
> images in current section
> >> 2. No argument, region selected: toggle images in region
> >> 3. C-u argument :: toggle images in the whole buffer
> >> 4. C-u C-u argument, no region selected :: unconditionally hide images
> in the buffer
> >> 5. M-1 argument, no region selected :: display images in current
> section with INCLUDE-LINKED
> >> 6. M-1 argument, region selected :: ... in region ...
> >> 7. M-11 argument :: ... in the whole buffer ...
> >> 8. Any other argument :: treat as INCLUDE-LINKED = t
> >>
> >> And please document all the new arguments in the manual and
> etc/ORG-NEWS file.
> >
> > I followed you upper 8 conditions to re-write my patch.
> > Except the 8. condition I'm not sure I understand correctly.
> > And I extend 1. condition to support the inline image link at point
> toggle displaying.
> > ...
>
> I do not like the code repetitions in the patch and relying upon
> `use-region-p' even for non-interactive use.
>
> I am attaching a complete rewrite of your idea.
> Please let me know if my patch does everything you want to include into
> the command.
>
> Note that I went with a new idea of introducing a branch new function
> instead of changing `org-toggle-inline-images'.  This way, existing
> users of `org-toggle-inline-images' will not be affected at all.  We are
> just changing the default C-c C-x C-v binding.  This way, the breakage
> is a little as possible.
>
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at .
> Support Org development at ,
> or support my work at 
>