Re: [PATCH] org-babel-demarcate-block: duplicate switches too

2024-01-02 Thread Ihor Radchenko
gerard.vermeu...@posteo.net writes:

>> Thanks for the patch!
>> Would you mind also adding a test for `org-babel-demarcate-block' in
>> testing/lisp/test-ob.el?
>
> I have attached a new patch with a test named 
> `test-ob/demarcate-block-split'.
> Besides testing the duplication of switches and some header arguments, 
> it also
> shows that multi-line header arguments are not duplicated.
>
> Whether this is a bug or a feature in `org-babel-demarcate-block' may be 
> a
> point of discussion. I have no real opinion.

IMHO, this is a bug.
The current approach with regexp matching in `org-babel-demarcate-block'
is clearly not accurate. What would be more robust is using
org-element-at-point + org-element-copy + set :value +
org-element-interpret-data to carry over all the affiliated keywords and
header arguments.

> The code of the 4 (should ...) forms in the test below the line
> ;; unduplicated multi-line header arguments:
> feels a bit clumsy. Does Org have a function to extract the value that a 
> particular
> var-name has from the association list returned by 
> `org-babel-get-src-block-info'?

(org-babel--get-vars (nth 2 (org-babel-get-src-block-info)))

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



[PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization

2024-01-02 Thread dark . key8799
On Sun, Dec 31, 2023, at 22:42, Ihor Radchenko wrote:

> I do not see why we shouldn't add such a hook. Patches welcome!

Would this work?

-- 
Alexandre Avanian

0001-lisp-org-indent.el-Add-hook-to-run-after-it-initiali.patch
Description: Binary data


Re: [PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization

2024-01-02 Thread Ihor Radchenko
dark.key8...@151e.ai writes:

>> I do not see why we shouldn't add such a hook. Patches welcome!
>
> Would this work?

Yes, but please address some minor comments.

> +(defcustom org-indent-post-buffer-init-hook nil
> +  "Hook run after org-indent finishes initializing a buffer.
> +The function(s) in in this hook must accept a single argument representing
> +the initialized buffer."
> +  :group 'org-indent
> +  :type 'hook)

By convention, abnormal hooks (hooks that require arguments) are named
as *-functions, not *-hook.

Also, when adding new customizations, we generally announce them in
etc/ORG-NEWS.

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



#5 [[bbb:OrgMeetup]] on Wed, Jan 17, 19:00 UTC+3

2024-01-02 Thread Ihor Radchenko
Dear all,

Another OrgMeetup will be scheduled on the third Wednesday of January,
in two weeks.

Previous meetup notes:
https://list.orgmode.org/87bkanr76o.fsf@localhost/

URL: https://bbb.emacsverse.org/b/iho-h7r-qg8-led
Time & Date: <2024-01-17 Wed 19:00-21:00 @+03,Europe/Istanbul>
The room will be open half an hour before the official start.

During the meetup, we can:

- Give advice to new users
- Showcase Org configs or workflows
- Demo/discuss interesting packages
- Troubleshoot each-other's issues
- Discuss "Org mode" section of Emacs news (https://sachachua.com/blog/)
- Discuss anything else Org-related

Everyone is free to join the discussion/chat or lurk around silently,
listening.

We will _not_ do any recording by default.

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



Re: Should org-link-parser add type "file" when link has no "file:" prefix?

2024-01-02 Thread Ihor Radchenko
Joseph Turner  writes:

>> See `org-open-file' IN-EMACS argument - we may use different handlers
>> to open file links. Currently, IN-EMACS can be 'system or 'emacs. But
>> nothing stops us from adding more options.
>
> Thanks!  Are you suggesting something like [[file+hyper:/README.org]] ?

Yes.

>> This will cause major issues when trying to export such links.
>> Except for HTML export that utilizes `org-html-link-use-abs-url', but
>> only for relative links.
>
> Yes, there are many users who rely on [[file:/index.html]] exporting to
>  instead of .

This is not what Org HTML export does. Only relative links are affected
by `org-html-link-use-abs-url':

Documentation
Should we prepend relative links with HTML_LINK_HOME?

Absolute links always remain absolute.

