Re: [Need Help] Error to evaluate "mpv" command in inline src block

2023-04-29 Thread General discussions about Org-mode.


stardiviner  writes:

> I have example Org file like bellowing.
>
> Here is the testing Org content:
>
> #+begin_src org
> ,* 《枕刀歌》
> :PROPERTIES:
> :DATE: [2021-05-13 Thu 20:09]
> :Douban:   https://movie.douban.com/subject/35350794/
> :DIR:  枕刀歌
> :EVAL: src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
> :END:
> #+end_src
>
> When I press Tab key to expand upper headline. I check the inline src block 
> session buffer, here is the output:
>
> #+begin_example
> bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
> org_babel_sh_prompt> echo 
> 'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
> mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
> echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
> ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
> org_babel_sh_prompt> =[input] No key binding found for key 'c'.
> [input] No key binding found for key 'h'.
> [input] No key binding found for key '''.
> [input] No key binding found for key 'b'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key 'n'.
> [input] No key binding found for key 'a'.
> [input] No key binding found for key 'y'.
> [input] No key binding found for key 'n'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key 'h'.
> [input] No key binding found for key 'n'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key 'b'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key 'a'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key 'b'.
> [input] No key binding found for key '''.
>
> Resuming playback. This behavior can be disabled with --no-resume-playback.
>
>  Video --vid=1 (*) (h264 1920x1080 25.000fps)
>  (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
> AO: [coreaudio] 48000Hz stereo 2ch floatp
> Mute: yes
>
>   C-c C-c>
> Saving state.
>
> Exiting... (Quit)
> org_babel_sh_prompt> echo $SHELL 
> /bin/zsh
> org_babel_sh_prompt> 
> #+end_example
>
> Then I try to replace the "mpv" shell command with another command without 
> need to invoke desktop GUI. Like bellowing Org content:
>
> #+begin_src org
> ,* 《枕刀歌》
> :PROPERTIES:
> :DATE: [2021-05-13 Thu 20:09]
> :Douban:   https://movie.douban.com/subject/35350794/
> :DIR:  枕刀歌
> :EVAL: src_sh{sleep 10; echo "done"}
> :END:
> #+end_src
>
> It evaluated fine.

Try putting "cat" there.  I suspect something is fed into the stdin of
the process.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]



[Need Help] Error to evaluate "mpv" command in inline src block

2023-04-29 Thread stardiviner
*** Reproduce and experience log

I have Emacs Org mode config like bellowing to auto evaluate inline src
block when Org headline cycle expanded.

#+begin_src emacs-lisp
;;; auto evaluate inline source block in property "EVAL".

