Re: [BUG] SPACE jumps to tag in header line after hidden emphasis marker [9.7-pre (release_9.6.7-562-g5b6268 @ /home/jschmidt/work/org-mode/lisp/)]

2023-07-19 Thread Jens Schmidt

On 2023-07-19  09:10, Ihor Radchenko wrote:


I see no good way to address this quickly, so I re-added stickiness to
the opening emphasis marker, as you suggested.

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=724135dda

Follow-ups:
1. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64724 (for Emacs point
adjustment rules)
2. https://orgmode.org/list/87edl41jf0.fsf@localhost (for proper
handling of emphasis markers when moving across words)


Thanks.

What a wasps' nest.



[PATCH] org-clock-sum: Rewrite function to improve performance

2023-07-19 Thread Morgan Smith
* lisp/org-clock.el(org-clock-sum): Rewrite function using
'org-element-map' to traverse the file instead of searching.
---

Hello!

I have a very big file with lots of clock entries and refreshing my clocktable
has become slow.  Using '(benchmark-elapse (org-ctrl-c-ctrl-c))' I saw that it
took 5.660532903 seconds to refresh it!  After this rewrite it only takes
3.384914703 seconds.  Not great, but better.

Thanks,

Morgan

 lisp/org-clock.el | 148 +-
 1 file changed, 54 insertions(+), 94 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 264774032..148af864b 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -33,15 +33,10 @@
 
 (require 'cl-lib)
 (require 'org)
+(require 'org-element)
 
 (declare-function calendar-iso-to-absolute "cal-iso" (date))
 (declare-function notifications-notify "notifications" ( params))
-(declare-function org-element-property "org-element-ast" (property node))
-(declare-function org-element-contents-end "org-element" (node))
-(declare-function org-element-end "org-element" (node))
-(declare-function org-element-type "org-element-ast" (node  
anonymous))
-(declare-function org-element-type-p "org-element-ast" (node types))
-(defvar org-element-use-cache)
 (declare-function org-inlinetask-at-task-p "org-inlinetask" ())
 (declare-function org-inlinetask-goto-beginning "org-inlinetask" ())
 (declare-function org-inlinetask-goto-end "org-inlinetask" ())
@@ -1948,100 +1943,65 @@ each headline in the time range with point at the 
headline.  Headlines for
 which HEADLINE-FILTER returns nil are excluded from the clock summation.
 PROPNAME lets you set a custom text property instead of :org-clock-minutes."
   (with-silent-modifications
-(let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
-  org-clock-string
-  "[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ 
\t]+\\([0-9]+\\):\\([0-9]+\\)\\)"))
-  (lmax 30)
-  (ltimes (make-vector lmax 0))
-  (level 0)
-  (tstart (cond ((stringp tstart) (org-time-string-to-seconds tstart))
+(let* ((tstart (cond ((stringp tstart) (org-time-string-to-seconds tstart))
 ((consp tstart) (float-time tstart))
 (t tstart)))
   (tend (cond ((stringp tend) (org-time-string-to-seconds tend))
   ((consp tend) (float-time tend))
   (t tend)))
-  (t1 0)
-  time)
+   (file-total 0))
   (remove-text-properties (point-min) (point-max)
- `(,(or propname :org-clock-minutes) t
-   :org-clock-force-headline-inclusion t))
-  (save-excursion
-   (goto-char (point-max))
-   (while (re-search-backward re nil t)
-  (let* ((element (save-match-data (org-element-at-point)))
- (element-type (org-element-type element)))
-   (cond
-((and (eq element-type 'clock) (match-end 2))
- ;; Two time stamps.
- (let* ((timestamp (org-element-property :value element))
-(ts (float-time
-  (org-encode-time
-   (list 0
- (org-element-property :minute-start timestamp)
- (org-element-property :hour-start timestamp)
- (org-element-property :day-start timestamp)
- (org-element-property :month-start timestamp)
- (org-element-property :year-start timestamp)
- nil -1 nil
-(te (float-time
-  (org-encode-time
-   (list 0
- (org-element-property :minute-end timestamp)
- (org-element-property :hour-end timestamp)
- (org-element-property :day-end timestamp)
- (org-element-property :month-end timestamp)
- (org-element-property :year-end timestamp)
- nil -1 nil
-(dt (- (if tend (min te tend) te)
-   (if tstart (max ts tstart) ts
-   (when (> dt 0) (cl-incf t1 (floor dt 60)
-((match-end 4)
- ;; A naked time.
- (setq t1 (+ t1 (string-to-number (match-string 5))
- (* 60 (string-to-number (match-string 4))
-((memq element-type '(headline inlinetask)) ;A headline
- ;; Add the currently clocking item time to the total.
- (when (and org-clock-report-include-clocking-task
-(eq (org-clocking-buffer) (current-buffer))
-(eq (marker-position org-clock-hd-marker) (point))
-

Re: Dates in headlines

2023-07-19 Thread Max Nikulin

On 18/07/2023 16:24, Ihor Radchenko wrote:

Max Nikulin writes:


The footnote on dates in heading title was added in response to

Links to datestamped headings broken? Thu, 24 Feb 2011 16:49:14 +1300

3765304c8 2011-06-28 15:30:50 +0200 Bastien Guerry: doc/org.texi:
footnote: don't put timestamps in headlines.

however removing of timestamps was dropped during migration to org-element:


I have removed this footnote in 5adde9f3f.
Are you saying that there are still some bugs related to this topic?


My intention was just to explain origin of that footnote and to confirm 
that it was an obsolete one. I have no idea why timestamps were removed 
while storing links to headings in the initial Org mode commit. Perhaps, 
the change to preserve timestamps was not intentional, but since it 
happened a decade ago and nobody has complained, there is no point in 
changing current behavior.






Re: [BUG] `org-delete-char` and `org-delete-backward-char` don't respect `delete-active-region`

2023-07-19 Thread Ihor Radchenko
Okamsn  writes:

> With your clarification, I am asking that Org commands be added/changed 
> to support `delete-active-region`.

Maybe something like below? (100% untested)

(defun org-delete-forward-char (N)
  "Like `delete-forward-char', insert whitespace at field end in tables.
When deleting, in tables this function will insert whitespace in front
of the previous \"|\" separator, to keep the table aligned.  The table
will still be marked for re-alignment if the field did fill the entire
column, because, in this case the deletion might narrow the column."
  (interactive "p")
  (save-match-data
(if (and (= N 1)
 (not overwrite-mode)
 (not (org-region-active-p))
 (not (eq (char-after) ?|))
 (looking-at-p ".*?|")
 (org-at-table-p))
(org-delete-char 1)
  (funcall-interactively #'delete-forward-char N)
  (org-fix-tags-on-the-fly


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



Re: [BUG] WORG example for ob-lilypond is no longer working as described (was: Moving some lisp/ob-*.el files to org-contrib - your advice?)

2023-07-19 Thread Jonathan Gregory


On 18 Jul 2023, Ihor Radchenko wrote:


Jonathan Gregory  writes:

I also checked what will happen with future versions, and it 
looks like \version "2.24.1" actually means >=.


That's good to know.

I know version 2.20.0 works without the update, so perhaps we 
could set those variables conditionally, WDYT?


\version "2.20"
#(if (ly:get-option 'use-paper-size-for-page)
 (begin (ly:set-option 'use-paper-size-for-page #f)
(ly:set-option 'tall-page-formats 'pdf)))


I do not mind. But remember that we are talking just about an 
example file. What you are suggesting appears to be closer to 
what we might do in ob-lilypond itself, when calculating default 
layout.


That would be even better, I agree.

Can you test my patch?

Command-line options are normally added to 
`org-babel-lilypond-ly-command`, but since we're trying to set 
variables conditionally to accommodate different versions, I don't 
see how we can do this without using scheme. WDYT?


Side note: ob-lilypond even has 
`org-babel-lilypond-toggle-midi-play' that plays sound 
corresponding to the lilypond source. Pretty cool, especially in 
the context of the discussion about non-textual output types in 
babel. 
https://list.orgmode.org/orgmode/87ttu95xst.fsf@localhost/


Sure, I'll think about adding a MIDI example as well.


--
Jonathan
diff --git a/lisp/ob-lilypond.el b/lisp/ob-lilypond.el
index 9693b89e2..3cbdd2b27 100644
--- a/lisp/ob-lilypond.el
+++ b/lisp/ob-lilypond.el
@@ -183,6 +183,12 @@ specific arguments to =org-babel-tangle=."
 	 (in-file (org-babel-temp-file "lilypond-")))
 
 (with-temp-file in-file
+  ;; To create music fragments suitable for mixing music and text,
+  ;; newer versions of lilypond require setting at least the
+  ;; following two variables introduced in version 2.22.
+  (insert "#(if (ly:get-option 'use-paper-size-for-page)
+(begin (ly:set-option 'use-paper-size-for-page #f)
+(ly:set-option 'tall-page-formats 'pdf)))\n")
   (insert (org-babel-expand-body:generic body params)))
 (org-babel-eval
  (concat
@@ -199,7 +205,9 @@ specific arguments to =org-babel-tangle=."
   (file-name-sans-extension out-file)
   " "
   cmdline
-  in-file) "")) nil)
+  in-file)
+ ""))
+  nil)
 
 (defun org-babel-prep-session:lilypond (_session _params)
   "Return an error because LilyPond exporter does not support sessions."


Is there a better (built-in) way to insert an org link with title as description?

2023-07-19 Thread Arthur Miller


Hello Org experts,

I want to auto insert a title from an HTML page as description for an org link 
in
my notes. I stumbled upon some old message by Miro Bezjak on this list:

https://lists.gnu.org/archive/html/emacs-orgmode/2012-09/msg01435.html

I have seen the replies, but I am not sure how to use
org-make-link-description-function, so I coded my own version of Miros idea:

#+begin_src emacs-lisp
(defun org-link-from-clipboard ()
  "Insert an org link into current buffer from an URL in clipboard."
  (interactive)
  (let ((marker (point-marker))
(url
 (if (string-match-p "^\\(http\\|https\\)://" (current-kill 0))
 (current-kill 0)
   (read-string "URL: ")))
(title nil))
(when url
  (url-retrieve url
   (lambda (buffer)
 (goto-char (point-min))
 (when (re-search-forward "\\(.*\\)" nil t)
   (setq title (string-trim (match-string-no-properties 1
 (with-current-buffer (marker-buffer marker)
   (save-excursion
 (goto-char (marker-position marker))
 (org-insert-link
  nil url (or title (read-string "Description: "))
   nil t t
#+end_src

While my function is not very big, I would still like to learn how to use the
suggested built-in stuff from that discussion. I also dislike the interactive
fallback in asynchronous callback if the title is not found, but I would also
dislike to have a bunch of "No description found" strings in my notes too, so I
am not sure which one is less evil there.

Thankful for any help and advice.



Re: eval with :dir in included file

2023-07-19 Thread Dominique Dumont
On Friday, 7 July 2023 17:44:10 CEST Ihor Radchenko wrote:
> No, currently.
> We do something similar in `org-export--update-included-link', but not
> for :dir.

Thanks for the quick answer.

FTR, I'm now using ':eval never-export' [1] to workaround this issue.

All the best

[1] https://orgmode.org/manual/Evaluating-Code-Blocks.html








Re: [POLL] Add command names to key bindings in Org Guide? (was: Suggestion: for each listed keybinding, also name the command)

2023-07-19 Thread Ihor Radchenko
Ihor Radchenko  writes:

> Yuval Langer  writes:
>
>> For many commands, I find it helpful to first learn their names before
>> learning their keybindings. The org-mode guide does not include
>> command names.
>>
>> I want to add command names into the org-mode guide. I have attached
>> an example of such an addition.
>
> Will it be useful?

Done.

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



Re: [PATCH] Testing: Ensure 'org-id-locations-file' is set before updating

2023-07-19 Thread Ihor Radchenko
Morgan Smith  writes:

> Previously, when trying to run the tests in a container limited to the
> org repository, it fails because it can't create the directory
> "~/.emacs.d/.org-id-locations".
>
> * testing/org-test.el (org-test-load): Move setting
> 'org-id-locations-file' from here ...
> org-test-update-id-locations: ... to here
> ---
>
> Hello!  This fix allows me to run the tests without giving it access to the
> filesystem outside of the repository.  I have no clue what org-id-locations 
> are
> and I'm hoping someone else does so I don't have to learn.  I'm not sure if
> this is the best fix, but it works.

The whole

(defconst org-test-dir
  (expand-file-name (file-name-directory (or load-file-name buffer-file-name

is fishy when users attempt to run tests from normal Emacs session.

If you had issues with this variable from batch invocation, something
should be fixed in the defconst, I think.

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



Re: [PATCH] lisp/org-table.el: Allow named columns on lhs

2023-07-19 Thread Ihor Radchenko
Gavin Downard  writes:

> This patch does prioritize named columns over named fields, which can
> break compatibility in tables with a named column and named field with
> the same name. Alternatively, we could prioritize named fields to
> preserve compatibility, but since named columns are prioritized on the
> rhs, it could be pretty confusing.

Makes sense.
Do I understand correctly the named columns where not allowed at all in
the left side of the formulas previously?

> This change breaks compatibility in tables with a named field and named
> column with the same name, when that name is used on the lhs of a formula.

Please, document this in the new as well.

> +*** Spreadsheets now support named columns on the lhs
> +
> +Spreadsheet formulas can now use named column references on the lhs.

lhs is not a commonly known abbreviation.

Also, may you document the priority of named columns in 3.5.10 Advanced
features section of the manual?

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



Re: [BUG] SPACE jumps to tag in header line after hidden emphasis marker [9.7-pre (release_9.6.7-562-g5b6268 @ /home/jschmidt/work/org-mode/lisp/)]

2023-07-19 Thread Farblos

On 2023-07-18  10:13, Ihor Radchenko wrote:


Confirmed.


Thanks for caring about this so quickly ...


https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64696


... and for the discussion with Eli & co.  Which I did not try to follow 
TBH.



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


Well, I have one not-so-minor nit here: With that commit you cannot 
insert text *before* some text having hidden emphasis without breaking 
the emphasis.  More concretely (in an empty org-mode buffer):


 t   ;; org-self-insert-command
 e   ;; org-self-insert-command
 s   ;; org-self-insert-command
 t   ;; org-self-insert-command
 SPC ;; org-self-insert-command
 =   ;; org-self-insert-command
 t   ;; org-self-insert-command
 e   ;; org-self-insert-command
 s   ;; org-self-insert-command
 t   ;; org-self-insert-command
 =   ;; org-self-insert-command
 SPC ;; org-self-insert-command
 t   ;; org-self-insert-command
 e   ;; org-self-insert-command
 s   ;; org-self-insert-command
 t   ;; org-self-insert-command
 C-;; left-word
 C-;; left-word
 SPC ;; org-self-insert-command

The last SPC breaks the emphasis around the middle "test", which it did 
not previously.  Previously, the SPC would just move the whole 
emphasized word one space to the right.  Which I somehow got used to, 
and probably many others as well.


OTOH, to fix my bug, only the first of the new `org-rear-nonsticky-at' 
calls is actually needed.  So probably we could have something like the 
following to get my bug fixed without any changes in behavior (diff on 
top of main, that is, in addition to your commit):


diff --git a/lisp/org.el b/lisp/org.el
index 0d8b5386c..71f482f64 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5153,8 +5153,7 @@ stacked delimiters is N.  Escaping delimiters is 
not possible."
 ;; 
https://orgmode.org/list/8b691a7f-6b62-d573-e5a8-80fac3dc9...@vodafonemail.de

 (org-rear-nonsticky-at (match-beginning 5))
(add-text-properties (match-beginning 3) (match-end 3)
-'(invisible t))
-(org-rear-nonsticky-at (match-end 3)))
+'(invisible t)))
  (throw :exit t

 (defun org-emphasize ( char)




Re: [BUG] SPACE jumps to tag in header line after hidden emphasis marker [9.7-pre (release_9.6.7-562-g5b6268 @ /home/jschmidt/work/org-mode/lisp/)]

2023-07-19 Thread Ihor Radchenko
Ihor Radchenko  writes:

>> OTOH, to fix my bug, only the first of the new `org-rear-nonsticky-at' 
>> calls is actually needed.  So probably we could have something like the 
>> following to get my bug fixed without any changes in behavior (diff on 
>> top of main, that is, in addition to your commit):
>
> I am not sure if it is a proper fix. The basic problem is that Org's
> syntax table does not declare emphasis markup as part of a word.
>
> I need to consult Emacs devs about rules of point adjustment.

I see no good way to address this quickly, so I re-added stickiness to
the opening emphasis marker, as you suggested.

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=724135dda

Follow-ups:
1. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64724 (for Emacs point
   adjustment rules)
2. https://orgmode.org/list/87edl41jf0.fsf@localhost (for proper
   handling of emphasis markers when moving across words)

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



[BUG] Emphasis markers should be considered word constituents (was: [BUG] SPACE jumps to tag in header line after hidden emphasis marker [9.7-pre (release_9.6.7-562-g5b6268 @ /home/jschmidt/work/org-m

2023-07-19 Thread Ihor Radchenko
> Jens Schmidt  writes:
> ...
>> Well, I have one not-so-minor nit here: With that commit you cannot 
>> insert text *before* some text having hidden emphasis without breaking 
>> the emphasis.  More concretely (in an empty org-mode buffer):
>>

(setq org-hide-emphasis-markers t)

*foo*

>> ...
>>   C-;; left-word
>>   SPC ;; org-self-insert-command
>>
>> The last SPC breaks the emphasis around the middle "test", which it did 
>> not previously.  Previously, the SPC would just move the whole 
>> emphasized word one space to the right.  Which I somehow got used to, 
>> and probably many others as well.

The root cause revealed by my change is that Org mode does not always
consider emphasis markers to be word boundaries.

Note how when you do not hide emphasis markers, C- will end up in

 *foo*

When emphasis markers are not hidden, things were the same, except that
Emacs adjusted point right to sticky invisible text in the direction of
point movement, leading to inconsistent behaviour between hiding and not
hiding emphasis markers.

Yet, Org sometimes does treat emphasis markers as word constituents:
At least, `org-fill-element' and `org-transpose-words' temporarily turn
emphasis markers into parts of words.

The situation is clearly a bit chaotic.

One of the reasons why we have such a mess is because *_/~+ are not
always representing emphasis. Proper distinction between *_/~+ that are
and aren't part of actual emphasis would require a custom
`syntax-propertize-function' that would query Org element API to
determine the context.

Unfortunately, using `syntax-propertize-function' it is not very
practical yet.

We need parser context down to object level, while we only cache parser
state down to element (paragraph) level. So, querying element API in
this case will lead to significant performance degradation, with
quadratic (N_objects_in_paragraph^2) complexity in some cases.

I will leave this bug report open until we have a better caching and can
reasonably implement custom `syntax-propertize-function'.

Or, if any, please post arguments against making emphasis markers word
constituents.

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