>> Why not make [[hyper:/README.org]] use the "default" hyperdrive the
>> Org file belongs to.
>
> I'd like for users to be able to take an existing directory of Org mode
> documents and copy them all into a hyperdrive.  I think the least
> surprising behavior is for the links between those files to continue
> working.  Perhaps the best option is for hyperdrive.el to make all "file"
> type links, explicit or not, point to other files inside the hyperdrive?
>
> In that case, there would be no way for Org mode files in a hyperdrive
> to point to the local filesystem.  Similarly, when Org documents are
> exported to HTML, there's no way to export .

May you please elaborate? How is hyperdrive directory different from
local directory?

>> For example, see WIP patch where we expose setting id: link properties:
>> https://list.orgmode.org/orgmode/c98a38b0-6dea-4b5c-b00f-a39ea9225...@app.fastmail.com/
>
> How would the :follow function for "file:" links get access to the link
> search option?  IIUC, `org-link-open' handles "file:" links specially because
> they require
>
> (org-element-property :search-option link)

:follow functions are passed both path and search option.

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



Re: [PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization

2024-01-02 Thread dark . key8799
On Tue, Jan 2, 2024, at 19:15, Ihor Radchenko wrote:
> By convention, abnormal hooks (hooks that require arguments) are named
> as *-functions, not *-hook.
>
> Also, when adding new customizations, we generally announce them in
> etc/ORG-NEWS.

Understood. Please find amended patch.

-- 
Alexandre Avanian

0001-lisp-org-indent.el-Add-hook-to-run-after-it-initiali.patch
Description: Binary data


Re: [PATCH v2] org-id: allow using parent's existing id in links to headlines

2024-01-02 Thread Rick Lupton
On Mon, 18 Dec 2023, at 12:27 PM, Ihor Radchenko wrote:
> I played around with the patch a bit and found a couple of rough edges:
>
> 1. When I try to open a link to non-existing search target, like
>, I get a query to create a new
>heading. If I reply "yes", a new heading is created. However, the
>heading is created at the end of the file and is always level 1,
>regardless of the "some-id" parent context.
>It would make more sense to create a new heading at the end of the
>id:some-id subtree.

Thanks for the comments. On this point, I'd like to modify `org-insert-heading' 
to allow for choosing the level of the newly inserted heading, but first wanted 
to check if you have a preference for how to change it.


I think it would be simplest to change the current:

