Re: TODO or checkboxes in org tables

2020-05-07 Thread Axel Kielhorn



> Am 07.05.2020 um 19:05 schrieb Uwe Brauer :
> 
 "AK" == Axel Kielhorn  writes:
> 
> Hi Alex
>>> Am 02.05.2020 um 21:33 schrieb Uwe Brauer :
>>> 
>> "AK" == Axel Kielhorn  writes:
>>> 
>>> Hi Alex,
>>> 
>>> I am not sure my first answer made it, so I apologize for a possible
>>> crossposting.
> 
>> It didn’t reach me.
> 
>>> A last question, which the command to generate the table
>>> org-insert-dblock:columnview ?
> 
>> I’m using:
> 
>> org-columns-insert-dblock
> 
> 
> That seems to be the same function I use. 
> 
> However I set the cursor on 
> ** Arbeitsfortschritt, 
> use that function and I obtain 
> 
> #+BEGIN: columnview :hlines 1 :id local
> | ITEM   | TODO | PRIORITY | TAGS  |
> |+--+--+---|
> | Arbeitsfortschritt |  | B|   |
> | 2017-10-19 |  | B|   |
> | CAD nachpflegen Lasertaster|  | B| :BKI: |
> | Ventilinsel| DONE | B| :BKI: |
> | Schaltschrank  | DONE | B|   |
> | Schutzverkleidung  | DONE | B|   |
> | Projektleiter Bodenverankerung (Bohrtiefe) |  | B| :PL:  |
> | Wartungseinheit| DONE | B|   |
> | Roboter Vakuumerzeuger | DONE | B|   |
> | Aushang Arbeitsfortschritt |  | B|   |
> | Aushang Arbeitsfortschritt (alt)   |  | B|   |
> #+END:
> 
> 
> Which is not what you seemed to get. What is my mistake?

I’m sorry, I didn’t tell you the whole truth.

„Projektleiter“ and „CAD Nachpflegen“ are defined as TODO keywords.

(A special case of WAITNG and an ALLMOST DONE state)

You have to add the additional options yourself:

:indent t :format "%50ITEM(Problem) %5PB(Nr) %12TODO %8TAGS(Wer) %12Termin 
%7ERLEDIGT(Erledigt){X/}"

I hope that helps
Axel





Re: [PATCH] Fix moving cursor in org-set-tags-command

2020-05-07 Thread Kyle Meyer
Matt Lundin writes:

> Commit 44ec473c199262d89b372d8a6cd35bed7672164d from Feb. 23 causes
> org-set-tags-command to move the cursor forward 1 char when situated on
> headline asterisks.
[...]
> This commit modified a previous change on Feb. 21
> (450452de4b790706d187291f9f71a286f8f62004). But that commit also had
> problems, since it would move the cursor one asterisk forward on
> headlines > 1, thus also interfering with org-speed-keys. In my view
> org-set-tags-command should not move the cursor except to fix the very
> specific thing that commit 450452de4b was meant to fix: namely the
> cursor moving when on a blank headline: i.e., from here...

Thanks for the nice description of the problem.  I wouldn't mind if at
least a condensed version made its way into the commit message :)

> I've attached a patch that corrects the problem, but it would be ideal
> if we figured out why the cursor is moving in the first place.

I looked quickly at org-set-tags (and the functions it calls).  Based on
commenting bits out, I think there are at least a couple of parts that
modify the buffer in a way that prevent save-excursion from restoring
the intended location.  While not ideal, this after-the-fact adjustment
is probably the simplest way to deal with the issue.

> Subject: [PATCH 1/1] Fix bug that placed cursor incorrectly when setting tags
>
> * lisp/org.el: (org-set-tags-command) Only fix cursor position in very

nitpick: The colon should follow (org-set-tags-command).