(defcustom org-property-eval-keyword "EVAL"
  "A property keyword for evaluate code."
  :type 'string
  :safe #'stringp
  :group 'org)

(add-to-list 'org-default-properties org-property-eval-keyword)

(defun org-property-eval-on-cycle-expand ( state)
  "Evaluate Org inline source block in property value on headline cycle
expand."
  (when (memq state '(children subtree))
(if-let ((inline-src-block (org-entry-get nil org-property-eval-keyword
nil)))
(with-temp-buffer
  (insert inline-src-block)
  (goto-char (point-min))
  (let* ((context (org-element-context))
 (lang (org-element-property :language context))
 (type (org-element-type context))
 (src-block-info (org-babel-get-src-block-info nil
context)))
(when (eq type 'inline-src-block)
  (org-babel-execute-src-block
   nil src-block-info
   (pcase lang
 ("sh" `((:session . ,(make-temp-name " *ob-sh-inline-async
(sh) ")) (:async . "yes") (:results . "silent")))
 ("shell" `((:session . ,(make-temp-name "
*ob-sh-inline-async (shell) ")) (:async . "yes") (:results . "silent")))
 ("bash" `((:session . ,(make-temp-name "
*ob-sh-inline-async (bash) ")) (:async . "yes") (:results . "silent")))
 ("zsh" `((:session . ,(make-temp-name "
*ob-sh-inline-async (zsh) ")) (:async . "yes") (:results . "silent")))
 (_ '((:results . "none")))

(add-hook 'org-cycle-hook #'org-property-eval-on-cycle-expand)
#+end_src

I have example Org file like bellowing.

Here is the testing Org content:

#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE: [2021-05-13 Thu 20:09]
:Douban:   https://movie.douban.com/subject/35350794/
:DIR:  枕刀歌
:EVAL: src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
:END:
#+end_src

When I press Tab key to expand upper headline. I check the inline src block
session buffer, here is the output:

#+begin_example
bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo
'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
org_babel_sh_prompt> =[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key '''.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'y'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key '''.

Resuming playback. This behavior can be disabled with --no-resume-playback.

 Video --vid=1 (*) (h264 1920x1080 25.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [coreaudio] 48000Hz stereo 2ch floatp
Mute: yes



  C-c C-c>
Saving state.

Exiting... (Quit)
org_babel_sh_prompt> echo $SHELL
/bin/zsh
org_babel_sh_prompt>
#+end_example

Then I try to replace the "mpv" shell command with another command without
need to invoke desktop GUI. Like bellowing Org content:

#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE: [2021-05-13 Thu 20:09]
:Douban:   https://movie.douban.com/subject/35350794/
:DIR:  枕刀歌
:EVAL: src_sh{sleep 10; echo "done"}
:END:
#+end_src

It evaluated fine.

#+begin_example
sh-3.2$ sh-3.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo
'ob_comint_async_shell_start_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5'
sleep 10; echo "done"
echo 'ob_comint_async_shell_end_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5'
ob_comint_async_shell_start_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5
org_babel_sh_prompt> done
org_babel_sh_prompt>
ob_comint_async_shell_end_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5
org_babel_sh_prompt>
#+end_example

Even I testing using content directly instead of in "EVAL" property like
bellowing:

#+begin_src org
Test src_sh{pwd} {{{results(=/Users/stardiviner/Org/Wiki/ACG/Anime/Anime
Videos=)}}}
#+end_src

It works fine.

But I failed to 

Org-mode publish: Some questions when use it for a blog

2023-04-29 Thread Sébastien Gendre
Hello,

I try do generate a blog with Org-mode publish. 

I'm very impressed by the publishing tool. But as it's nice to do a
simple website, I have some difficulties to use it for a blog.

First, I try to customize the site map:

* Is it possible to customize the entry without writing a function ?
  Something like the preamble with escaped chars (ex %t, %d) ?

* How can I set a postamble in the sitemap different from my blog
  posts ?


Secondly, how can I put the author name and publication date just at the
bottom of the document title ? I tried with preamble, but the preamble
is inserted before the document that I cannot disable.


Finally, how can I generate the RSS feed ? I tried with ox-rss, but I
got an error about my version of Org:
Error (use-package): ox-rss/:catch: Invalid function: org-assert-version

Best regards



Re: [BUG] Filling in source blocks fills by region, not paragraph [9.5.5 (release_9.5.5/master)]

2023-04-29 Thread Ihor Radchenko
"Farblos"  writes:

> To me that seems strange, at least for source blocks.  If this is really 
> intended, it should probably be made configurable.

Canceled, by the original author.
https://list.orgmode.org/orgmode/59d95fcaa0e84b66a811d8fc181d6...@vodafonemail.de/

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



Re: [BUG] Filling in source blocks fills by region, not paragraph [9.5.5 (release_9.5.5/master)]

2023-04-29 Thread Farblos
Forget about that one, it is already fixed in master.  During my first test I 
used the wrong load path and thus used the distribution-provided org-mode 
version.





[BUG] Filling in source blocks fills by region, not paragraph [9.5.5 (release_9.5.5/master)]

2023-04-29 Thread Farblos
Cloned https://git.savannah.gnu.org/git/emacs/org-mode.git, changed to 
directory "org-mode", made "autoloads", started Emacs as "emacs -Q -L $PWD".

In an otherwise empty org-mode buffer, create a block

#+begin_src shell
# configure shell options and variables.  bash-completion
# requires shell option extglob, anyway, so set and use it
# without further pondering about adverse consequences.
shopt -s checkwinsize
shopt -s direxpand
shopt -s extglob
#+end_src

Move point into the comment part of that shell snippet and press M-q.  The 
result should look like this:

#+begin_src shell
  # configure shell options and variables.  bash-completion requires
  # shell option extglob, anyway, so set and use it without further
  # pondering about adverse consequences.  shopt -s checkwinsize shopt
  # -s direxpand shopt -s extglob
#+end_src

That is, code and comment got filled into one big comment.

When changing into edit mode first, only the comment part gets filled, as it 
would happen also in a real sh-mode buffer.

The root cause should be this snippet from `org-fill-element':

   (org-babel-do-in-edit-buffer
;; `org-babel-do-in-edit-buffer' will preserve region if it
;; is within src block contents.  Otherwise, the region
;; crosses src block boundaries.  We re-fill the whole src
;; block in such scenario.
(when (and regionp (not (region-active-p)))
  (push-mark (point-min))
  (goto-char (point-max))
  (setq mark-active t))
(funcall-interactively #'fill-paragraph justify 'region

where `fill-paragraph' gets called with an active region.

To me that seems strange, at least for source blocks.  If this is really 
intended, it should probably be made configurable.

Thanks

Jens

Emacs  : GNU Emacs 28.2 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 
1.16.0, Xaw3d scroll bars)
 of 2023-03-14, modified by Debian
Package: Org mode version 9.5.5 (release_9.5.5 @ 
/usr/share/emacs/28.2/lisp/org/)

current state:
==
(setq
 org-link-elisp-confirm-function 'yes-or-no-p
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn 
ENTRY)"]
 org-export-before-parsing-hook '(org-attach-expand-links)
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
  org-cycle-show-empty-lines
  org-optimize-window-after-visibility-change)
 org-mode-hook '(#[0 "\300\301\302\303\304$\207"
   [add-hook change-major-mode-hook org-show-all append local]
   5]
 #[0 "\300\301\302\303\304$\207"
   [add-hook change-major-mode-hook org-babel-show-result-all
append local]
   5]
 org-babel-result-hide-spec org-babel-hide-all-hashes)
 org-confirm-shell-link-function 'yes-or-no-p
 outline-isearch-open-invisible-function 'outline-isearch-open-invisible
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-src-mode-hook '(org-src-babel-configure-edit-buffer
 org-src-mode-configure-edit-buffer)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-speed-command-hook '(org-speed-command-activate
  org-babel-speed-command-activate)
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe
  org-babel-header-arg-expand)
 org-link-shell-confirm-function 'yes-or-no-p
 org-babel-pre-tangle-hook '(save-buffer)
 org-agenda-loop-over-headlines-in-active-region nil
 org-occur-hook '(org-first-headline-recenter)
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-link-parameters '(("attachment" :follow org-attach-follow :complete
org-attach-complete-link)
   ("id" :follow org-id-open)
   ("eww" :follow org-eww-open :store org-eww-store-link)
   ("rmail" :follow org-rmail-open :store
org-rmail-store-link)
   ("mhe" :follow org-mhe-open :store org-mhe-store-link)
   ("irc" :follow org-irc-visit :store org-irc-store-link
:export org-irc-export)
   ("info" :follow org-info-open :export org-info-export
:store org-info-store-link)
   ("gnus" :follow org-gnus-open :store
org-gnus-store-link)
   ("docview" :follow org-docview-open :export
org-docview-export :store org-docview-store-link)
   ("bibtex" :follow org-bibtex-open :store
org-bibtex-store-link)
   ("bbdb" :follow org-bbdb-open :export org-bbdb-export
:complete org-bbdb-complete-link :store
org-bbdb-store-link)
   ("w3m" :store 

Troubleshooting empty *Org PDF LaTeX Output*

2023-04-29 Thread John Kitchin
For a while the *Org PDF LaTeX Output* buffer has been empty for me when I
export to PDF.

I am currently using: Org mode version 9.7-pre (release_9.6.4-337-geaf274

It looks like this happens because of this code:

https://git.sr.ht/~bzg/org-mode/tree/main/item/lisp/ox-latex.el#L4313

It seems to have been added in
commit f0dfbf0c3999e44ef7b6704e6584aa2a5d43f2d8

Author: TEC 

Date:   Sun Dec 25 00:59:21 2022 +0800


ox-latex: Erase compile buffer at the start



* lisp/ox-latex.el (org-latex-compile): Before running the compile

command, erase the log buffer to ensure that stale/old logging is

cleared.


It seems like it is in the wrong place though, and it erases the buffer
after the compile happens.

It looks like the code should be modified to look like something like this:

(defun org-latex-compile (texfile  snippet)
  "Compile a TeX file.

TEXFILE is the name of the file being compiled.  Processing is
done through the command specified in `org-latex-pdf-process',
which see.  Output is redirected to \"*Org PDF LaTeX Output*\"
buffer.

When optional argument SNIPPET is non-nil, TEXFILE is a temporary
file used to preview a LaTeX snippet.  In this case, do not
create a log buffer and do not remove log files.

Return PDF file name or raise an error if it couldn't be
produced."
  (unless snippet (message "Processing LaTeX file %s..." texfile))
  (let* ((compiler
 (or (with-temp-buffer
(save-excursion (insert-file-contents texfile))
(and (search-forward-regexp (regexp-opt org-latex-compilers)
   (line-end-position 2)
   t)
(progn (beginning-of-line) (looking-at-p "%"))
(match-string 0)))
  ;; Cannot find the compiler inserted by
  ;; `org-latex-template' -> `org-latex--insert-compiler'.
  ;; Use a fallback.
  org-latex-compiler))
(process (if (functionp org-latex-pdf-process) org-latex-pdf-process
   ;; Replace "%latex" with "%L" and "%bib" and
   ;; "%bibtex" with "%B" to adhere to `format-spec'
   ;; specifications.
   (mapcar (lambda (command)
 (replace-regexp-in-string
   "%\\(?:\\(?:bib\\|la\\)tex\\|bib\\)\\>"
  (lambda (m) (upcase (substring m 0 2)))
  command))
   org-latex-pdf-process)))
 (spec `((?B . ,(shell-quote-argument org-latex-bib-compiler))
 (?L . ,(shell-quote-argument compiler
(log-buf-name "*Org PDF LaTeX Output*")
 (log-buf (and (not snippet) (get-buffer-create log-buf-name)))
 (outfile))
(with-current-buffer log-buf
  (erase-buffer))
(setq outfile (org-compile-file texfile process "pdf"
   (format "See %S for details" log-buf-name)
   log-buf spec))
(org-latex-compile--postprocess outfile log-buf snippet)
;; Return output file name.
outfile))

WDYT?
-- 
John

---
Professor John Kitchin (he/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
https://kitchingroup.cheme.cmu.edu
https://pointbreezepubs.gumroad.com/ pycse bookstore


Re: [PATCH] lisp/ob-scheme.el

2023-04-29 Thread Zelphir Kaltstahl

On 4/25/23 14:28, Ihor Radchenko wrote:

Zelphir Kaltstahl  writes:


Subject: [PATCH] org-babel-expand-body:scheme: define header arg vars using
  define

Applied, onto main, adding TINYCHANGE cookie and newline between
variable definitions and body.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d97ba5ba5

You are also now listed as Org contributor, thanks!
https://git.sr.ht/~bzg/worg/commit/eee4cb25


Thank you for taking care of the remaining work!

Best wishes,
Zelphir

--
repositories: https://notabug.org/ZelphirKaltstahl




Re: Dealing with inter-org links vs #+include

2023-04-29 Thread Ihor Radchenko
Brett Viren  writes:

> I want what may be two conflicting things:
>
> - Produce a monolithic HTML export of an main org file that #+include:'s
>   other org files.
>
> - Have links in the other org files that are valid both when the
>   monolith is exported to HTML and when visiting the individual org
>   files in Emacs.

I can see the rationale, but it is tricky.

> === a.org ===
> * A
>
> This is A.
> === b.org ===
> * B
>
> This is B.  Links:
> - [[file:a.org::*A][A by file with headline]].
> - [[A][A by headline only]].
>   
> === main.org ===
> ...
> * Includes
>
> #+include: a.org
> #+include: b.org

In this scenario, it indeed makes sense to replace links to a.org and
b.org with internal links.

However, someone who is exporting multiple files, including a.org/b.org
may actually want to keep links to a.org/b.org. In particular, when only
portions of a.org/b.org are included (like a single src block or certain
lines).

> * Links
>
> - A :: [[file:a.org]]
>
> - B :: [[file:b.org]]

And this is actually a scenario where it also makes more sense to keep
the links to a.org/b.org. If we follow your suggestion, these would be

> - A :: [[file:main.org]]
>
> - B :: [[file:main.org]]

which would look confusing.

For reference, I am attaching a patch that blindly converts links to
included files into links to the top-level includer. However, the patch
will fail for partially included files where the portions the links are
referencing are not actually included. It will also replace A:: and B::
links in the above example. So, it is not suitable for inclusion in Org
- we need some better idea how to handle other possible scenarios.

Suggestions welcome!
(For now, I do not see how we can handle the described scenarios
cleanly)

diff --git a/lisp/ox.el b/lisp/ox.el
index 480c484d4..1d6f4dff5 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3392,7 +3392,17 @@ (defun org-export-expand-include-keyword ( included dir footnotes inclu
(goto-char (point-max))
(maphash (lambda (k v)
   (insert (format "\n[fn:%s] %s\n" k v)))
-footnotes
+footnotes))
+;; Replace all the links to included files with links
+;; to top-level includer.
+(unless included
+  (org-with-wide-buffer
+   (org-export--map-links
+(lambda (link)
+  (org-export--update-included-link-file
+   (buffer-file-name (buffer-base-buffer))
+   (hash-table-keys file-prefix)
+   link)))
 
 (defun org-export-parse-include-value (value  dir)
   "Extract the various parameters from #+include: VALUE.
@@ -3606,15 +3616,17 @@ (defun org-export--inclusion-absolute-lines (file location only-contents lines)
 		   (while (< (point) end) (cl-incf counter) (forward-line))
 		   counter
 
-(defun org-export--update-included-link (file-dir includer-dir)
+(defun org-export--update-included-link (file-dir includer-dir  link)
   "Update relative file name of link at point, if possible.
 
 FILE-DIR is the directory of the file being included.
 INCLUDER-DIR is the directory of the file where the inclusion is
 going to happen.
 
+Optional argument LINK, when non-nil, holds the link object.
+
 Move point after the link."
-  (let* ((link (org-element-link-parser))
+  (let* ((link (or link (org-element-link-parser)))
 	 (path (org-element-property :path link)))
 (if (or (not (string= "file" (org-element-property :type link)))
 	(file-remote-p path)
@@ -3633,6 +3645,80 @@ (defun org-export--update-included-link (file-dir includer-dir)
 		   (org-element-property :end link))
 	(insert (org-element-interpret-data new-link))
 
+(defun org-export--update-included-link-file (new-file files  link)
+  "Replace file link paths to FILES with NEW-FILE.
+
+Absolute paths are replaced with NEW-FILE.  Relative paths are
+replaced with NEW-FILE relative to `default-directory'.
+
+FILES are assumed to be absolute paths.
+
+Optional argument LINK, when non-nil, holds the link object.
+
+Move point after the link."
+  (let* ((link (or link (org-element-link-parser)))
+	 (path (org-element-property :path link)))
+(if (or (not (string= "file" (org-element-property :type link)))
+(not (member (expand-file-name path) files)))
+(goto-char (org-element-property :end link))
+  (let ((new-path
+ (if (file-name-absolute-p path)
+ new-file (file-relative-name new-file)))
+	(new-link (org-element-copy link)))
+(if (equal new-path path)
+(goto-char (org-element-property :end link))
+  (if (not (org-element-property :search-option link))
+  (org-element-put-property new-link :path new-path)
+;; Internal link to included file.  Do not keep file
+;; type as `org-export-resolve-link' will look into the
+;; original file version without INCLUDE keywords
+ 

Re: "Indent headline data" is indenting non-headline-data

2023-04-29 Thread "James Harkins"
 On Thu, 27 Apr 2023 09:30:13 +0800  Ruijie Yu  wrote --- 
> Reproducible in built-in Org (9.5.5 release) from Emacs 28.2, but
> unreproducible in latest Org main branch (release_9.6.4-329-g466a37).
> So, assuming that this indeed is a bug, it has been fixed, but the fix
> is not present in your version.  Maybe you can try to install Org from
> elpa and see if that helps?

Thanks for confirming! If it's already fixed in some version, that's OK.

hjh