(defun org-insert-heading (&optional arg invisible-ok top)
  "...When optional argument TOP is non-nil, insert a level 1 heading, 
unconditionally."

to:

(defun org-insert-heading (&optional arg invisible-ok level)
  "...When optional argument LEVEL is a number, insert a heading at that level. 
 For backwards compatibility, when LEVEL is non-nil but not a number, insert a 
level-1 heading."

but that is not totally backwards compatible -- is that ok?


If it should be completely backwards compatible, alternatively could add an 
additional optional argument:

(defun org-insert-heading (&optional arg invisible-ok top top-level)
  "...When optional argument TOP is non-nil, insert a top-level heading, 
unconditionally.  When TOP-LEVEL is non-nil, use that level, otherwise level 1."


Alternatively I could preserve the intention of TOP but add a special value to 
change what "top-level" means, so the docstring would become something like 
this:

"When optional argument TOP is non-nil, insert a top-level
heading, unconditionally.  Specifically, when TOP is `relative',
\"top-level\" means one level deeper than the outline level at
minimum point position (respecting any narrowing of the buffer).
Otherwise, \"top-level\" means level 1."

(the motivation for this is that when the buffer is narrowed to the subtree 
with the matching ID, the new heading will be created at the appropriate level).


Best
Rick



org table export to latex, longtable, code does not compile

2024-01-02 Thread Uwe Brauer


Hi

I am running emacs 29 and org mode 9.6.9

I have set (setq org-latex-line-break-safe "")

Nevertheless the following example 
#+begin_src 
#+ATTR_LATEX: :environment longtable
| / |  <> |<> | <>   | <>   | <>   | <> 
  | <>   |
|---+-+---+--+--+--+--+--|
|   | Num | Documento | <2024-04-26> | <2024-04-29> | <2024-05-06> | 
<2024-05-08> | <2024-05-10> |
|---+-+---+--+--+--+--+--|
|   |   1 |  12345678 |  |  |  |
  |  |
|   |   2 |  12345678 |  |  |  |
  |  |
|   |   3 |  12345678 |  |  |  |
  |  |
|   |   4 |  12345678 |  |  |  |
  |  |
#+end_src

Will be translated to 

#+begin_src 

\begin{longtable}{|r|r|l|l|l|l|l|}
\hline
Num & Documento & \textit{26.04.2024} & \textit{29.04.2024} & 
\textit{06.05.2024} & \textit{08.05.2024} & \textit{10.05.2024}\\ \hline
\hline
\endfirsthead
\multicolumn{7}{l}{Continued from previous page} \\ \hline[0pt]
\hline

Num & Documento & \textit{26.04.2024} & \textit{29.04.2024} & 
\textit{06.05.2024} & \textit{08.05.2024} & \textit{10.05.2024} \\ \hline[0pt]

\hline
\endhead
\hline\multicolumn{7}{r}{Continued on next page} \\ \hline
\endfoot
\endlastfoot
\hline
1 & 12345678 &  &  &  &  & \\ \hline
2 & 12345678 &  &  &  &  & \\ \hline
3 & 12345678 &  &  &  &  & \\ \hline
4 & 12345678 &  &  &  &  & \\ \hline
\end{longtable}
#+end_src


#+begin_src 

And this does not compile for TL2023, it gives the following error:
Overfull \hbox (64.42285pt too wide) in alignment at lines 28--32
 [] [] [] [] [] [] [] 
./problem.tex:34: Misplaced \noalign.
\hline ->\noalign 
  {\ifnum 0=`}\fi \penalty \@M \futurelet \@let@token 
\LT@@h...l.34 \hline
   
./problem.tex:35: Misplaced \omit.
\multispan ->\omit 
   \@multispan 
l.35 
 
./problem.tex:38: Misplaced \noalign.
\hline ->\noalign 
  {\ifnum 0=`}\fi \penalty \@M \futurelet \@let@token 
\LT@@h...l.38 \hline
   
./problem.tex:39: Misplaced \omit.
\multispan ->\omit 
   \@multispan 
l.39 \endhead
#+end_src
 


The problem are the lines \hline[0pt]

I can query replace them, but is there any other solution.

Regards

Uwe Brauer 
-- 
I strongly condemn Hamas heinous despicable pogroms/atrocities on Israel
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the EU and NATO membership of Ukraine. 



smime.p7s
Description: S/MIME cryptographic signature


[SOLVED] (was: org table export to latex, longtable, code does not compile)

2024-01-02 Thread Uwe Brauer
>>> "UB" == Uwe Brauer  writes:

> Hi

> I am running emacs 29 and org mode 9.6.9

> I have set (setq org-latex-line-break-safe "")

> Nevertheless the following example 

This helped


(defun my-latex-insert-hline-always (row backend info)
  "Add a hline to every row when exporting to  LaTeX."
  (when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string "\\[0pt\\]\\|" " 
hline" row)))

(add-to-list 'org-export-filter-table-row-functions 
'my-latex-insert-hline-always)


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] org-babel-demarcate-block: split using org-element instead of regexp

2024-01-02 Thread gerard . vermeulen



On 02.01.2024 11:48, Ihor Radchenko wrote:

gerard.vermeu...@posteo.net writes:


[...]


IMHO, this is a bug.
The current approach with regexp matching in 
`org-babel-demarcate-block'

is clearly not accurate. What would be more robust is using
org-element-at-point + org-element-copy + set :value +
org-element-interpret-data to carry over all the affiliated keywords 
and

header arguments.


[...]


(org-babel--get-vars (nth 2 (org-babel-get-src-block-info)))


Attached you'll find a new patch trying to implement your suggestions.
Interactive splitting by demarcation seems to work quite well (see the
before and after splitting snippets in the PS).

However, I cannot run the test because org-babel-demarcate-block
always errors "org-element--cache: Emergency exit" while the same
input works interactively. Could there be a problem of cache
synchronization or something like that? Is there something I can do?

I also did not yet look into how to propagate a switch like -n10.

PS:
# begin before splitting snippet
#+caption[Demarcation splitting test]:
#+caption: Demarcation splitting test.
#+header: :var edge="also copied"
#+header: :wrap "src any-spanish -n"
#+name: lst:test
#+begin_src python -i -n :var here="copied" :wrap "src any-english -n"

# above-split

# below-split

#+end_src
# end before splitting snippet

# begin after splitting snippet
#+caption[Demarcation splitting test]:
#+caption: Demarcation splitting test.
#+header: :var edge="also copied"
#+header: :wrap "src any-spanish -n"
#+name: lst:test
#+begin_src python -i -n :var here="copied" :wrap "src any-english -n"

# above-split
#+end_src

#+header: :var edge="also copied"
#+header: :wrap "src any-spanish -n"
#+begin_src python -i -n :var here="copied" :wrap "src any-english -n"

# below-split
#+end_src
# end after splitting snippet


0001-org-babel-demarcate-block-split-using-org-element-in.patch
Description: Binary data


Re: [PATCH] Fix org-agenda-skip-scheduled-if-deadline-is-shown bug

2024-01-02 Thread Morgan Smith
Ihor Radchenko  writes:

> Morgan Smith  writes:
>
>> lisp/org-agenda.el (org-agenda-get-scheduled): Consolidate deadline
>> fetching code.  Don't check if deadline is shown when
>> 'org-agenda-skip-scheduled-if-deadline-is-shown' has a value of
>> 'repeated-after-deadline'.
>>
>> Currently when 'org-agenda-skip-scheduled-if-deadline-is-shown' has a
>> value of 'repeated-after-deadline' then there is no effect.  This is
>> because when 'org-agenda-get-scheduled' is run on later dates, the
>> previous deadlines are not put in 'deadline-pos'.
>
> May you please provide a detailed reproducer demonstrating the bug you
> are trying to fix? Such reproducer could be a basis of a new test.

See a detailed reproducer attached to this mail.  It has a task defined
as this:

* TODO task
SCHEDULED: <2017-03-06 Mon +2d> DEADLINE: <2017-03-10>

Running said reproducer currently fails as follows (the numbers are the
days of the month).

(string-equal
"06\nScheduled: task\n08\nScheduled: task\n10\nScheduled: task\nDeadline:  
task\n"
"06\nScheduled: task\n08\nScheduled: task\n10\nScheduled: task\nDeadline:  
task\n12\nScheduled: task\n")


As you can see, we expect to not see anything scheduled after the
deadline if 'org-agenda-skip-scheduled-if-deadline-is-shown' is set to
'repeated-after-deadline', however, we actually see that things continue
to be scheduled.  Hence the bug is that that option currently does
nothing.

>From d7e72b9f0189b98d7ae59f0a56d54ffe70583956 Mon Sep 17 00:00:00 2001
From: Morgan Smith 
Date: Tue, 2 Jan 2024 14:25:07 -0500
Subject: [PATCH] Testing: Add tests for
 'org-agenda-skip-scheduled-if-deadline-is-shown'

* testing/lisp/test-org-agenda.el
(test-org-agenda/org-agenda-skip-scheduled-if-deadline-is-shown): New test.
---
 testing/lisp/test-org-agenda.el | 45 +
 1 file changed, 45 insertions(+)

diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 409d44192..6618fabc5 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -651,6 +651,51 @@ functions."
   (should (= arg-f-call-cnt 1))
   (should (equal f-called-args '(1 2 3))
 
+(ert-deftest test-org-agenda/org-agenda-skip-scheduled-if-deadline-is-shown ()
+  "Test values for `org-agenda-skip-scheduled-if-deadline-is-shown'."
+  (cl-assert (not org-agenda-sticky) nil "precondition violation")
+  (cl-assert (not (org-test-agenda--agenda-buffers))
+ nil "precondition violation")
+  (dolist (test-time '("2017-03-06" "2017-03-10"))
+(let ((org-agenda-custom-commands
+   '(("f" "no fluff" agenda ""
+  ((org-agenda-overriding-header "")
+   (org-agenda-todo-keyword-format "")
+   (org-agenda-prefix-format "%s")
+   (org-agenda-format-date "%d")
+   (org-agenda-show-all-dates nil)
+  (org-deadline-warning-days 0)
+  (todayp (string= test-time "2017-03-10")))
+  (dolist (org-agenda-skip-scheduled-if-deadline-is-shown (list nil t 'not-today 'repeated-after-deadline))
+(org-test-at-time test-time
+  (org-test-agenda-with-agenda
+   "
+* TODO task
+SCHEDULED: <2017-03-06 Mon +2d> DEADLINE: <2017-03-10>
+"
+   (should
+(string-equal
+ (concat "06\n"
+ "Scheduled: task\n"
+ (if todayp ; We don't show repeats scheduled in the past
+ ""
+   "08\nScheduled: task\n")
+ "10\n"
+ (if (and org-agenda-skip-scheduled-if-deadline-is-shown
+  (not (and (not todayp) (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)))
+  (not (eq org-agenda-skip-scheduled-if-deadline-is-shown 'repeated-after-deadline)))
+ ""
+   (if todayp
+   "Sched. 4x: task\n"
+ "Scheduled: task\n"))
+ "Deadline:  task\n"
+ (unless (eq org-agenda-skip-scheduled-if-deadline-is-shown 'repeated-after-deadline)
+   "12\nScheduled: task\n"))
+ (progn
+   (org-agenda nil "f")
+   (substring-no-properties (buffer-string)
+   (org-test-agenda--kill-all-agendas)))
+
 
 
 (provide 'test-org-agenda)
-- 
2.41.0



Re: Are 'placement' and 'float' "obsolete terms" in inline images export

2024-01-02 Thread Juan Manuel Macías
Apologies for my delay in answering all the interesting questions
you raised in this last message. November and December have been
horrible work days for me (all publishers are always in a hurry) and I
haven't been able to attend to the mailing list as I would like...

Ihor Radchenko writes:

> Juan Manuel Macías  writes:
>
>>> What about :wrap?
>>
>> I like :wrap. What's more, remembering that old thread where
>> some questions about code before/after the image were discussed,
>> what if the expected value of :wrap were a kind of template? This would
>> allow code to be placed before and/or after (not just an environment)
>> the image, always within the float environment, if it exists. Something
>> like this:
>>
>> #+ATTR_LaTeX: :float nil :wrap 
>> \begin{minipage}[b]{10pc}\small\n%s\n\end{minipage} 
>> #+CAPTION: caption
>> [[file:foo.png]]
>> ...
>> #+ATTR_LaTeX: :float minipage :placement [b]{10pc} :caption 
>> \captionof{figure}{caption} 
>> [[file:foo.png]]
>>
>> I don't know if it would be appropriate to explain in the Manual that
>> doing so would not be... "correct"? I don't know if there is any term in
>> programming to designate these situations which, without being bugs, are
>> functionalities not consciously sought...
>
> What about making :wrap override :float completely + obsoleting :float.
> We can allow wrap to have special values like in float:
>
> :wrap t/:wrap multicolumn/:wrap sideways
>
> With these special values, :placement will be taken into account.

+1. Great idea.

> Further, we can make templates a bit more detailed.
> Starting from similar to what you proposed in the above
>
> :wrap \begin{minipage}[b]{10pc}\small\n%{body}\n\end{minipage}
>
> to more granular control over caption, centering, comment-include,
> and image-code:
>
> %{caption} %{caption-text} %{centering} %{comment} %{comment-text}
>  %{image} %{image-path}.
>
> If the :wrap text does not contain %{...} placeholder, it will be
> treated as what  :float artbirary-environment does.
>
> We may even consider something like
>
> #+name: latex-template
> #+begin_src latex :export none
>
> \begin{minipage}[b]{10pc}\small
> %{body}
> \end{minipage}
> #+end_src
>
> #+attr_latex: :wrap latex-template[]
>
> As a bonus, :wrap may allow prepending/appending arbitrary code to
> headings:
>
> * Heading starting at a new page
> :PROPERTIES:
> :ATTR_LATEX: :wrap \clarpage%{default}
> :END:

I really like what you propose, both the idea and the syntax. I think
that such a versatile template system (with such a level of granularity
but with a clear syntax at the same time) would be a killer feature. It
wouldn't be bad to also extend it to the case of tables and other
backends, such as html. I also think it would solve a "classic" Org
syntax issue (in my opinion) which is the difficulty in 'nesting things'.
Well, it can be done currently (for example, the special blocks do their job
pretty  well), but at the cost of increasing the verbosity of the code (I am
thinking, for example, of using the LaTeX threeparttable package through
nested special blocks...)

Best regards, and  happy New Year

-- 
Juan Manuel Macías




[PATCH] Add org-after-note-stored-hook

2024-01-02 Thread General discussions about Org-mode.

Hello,

I've been archiving tasks automatically using
`org-after-todo-state-change-hook' but I've been recently bit with a
note (entering a todo state configured with '@') being placed where the
task was before its archival.

This patch aims to offer a way to defer the archival after the
note is stored. Actually, I am using it like this:

#+begin_src elisp
(add-to-list 'org-after-todo-state-change-hook
   (lambda ()
 ;; States configured without mandatory note
 (when (member org-state '("DONE"))
   (my/org-roam-archive-to-today))
 ;; States configured with mandatory note
 (when (member org-state '("CANCELLED" "READ"))
   (add-to-list 'org-after-note-stored-hook 
'my/org-roam-archive-to-today
#+end_src

With `my/org-roam-archive-to-today' removing itself from
`org-after-note-stored-hook'.

Hopefully I did not miss an existing way to do this.

Regards,
Joris

>From 18de09a3aa08e3d06f180165530cbaeeccdf3ccf Mon Sep 17 00:00:00 2001
From: Joris Caravati 
Date: Tue, 2 Jan 2024 22:50:32 +0100
Subject: [PATCH] lisp/org.el: Add `org-after-note-stored-hook'

* lisp/org.el: Add `org-after-note-stored-hook' which is called at the
end of the `org-store-log-note' function.
* etc/ORG-NEWS: Document the new hook.

This change allows customization after a note is taken. One case where
it is useful is when one wants to move a task after a state change but
cannot do so in `org-after-todo-state-change' because the new state is
configured to take a note (with '@' in `org-todo-keywords').

Setting this hook in `org-after-todo-state-change' allows to defer the
move after the note is taken and prevents the note to be placed where
the task was before being moved.

TINYCHANGE
---
 etc/ORG-NEWS | 4 
 lisp/org.el  | 6 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c54473f55..911e8ffeb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -742,6 +742,10 @@ Completion is enabled for links to man pages added using ~org-insert-link~:
 =C-c C-l man RET emacscl TAB= to get =emacsclient=.  Of course, the ~ol-man~
 library should be loaded first.
 
+*** New hook [[doc::org-after-note-stored-hook][org-after-note-stored-hook]]
+
+This new hook runs when a note has been stored.
+
 ** New functions and changes in function arguments
 *** ~org-fold-hide-drawer-all~ is now interactive
 
diff --git a/lisp/org.el b/lisp/org.el
index 6e6e075b4..fad21d8ba 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1944,6 +1944,9 @@ Lisp variable `org-state'."
   :group 'org-todo
   :type 'hook)
 
+(defcustom org-after-note-stored-hook nil
+  "Hook which is run after a note was stored")
+
 (defvar org-blocker-hook nil
   "Hook for functions that are allowed to block a state change.
 
@@ -10729,7 +10732,8 @@ items are State notes."
   (with-current-buffer (marker-buffer org-log-note-return-to)
 (goto-char org-log-note-return-to))
   (move-marker org-log-note-return-to nil)
-  (when org-log-post-message (message "%s" org-log-post-message)))
+  (when org-log-post-message (message "%s" org-log-post-message))
+  (run-hooks 'org-after-note-stored-hook))
 
 (defun org-remove-empty-drawer-at (pos)
   "Remove an empty drawer at position POS.
-- 
2.38.5


Re: [PATCH] doc/org-manual.org (Summary): Clarify the Org markup is human-readable

2024-01-02 Thread Matt
  On Sun, 31 Dec 2023 16:22:00 +0100  Ihor Radchenko  wrote ---
 >
 > I'd like to amend the Org manual introduction as in the attached patch.
 > The idea is to highlight that Org markup is designed to be
 > human-readable first and foremost rather than just computer-readable.
 >
 > This is the first section of the manual. Most of the new users will see
 > it. So, I'd like to hear any objections before installing the patch.

I like the points about using any text editor and understanding Org
without an editor.  The main point, it seems, is Org mode avoids
lock-in.  Two perspectives, the author and the reader, are addressed.

An important question is, "Who are we writing to?"

Addressing authors and readers covers pretty much everyone, I think :)
I believe that makes these good points for the intro.

The first paragraph of the current introduction reads,

"Org Mode is an authoring tool and a TODO lists manager for GNU Emacs.
It relies on a lightweight plain-text markup language used in files
with the =.org= extension."

Since the first paragraph already mentions "lightweight plain-text
markup language," I think making a similar point in the next paragraph
is unnecessary.  It may be better to say what you want in the first
paragraph.

I like "human-readable."  It's clear and direct.  However, trying to
incorporate it into the first paragraph becomes heavy:

"Org Mode is an authoring tool and a TODO lists manager for GNU Emacs.
It relies on a human-readable, plain-text markup language used in
files with the =.org= extension."

That's a lot of hyphenated words and syllables!  Maybe "legible" would
be better?  It's more precise.  But maybe precise isn't good.  I'm
wondering if there's a simpler word that accommodates non-native
speakers better (and not just for this word).

"Org Mode is an authoring tool and a TODO lists manager for GNU Emacs.
It relies on a legible, plain-text markup language used in files with
the =.org= extension."

Last comment on your changes.  I understand what you mean by "with a
naked eye" and I think it's a valid point.  However, not everyone who
uses Emacs can see.  I wonder, do the benefits of Org syntax only
apply visually?

Several things in the first paragraph unrelated to your changes stick
out to me. I can't help but make some other remarks.

"TODO" should probably be "to-do".  Every dictionary I looked in has
an entry for "to-do".  I think that's the common spelling.

Regarding "markup language," that reads to me like programmer jargon.
What does it mean and why should someone care?  Again, who are we
writing to?  A markup language is a notation for formatting,
structure, and relationships.  I think it would be best to directly
say that.

I would also soften that Org "relies" on its markup.  It doesn't.  I
used Org only for lists for a long time.  I believe lists to be a
fundamental feature of Org (and hence a great item for the first
sentence).  Lists are as simple as dashes.  It's hard to say that
dashes before list items is a markup language.

Finally, I don't think the file extension is relevant for the first
paragraph.  Technically, an extension isn't necessary.  A person can
call M-x org-mode or use a file local variable.  Worse, I think the
extension contradicts the point that any text editor can view an Org
file.  Ever try to open a .org file in Windows?  It asks for the
program.  Yes, *technically* Windows could open a .org file *if* the
person opening it knew which program to use (or to change the
extension to something like .txt).  Again, who are we writing to?  If
it's someone who believes file extensions matter, then this would
introduce unnecessary friction.  It seems best to avoid it.  Better to
do as you've done and say Org is readable (which it is) rather than
specify the extension (which doesn't really matter).

Text encodings notwithstanding (plain-text is only as portable as far
as you can guess the encoding), what do you think of something like
this?

modified   doc/org-manual.org
@@ -18,9 +18,10 @@
 :END:
 #+cindex: summary

-Org Mode is an authoring tool and a TODO lists manager for GNU Emacs.
-It relies on a lightweight plain-text markup language used in files
-with the =.org= extension.
+Org Mode is an authoring tool and a to-do lists manager for GNU Emacs.
+It uses a legible plain-text notation to show formatting, structure,
+relationships.  Anyone able to edit text can write using Org.  Anyone
+able to read text can view it.

 As an authoring tool, Org helps you write structured documents and
 provides exporting facilities. Org files can also be used for literate

--
Matt Trzcinski
Emacs Org contributor (ob-shell)
Learn more about Org mode at https://orgmode.org
Support Org development at https://liberapay.com/org-mode




Re: Elisp function to get the upcoming event with the closest scheduled date

2024-01-02 Thread Rodrigo Morales
Rodrigo Morales  writes:

I managed to show the entry with the nearest upcoming scheduled date in
the tab bar with the following utilities (see code block below). Here's
an screenshot:
https://upload.wikimedia.org/wikipedia/commons/f/f3/Show_information_of_Org_Agenda_in_tab-bar.png

Here are some notes of the code:

+ The function my/org-agenda-nearest-upcoming-scheduled-search performs
  linear search through all headings in all files listed in
  org-agenda-files in order to search the entry with the nearest
  upcoming scheduled date.
+ The variable my/org-agenda-nearest-upcoming-scheduled stores the
  information of the event.
+ I added my/org-agenda-nearest-upcoming-scheduled-display to
  tab-bar-format in order to display the information that I requested.

Because my/org-agenda-nearest-upcoming-scheduled-search uses linear
search it is a rather expensive operation if there are many entries to
look up. I haven't decided yet when this functino should be called so
that it is called the fewer amount of times and it actually shows th
entry with the nearest upcoming scheduled date. It is necessary that it
is called in the proper times so that the
my/org-agenda-nearest-upcoming-scheduled is updated accordingly when
setting the scheduled date for new entries.

#+BEGIN_SRC elisp
(defvar my/org-agenda-nearest-upcoming-scheduled nil
  "Store entry with the nearest upcoming scheduled date.

The value should store a CONS CELL whose CAR is the title of the
entry and the CDR is the date of the entry.")

(defun my/org-agenda-nearest-upcoming-scheduled-search ()
  "Set the value for variable that store the entry with the nearest upcoming 
scheduled date."
  (let (nearest-entry
;; Store the scheduled date in seconds of the current entry.
entry-scheduled
(current-time (float-time)))
;; Iterate through all files in `org-agenda-files'
(dolist (file org-agenda-files)
  (with-current-buffer (find-file-noselect file)
;; Iterate through all headings
(org-map-entries
 (lambda ()
   (when (and
  ;; Check the current entry has SCHEDULED
  (setq entry-scheduled (org-entry-get nil "SCHEDULED"))
  ;; If the currenty entry has SCHEDULED, we proceed
  ;; to convert it to seconds using org-2ft. We cannot
  ;; write org-entry-get and org-2ft in the same
  ;; expression because it is possible that
  ;; org-entry-get returns nil and org-2ft returns 0
  ;; when nil is passed, so we won't be checking that
  ;; the entry has SCHEDULED.
  (setq entry-scheduled (org-2ft entry-scheduled))
  ;; Check time of the entry is greater than the current time
  (> entry-scheduled current-time))
 ;; If there's no nearest entry yet, then store the
 ;; current entry as the nearest entry.
 ;;
 ;; We use an if conditional because for plist-put to
 ;; work, it is needed that the property list is not nil.
 (if (null nearest-entry)
 (setq nearest-entry
   `(:item ,(org-entry-get nil "ITEM")
 :scheduled ,entry-scheduled
 :scheduled-string ,(org-entry-get nil "SCHEDULED")
 :marker ,(point-marker)))
   ;; If a nearest entry has been found previously,
   ;; compare their scheduled time.
   (when (> (plist-get nearest-entry :scheduled) entry-scheduled)
 (plist-put nearest-entry :item (org-entry-get nil "ITEM"))
 (plist-put nearest-entry :scheduled entry-scheduled)
 (plist-put nearest-entry :scheduled-string (org-entry-get nil 
"SCHEDULED"))
 (plist-put nearest-entry :marker (point-marker)
(setq my/org-agenda-nearest-upcoming-scheduled nearest-entry)
(unless nearest-entry
  (error "No event with scheduled date than the current date was found."

(defun my/org-agenda-nearest-upcoming-scheduled-display ()
  (if my/org-agenda-nearest-upcoming-scheduled
  (progn
;; If the previously found entry has an scheduled date that has
;; already passed, let's search for a new upcoming scheduled.
(when (<
   (plist-get my/org-agenda-nearest-upcoming-scheduled :scheduled)
   (float-time))
  (my/org-agenda-nearest-upcoming-scheduled-search))
(let* ((time-difference
(truncate
 (-
  (plist-get my/org-agenda-nearest-upcoming-scheduled 
:scheduled)
  (float-time
   (days (/ time-difference 86400))
   (hours (/ (% time-difference 86400) 3600))
   (minutes (/ (% time-difference 3600) 60)))
  ;; TODO: The following is a list of menu items. I still
  ;; do