> diff --git a/lisp/org.el b/lisp/org.el
> index dd017e662..0e4fd7be1 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -11846,8 +11846,9 @@ in Lisp code use `org-set-tags' instead."
> (org-set-tags tags)
>  ;; `save-excursion' may not replace the point at the right
>  ;; position.
> -(when (save-excursion (skip-chars-backward "*") (bolp))
> -  (forward-char
> +(and (looking-at " ")
> +  (string-match "\\*+" (buffer-substring (point-at-bol) (point)))
> +  (forward-char

Looks fine to me, with the minor nit that I think looking-at-p and
string-match-p would be preferable here.

Would you mind adding a regression test?



[PATCH] Fix moving cursor in org-set-tags-command

2020-05-07 Thread Matt Lundin
Commit 44ec473c199262d89b372d8a6cd35bed7672164d from Feb. 23 causes
org-set-tags-command to move the cursor forward 1 char when situated on
headline asterisks.

So if I am on the following level 1 headline with the cursor on the
asterisk as below...

* Headline
^

...and I call org-set-tags command, it moves the cursor forward one space:

* Headline  :tag:
 ^

This is causes problems with org-speed-keys, which requires that the
cursor remain on the headline.

This commit modified a previous change on Feb. 21
(450452de4b790706d187291f9f71a286f8f62004). But that commit also had
problems, since it would move the cursor one asterisk forward on
headlines > 1, thus also interfering with org-speed-keys. In my view
org-set-tags-command should not move the cursor except to fix the very
specific thing that commit 450452de4b was meant to fix: namely the
cursor moving when on a blank headline: i.e., from here...

*** 
^

...to here...

*** :tag:
   ^

I've attached a patch that corrects the problem, but it would be ideal
if we figured out why the cursor is moving in the first place.

Best,

Matt

>From ae5cf0e1110241426e49f573219e9740c25bf8ea Mon Sep 17 00:00:00 2001
From: Matt Lundin 
Date: Thu, 7 May 2020 19:06:08 -0500
Subject: [PATCH 1/1] Fix bug that placed cursor incorrectly when setting tags

* lisp/org.el: (org-set-tags-command) Only fix cursor position in very
specific circumstances (i.e., when cursor is on an empty headline).
---
 lisp/org.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index dd017e662..0e4fd7be1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11846,8 +11846,9 @@ in Lisp code use `org-set-tags' instead."
 	  (org-set-tags tags)
 ;; `save-excursion' may not replace the point at the right
 ;; position.
-(when (save-excursion (skip-chars-backward "*") (bolp))
-  (forward-char
+(and (looking-at " ")
+	 (string-match "\\*+" (buffer-substring (point-at-bol) (point)))
+	 (forward-char
 
 (defun org-align-tags (&optional all)
   "Align tags in current entry.
-- 
2.26.2



RE: [Bug] org-store-link should not insert a document level ID property

2020-05-07 Thread Matthew Lundin
Gustav Wikström  writes:

> Hi again,
>
> Patch is attached. It's not applied yet as it doesn't include anything
> about user-configuration yet. @Matt Lundin, care to elaborate what you
> had in mind in terms of that?
>
> With this patch a link before first headline is stored with the
> filename (no path) as description. Following the link does what you'd
> expect. Tests ran fine with the patch applied.

Hi Gustav,

Sorry it's taken so long to get back to you. Thanks for applying this.
It makes the behavior consistent.

What I was thinking of in terms of configuration is being able to
preserve path-based links (instead of IDs) if creating a link above the
first headline. This is the behavior that existed in the past when
org-id-link-to-org-use-id was set to t or
'create-if-interactive-and-no-custom-id.

I've attached a patch that implements this. However, I also know that we
are trying to avoid configuration/feature creep in Org, so I'm
submitting this here for comments. Is this a configuration other people
want?

If not, it would be easy enough for me to hack this through advice-add.

Best,

Matt

>From 758c7c513c6e5e0457b483dcf2bf7c9299d1015b Mon Sep 17 00:00:00 2001
From: Matt Lundin 
Date: Thu, 7 May 2020 16:31:05 -0500
Subject: [PATCH 1/1] Allow configuration of whether to create IDs before first
 heading

This allows users to keep file (path-based) links above the first
heading of a file.

* lisp/ol.el: (org-store-link) New test for whether to use ID links
* lisp/org-id.el: (org-id-create-id-before-first-heading) New variable
---
 lisp/ol.el |  5 -
 lisp/org-id.el | 11 +++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 0cb1b0a7e..d072ad9f1 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -35,6 +35,7 @@
 (defvar org-comment-string)
 (defvar org-highlight-links)
 (defvar org-id-link-to-org-use-id)
+(defvar org-id-create-id-before-first-heading)
 (defvar org-inhibit-startup)
 (defvar org-outline-regexp-bol)
 (defvar org-src-source-file-name)
@@ -1619,7 +1620,9 @@ non-nil."
 			 (and (eq org-id-link-to-org-use-id
   'create-if-interactive-and-no-custom-id)
   (not custom-id
-		(and org-id-link-to-org-use-id (org-entry-get nil "ID"
+		(and org-id-link-to-org-use-id (org-entry-get nil "ID")))
+		(or (not (org-before-first-heading-p))
+		org-id-create-id-before-first-heading))
 	   ;; Store a link using the ID at point
 	   (setq link (condition-case nil
 			  (prog1 (org-id-store-link)
diff --git a/lisp/org-id.el b/lisp/org-id.el
index 34720b7f2..8792aa3cb 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -123,6 +123,17 @@ nil   Never use an ID to make a link, instead link using a text search for
 	  (const :tag "Only use existing" use-existing)
 	  (const :tag "Do not use ID to create link" nil)))
 
+(defcustom org-id-create-id-before-first-heading t
+  "Non-nil means storing a link before the first heading will use IDs.
+This determines how `org-store-link' generates links before the
+first heading in an Org file when `org-id-link-to-org-use-id' is
+configured to create IDs.
+
+When nil, `org-store-link' will create a normal file link instead
+of an ID if before the first heading."
+  :group 'org-id
+  :type 'boolean)
+
 (defcustom org-id-uuid-program "uuidgen"
   "The uuidgen program."
   :group 'org-id
-- 
2.26.2



Re: [Bug]: org-capture-place-plain-text error when template :unnarrowed

2020-05-07 Thread Nicolas Goaziou
Hello,

No Wayman  writes:

> org-capture-place-plain-text throws an error for templates which 
> meet the following criteria:
>   - entry type is 'plain
>   - the template has a non-nil :unnarrowed option
>   - the template string is not empty and does not explicitly 
>   include "%?"
>
> Seems to be thrown in this section of 
> org-capture-place-plain-text:
>
>   #+begin_src emacs-lisp
>   (when (or (search-backward "%?" beg t)
> (search-forward "%?" end t))
>   #+end_src
>
>
> A minimal failing case:
>
> #+begin_src emacs-lisp
> (let ((org-capture-templates
>'(("t" "test" plain (file "/tmp/bug.org")
>   "FAIL" :unnarrowed t
>   (org-capture nil "t"))
> #+end_src
>
>
> And a minimal passing case:
>
> #+begin_src emacs-lisp
> (let ((org-capture-templates
>'(("t" "test" plain (file "/tmp/bug.org")
>   "PASS%?" :unnarrowed t
>   (org-capture nil "t"))
> #+end_src

Fixed. Thank you.

Regards,

-- 
Nicolas Goaziou



Re: [Patch] Do not ignore headers argument in ob-latex

2020-05-07 Thread Nicolas Goaziou
Hello,

Yuri Lensky  writes:

> Subject: [PATCH] lisp/ob-latex.el: Stop ignoring headers argument

Thank you.

> During default "png" export, the "headers" argument is no longer
> explicitly ignored.

According to the TODO in that function, this is not the first time it
happens. Would you mind writing a test for it?

> +  (let ((org-format-latex-header
> +  (concat org-format-latex-header "\n"
> +  (string-join headers "\n"
> +(org-create-formula-image
> +body out-file org-format-latex-options in-buffer)))

This looks hackish but I don't know how to do it otherwise. However
could you use `mapconcat' instead of `string-join'?

Also, you need to declare `org-format-latex-header' in order to silence
byte-compiler.

Regards,

-- 
Nicolas Goaziou



Re: [PATCH] Allow org-capture-mode-hook to access org-capture-current-plist [9.3.6 (release_9.3.6-443-g0e8aff @ /home/n/.emacs.d/straight/build/org/)]

2020-05-07 Thread Nicolas Goaziou
Hello,

No Wayman  writes:

> I'm proposing the following trivial patch to bring more consistency to
> org-capture-mode's hooks.
> By setting org-capture-current-plist before invoking org-capture-mode
> in the capture buffer, users
> can access the same variable in org-capture-mode-hook as they would in
> org-capture-before-finalize-hook and
> org-capture-prepare-finalize-hook.
> org-capture-after-finalize-hook is the only outlier, but that makes
> sense as the capture buffer is no longer current when it runs.

OK. 

Could you add the modified function in the commit message, add
TINYCHANGE cookie if you haven't signed FSF papers yet, and add an entry
in ORG-NEWS about it?

Regards,

-- 
Nicolas Goaziou



Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Nicolas Goaziou
Kévin Le Gouguec  writes:

>> (I hope I got that right.)

LGTM. I applied the patch on your behalf.

Now Org has future-proof support for Electric indent mode.

Thank you.



[O] (no)export of special blocks

2020-05-07 Thread Ken Mankoff
Hello,

I'd like to be able to optionally export/not-export a specific paragraph within 
a section, based on a top-level property. Is this possible in Org? I know I can 
toggle export of code blocks, but what about text blocks?

More specifically, I'm writing a journal article and I would like to have 
figures in the text where I think they should be:

[[./fig/foo.png]]
#+CAPTION: foo

But the journal wants the figures at the end of the document.

I'd like to replicate the "[[./fig/foo.png]]", once inline and once at the end. 
I'd then like to be able to wrap this in a #+BEGIN_SOMETHING and toggle that 
with a property to export or not. E.g:

#+BEGIN_something :export (org-macro--get-property "results-y-or-n" "")
[[./fig/foo.png]]
#+CAPTION: foo
#+END_something


I recognize that if the figure is generated from a code block I can achieve my 
desired behavior. The code can have ":exports results" set to ":exports 
(org-macro--get-property "results-y-or-n" "")", and elsewhere

:PROPERTIES:
:results-y-or-n: nil
:END:

But there are a few problems with this:

1) org-macro--get-property works for header level properties in :PROPERTIES: 
drawers, but not top level #+PROPERTY: items.

2) Not all my figures are generated from code blocks

Thanks,

  -k.



Re: TODO or checkboxes in org tables

2020-05-07 Thread Uwe Brauer
>>> "AK" == Axel Kielhorn  writes:

Hi Alex
   >> Am 02.05.2020 um 21:33 schrieb Uwe Brauer :
   >> 
   > "AK" == Axel Kielhorn  writes:
   >> 
   >> Hi Alex,
   >> 
   >> I am not sure my first answer made it, so I apologize for a possible
   >> crossposting.

   > It didn’t reach me.

   >> A last question, which the command to generate the table
   >> org-insert-dblock:columnview ?

   > I’m using:

   > org-columns-insert-dblock


That seems to be the same function I use. 

However I set the cursor on 
** Arbeitsfortschritt, 
use that function and I obtain 

#+BEGIN: columnview :hlines 1 :id local
| ITEM   | TODO | PRIORITY | TAGS  |
|+--+--+---|
| Arbeitsfortschritt |  | B|   |
| 2017-10-19 |  | B|   |
| CAD nachpflegen Lasertaster|  | B| :BKI: |
| Ventilinsel| DONE | B| :BKI: |
| Schaltschrank  | DONE | B|   |
| Schutzverkleidung  | DONE | B|   |
| Projektleiter Bodenverankerung (Bohrtiefe) |  | B| :PL:  |
| Wartungseinheit| DONE | B|   |
| Roboter Vakuumerzeuger | DONE | B|   |
| Aushang Arbeitsfortschritt |  | B|   |
| Aushang Arbeitsfortschritt (alt)   |  | B|   |
#+END:


Which is not what you seemed to get. What is my mistake?

Thanks and regards

Uwe 


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Kévin Le Gouguec
Kévin Le Gouguec  writes:

> (I hope I got that right.)

Except I forgot the explanatory comment, and I left a typo in the
docstring.  Ahem.

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 2b35535fa..caaf5ce58 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -102,6 +102,12 @@ is nil)."
   (defun org-time-convert-to-list (time)
 (seconds-to-time (float-time time
 
+;; `newline-and-indent' did not take a numeric argument before 27.1.
+(if (version< emacs-version "27")
+(defsubst org-newline-and-indent (&optional _arg)
+  (newline-and-indent))
+  (defalias 'org-newline-and-indent #'newline-and-indent))
+
 
 ;;; Emacs < 26.1 compatibility
 
diff --git a/lisp/org.el b/lisp/org.el
index 8ad437a20..142bfb999 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17649,12 +17649,12 @@ call `open-line' on the very first character."
 
 (defun org--newline (indent arg interactive)
   "Call `newline-and-indent' or just `newline'.
-If INDENT is non-nil, call `newline-and-indent' to indent
-unconditionally; otherwise, call `newline' with ARG and
-INTERACTIVE, which can trigger indentation if
+If INDENT is non-nil, call `newline-and-indent' with ARG (if
+supported) to indent unconditionally; otherwise, call `newline'
+with ARG and INTERACTIVE, which can trigger indentation if
 `electric-indent-mode' is enabled."
   (if indent
-  (newline-and-indent)
+  (org-newline-and-indent arg)
 (newline arg interactive)))
 
 (defun org-return (&optional indent arg interactive)


Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Kévin Le Gouguec
Nicolas Goaziou  writes:

> AFAICT, `newline-and-indent' doesn't accept any argument. Keeping it
> introduces a build warning and test failures. Hence the removal.
>
> Since you were calling it with an argument I assume this may be
> a novelty in Emacs 27.

Wow, you're right.  That caught me off-guard.

>However Org still supports Emacs 24.4. If that's
> the case, we need an additional compatibility layer to support both
> cases. WDYT?

I don't know if we want to jump through these hoops for a feature that
people have done without so far?  FWIW though, the following patch seems
to work ("make test" works with both 26.3 and 28.0 on my end):

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 2b35535fa..ed12b9d18 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -102,6 +102,11 @@ is nil)."
   (defun org-time-convert-to-list (time)
 (seconds-to-time (float-time time
 
+(if (version< emacs-version "27")
+(defsubst org-newline-and-indent (&optional _arg)
+  (newline-and-indent))
+  (defalias 'org-newline-and-indent #'newline-and-indent))
+
 
 ;;; Emacs < 26.1 compatibility
 
diff --git a/lisp/org.el b/lisp/org.el
index 8ad437a20..57e78599f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17649,12 +17649,12 @@ call `open-line' on the very first character."
 
 (defun org--newline (indent arg interactive)
   "Call `newline-and-indent' or just `newline'.
-If INDENT is non-nil, call `newline-and-indent' to indent
-unconditionally; otherwise, call `newline' with ARG and
-INTERACTIVE, which can trigger indentation if
+If INDENT is non-nil, call `newline-and-indent' with ARG (if
+supported) )to indent unconditionally; otherwise, call `newline'
+with ARG and INTERACTIVE, which can trigger indentation if
 `electric-indent-mode' is enabled."
   (if indent
-  (newline-and-indent)
+  (org-newline-and-indent arg)
 (newline arg interactive)))
 
 (defun org-return (&optional indent arg interactive)

(I hope I got that right.)

> Meanwhile, I fixed the docstring. Thanks!

And thanks again.


Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Kévin Le Gouguec
Stefan Monnier  writes:

>> +(defmacro org-test-with-minor-mode (mode state &rest body)
>> +  "Run BODY after setting MODE to STATE.
>> +Restore MODE to its former state afterward."
>> +  (declare (debug (sexp sexp body)) (indent 2))
>> +  `(let ((old-state ,mode))
>> +   (,mode (if ,state 1 0))
>> +   ,@body
>> +   (,mode (if old-state 1 0
>
> This should probably use `unwind-protect` in case `body` exits
> non-locally.
> [ And also, for buffer-local minor modes, we should try and be careful
>   to restore the mode in the same buffer, tho this can be pushed as
>   a responsability of `body`.  ]

Thanks for confirming my nagging feeling that this macro was a bit too
naive :)

Nicolas actually ditched it and turned on/off electric-indent-local-mode
in the temporary buffer where the Org commands are run; that should take
care of these issues IIUC.



Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Stefan Monnier
> +(defmacro org-test-with-minor-mode (mode state &rest body)
> +  "Run BODY after setting MODE to STATE.
> +Restore MODE to its former state afterward."
> +  (declare (debug (sexp sexp body)) (indent 2))
> +  `(let ((old-state ,mode))
> +   (,mode (if ,state 1 0))
> +   ,@body
> +   (,mode (if old-state 1 0

This should probably use `unwind-protect` in case `body` exits
non-locally.
[ And also, for buffer-local minor modes, we should try and be careful
  to restore the mode in the same buffer, tho this can be pushed as
  a responsability of `body`.  ]


Stefan




Re: ical2org.awk

2020-05-07 Thread Eric S Fraga
On Thursday,  7 May 2020 at 14:05, Andreas Röhler wrote:
> thanks providing ical2org.awk.
> When running on Debian8 however, encountered a bunch of errors:

[...]

> Turns out had to install gawk.

Yes, I guess ical2org does expect gawk.  I should have made that
clear.  On my Debian installation (currently a bullseye/sid
combination), /usr/bin/awk points to gawk (via /etc/alternatives/awk) so
I never thought about it. 

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-577-gb171ff



Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Nicolas Goaziou
Kévin Le Gouguec  writes:

> I see you've removed ARG from the call to `newline-and-indent'; I don't
> have a strong opinion about this (though I don't see a reason not to
> keep it), but I guess the docstring of `org--newline' should be changed
> to match?

AFAICT, `newline-and-indent' doesn't accept any argument. Keeping it
introduces a build warning and test failures. Hence the removal.

Since you were calling it with an argument I assume this may be
a novelty in Emacs 27. However Org still supports Emacs 24.4. If that's
the case, we need an additional compatibility layer to support both
cases. WDYT?

Meanwhile, I fixed the docstring. Thanks!



ical2org.awk

2020-05-07 Thread Andreas Röhler

Hi,

thanks providing ical2org.awk.

When running on Debian8 however, encountered a bunch of errors:

awk: ./ical2org.awk: line 394: function strftime never defined
awk: ./ical2org.awk: line 394: function gensub never defined
awk: ./ical2org.awk: line 394: function gensub never defined
awk: ./ical2org.awk: line 394: function mktime never defined
awk: ./ical2org.awk: line 394: function gensub never defined

Turns out had to install gawk.

After changing the shebang accordingly it worked.

Just FYI,

thanks again,

Andreas,

GNU Emacs 28.0.50 (build 1, i686-pc-linux-gnu, GTK+ Version 3.14.5, 
cairo version 1.14.0) of 2020-04-06





Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Kévin Le Gouguec
Nicolas Goaziou  writes:

> I fixed a typo and applied your patch.

Thank you for fixing the typo in ORG-NEWS.

I see you've removed ARG from the call to `newline-and-indent'; I don't
have a strong opinion about this (though I don't see a reason not to
keep it), but I guess the docstring of `org--newline' should be changed
to match?

> However, when I have to reproduce a failing test, I don't even want to
> think about the recipe and rather concentrate on the results. Hence,
> I expect `should' macro's body to be self-sufficient. Therefore,
> I skipped this part of the patch.

Fair enough; toggling the local variant of the minor mode is probably
cleaner anyway!


Thanks for the review, and for applying.



Re: [patch suggestion] Mitigating the poor Emacs performance on huge org files: Do not use overlays for PROPERTY and LOGBOOK drawers

2020-05-07 Thread Christian Heinrich
Hi,

thanks for your (initial) patch! I traced another error down today and found 
your code by chance. I
tested it on an org-drill file that I had (with over 3500 items and hence 3500 
drawers) and this
patch helps *a lot* already. (Performance broke in 
4403d4685e19fb99ba9bfec2bd4ff6781c66981f when
outline-flag-region was replaced with org-flag-region, as drawers are no longer 
opened using
outline-show-all which I had to use anyways to deal with my huge file.)

I am not sure I understand how your follow-up code (below) needs to be 
incorporated. Would you mind
sending a patch file? I hope that this ends up in the master branch at some 
point.

Thanks again!
Christian

On Mon, 2020-04-27 at 00:04 +0800, Ihor Radchenko wrote:
> > You cannot. You may however mimic it with `cursor-sensor-functions' text
> > property. These assume Cursor Sensor minor mode is active, tho.
> > I haven't tested it, but I assume it would slow down text properties
> > a bit, too, but hopefully not as much as overlays.
> 
> Unfortunately, isearch sets inhibit-point-motion-hooks to non-nil
> internally. Anyway, I came up with some workaround, which seems to work
> (see below). Though it would be better if isearch supported hidden text
> in addition to overlays.
> 
> > Missing `isearch-open-invisible' is a deal breaker, IMO. It may be worth
> > experimenting with `cursor-sensor-functions'.
> 
> So far, I came up with the following partial solution searching and
> showing hidden text.
> 
> ;; Unfortunately isearch, sets inhibit-point-motion-hooks and we
> ;; cannot even use cursor-sensor-functions as a workaround
> ;; I used a less ideas approach with advice to isearch-search-string as
> ;; a workaround 
> 
> (defun org-find-text-property-region (pos prop)
>   "Find a region containing PROP text property around point POS."
>   (require 'org-macs) ;; org-with-point-at
>   (org-with-point-at pos
> (let* ((beg (and (get-text-property pos prop) pos))
>  (end beg))
>   (when beg
>   (setq beg (or (previous-single-property-change pos prop)
> beg))
>   (setq end (or (next-single-property-change pos prop)
> end))
> (unless (equal beg end)
>   (cons beg end))
> 
> ;; :FIXME: re-hide properties when point moves away
> (define-advice isearch-search-string (:after (&rest _) put-overlay)
>   "Reveal hidden text at point."
>   (when-let ((region (org-find-text-property-region (point) 'invisible)))
> (with-silent-modifications
>   (put-text-property (car region) (cdr region) 'org-invisible 
> (get-text-property (point)
> 'invisible)))
>   (remove-text-properties (car region) (cdr region) '(invisible nil
> 
> ;; this seems to be unstable, but I cannot figure out why
> (defun org-restore-invisibility-specs (&rest _)
>   ""
>(let ((pos (point-min)))
>  (while (< (setq pos (next-single-property-change pos 'org-invisible nil 
> (point-max))) (point-
> max))
>(when-let ((region (org-find-text-property-region pos 'org-invisible)))
>  (with-silent-modifications
>(put-text-property (car region) (cdr region) 'invisible 
> (get-text-property pos 'org-
> invisible))
>(remove-text-properties (car region) (cdr region) '(org-invisible 
> nil)))
> 
> (add-hook 'post-command-hook #'org-restore-invisibility-specs)
> 
> (defun org-flag-region (from to flag spec)
>   "Hide or show lines from FROM to TO, according to FLAG.
> SPEC is the invisibility spec, as a symbol."
>   (pcase spec
> ('outline
>  (remove-overlays from to 'invisible spec)
>  ;; Use `front-advance' since text right before to the beginning of
>  ;; the overlay belongs to the visible line than to the contents.
>  (when flag
>(let ((o (make-overlay from to nil 'front-advance)))
>(overlay-put o 'evaporate t)
>(overlay-put o 'invisible spec)
>(overlay-put o 'isearch-open-invisible #'delete-overlay
> (_
>  (with-silent-modifications
>(remove-text-properties from to '(invisible nil))
>(when flag
>(put-text-property from to 'invisible spec)
>)
> 
> ;; This normally deletes invisible text property. We do not want this now.
> (defun org-unfontify-region (beg end &optional _maybe_loudly)
>   "Remove fontification and activation overlays from links."
>   (font-lock-default-unfontify-region beg end)
>   (let* ((buffer-undo-list t)
>(inhibit-read-only t) (inhibit-point-motion-hooks t)
>(inhibit-modification-hooks t)
>deactivate-mark buffer-file-name buffer-file-truename)
> (decompose-region beg end)
> (remove-text-properties beg end
>   '(mouse-face t keymap t org-linked-text t
>;; Do not remove invisible during 
> fontification
>
>;; invisible t
>  intang

Re: [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode

2020-05-07 Thread Nicolas Goaziou
Hello,

Kévin Le Gouguec  writes:

> Here's a complete patch to make RET and C-j honor electric-indent-mode
> in org-mode, targeting Org's master branch.

Thank you very much.

I fixed a typo and applied your patch.

> +(defmacro org-test-with-minor-mode (mode state &rest body)
> +  "Run BODY after setting MODE to STATE.
> +Restore MODE to its former state afterward."
> +  (declare (debug (sexp sexp body)) (indent 2))
> +  `(let ((old-state ,mode))
> +   (,mode (if ,state 1 0))
> +   ,@body
> +   (,mode (if old-state 1 0

This is a nice macro.

However, when I have to reproduce a failing test, I don't even want to
think about the recipe and rather concentrate on the results. Hence,
I expect `should' macro's body to be self-sufficient. Therefore,
I skipped this part of the patch.

Regards,

-- 
Nicolas Goaziou



Re: [patch suggestion] Mitigating the poor Emacs performance on huge org files: Do not use overlays for PROPERTY and LOGBOOK drawers

2020-05-07 Thread Karl Voit
Hi,

* Karl Voit  wrote:
> Hi Ihor,
>
> * Ihor Radchenko  wrote:
>>
>> So far, I came up with the following partial solution searching and
>> showing hidden text.
>>
>> (defun org-find-text-property-region (pos prop)
>> (define-advice isearch-search-string (:after (&rest _) put-overlay)
>> (defun org-restore-invisibility-specs (&rest _)
>> (add-hook 'post-command-hook #'org-restore-invisibility-specs)
>> (defun org-flag-region (from to flag spec)
>> (defun org-unfontify-region (beg end &optional _maybe_loudly)
>
> After a couple of hours working with these patches, my feedback is
> very positive. Besides some visual glitches when creating a new
> heading with org-expiry-insinuate activated (which automatically
> adds :CREATED: properties), I could not detect any side-effect so
> far (will keep testing).
>
> The visual glitch looks like that:
>
>:PROPERTIES:X:CREATED:  [2020-05-04 Mon 18>54]
> X
>
> ... with "X" being my character that symbolizes collapsed content.
> The way it looked without the patch was a simple collapsed property
> drawer.

Here some hard numbers to demonstrate the impact:

my-org-agenda: from 11-16s down to 10 -> not much of a difference

helm-org-contacts-refresh-cache: 29-59s down to 2½ -> HUGE

Emacs boot time: 50-65s down to 10 -> HUGE

Navigating the cursor in large Org files -> HUGE subjective impact

>>> Anyway, the real fix should come from Emacs itself. There are ways to
>>> make overlays faster. These ways have already been discussed on the
>>> Emacs devel mailing list, but no one implemented them. It is a bit sad
>>> that we have to find workarounds for that.
>>
>> I guess that it is a very old story starting from the times when XEmacs
>> was a thing [1]. I recently heard about binary tree implementation of
>> overlays (there should be a branch in emacs git repo) [2], but there was
>> no update on that branch for a while. So, I do not have much hope on
>> Emacs implementing efficient overlay access in the near future. (And I
>> have problems with huge org files already).
>
> I can not express how this also reflects my personal situation.
>
>> [1] 
>> https://www.reddit.com/r/planetemacs/comments/e9lgwn/history_of_lucid_emacs_fsf_emacs_schism/
>> [2] https://lists.gnu.org/archive/html/emacs-devel/2019-12/msg00323.html
>
> [3] https://karl-voit.at/2020/05/03/current-org-files
>

-- 
get mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML into Org-mode:
   > get Memacs from https://github.com/novoid/Memacs <
Personal Information Management > http://Karl-Voit.at/tags/pim/
Emacs-related > http://Karl-Voit.at/tags/emacs/