[PATCH v3] Emacs: Indent first header line only when indentation is turned on

2020-08-15 Thread Teemu Likonen
Previously in message-show mode message's first header line (From
header) was always indented, even if user had turned thread
indentation off with "<" (notmuch-show-toggle-thread-indentation)
command.

This change modifies notmuch-show-insert-headerline function so that
it doesn't indent the first header line if notmuch-show-indent-content
variable is nil.

This change also modifies tests so that they expect this new output
format:
test/emacs-show.expected-output/notmuch-show-indent-thread-content-off
---
 emacs/notmuch-show.el|  5 -
 .../notmuch-show-indent-thread-content-off   | 12 ++--
 2 files changed, 10 insertions(+), 7 deletions(-)


* 2020-08-12 20:38:06-03, David Bremner wrote:
> the test "notmuch-show: disable indentation of thread content (w/
> notmuch-show-toggle-thread-indentation)" in T450-emacs-show needs to be
> adjusted for this change (i.e. it fails as is).

Thanks. This version has updated test output files.


diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 0eb27e33..444b2a45 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -474,7 +474,10 @@ message at DEPTH in the current thread."
   ;; invisible U+200E LEFT-TO-RIGHT MARK character which forces
   ;; the header paragraph as left-to-right text.
   (insert (propertize (string ?\x200e) 'invisible t)))
-(insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width 
depth))
+(insert (if notmuch-show-indent-content
+   (notmuch-show-spaces-n (* notmuch-show-indent-messages-width
+ depth))
+ "")
from
" ("
date
diff --git 
a/test/emacs-show.expected-output/notmuch-show-indent-thread-content-off 
b/test/emacs-show.expected-output/notmuch-show-indent-thread-content-off
index 1a06374d..0bb58330 100644
--- a/test/emacs-show.expected-output/notmuch-show-indent-thread-content-off
+++ b/test/emacs-show.expected-output/notmuch-show-indent-thread-content-off
@@ -31,8 +31,8 @@ Cheers,
 [ application/pgp-signature ]
 [ text/plain ]
 [ 4-line signature. Click/Enter to show. ]
- Mikhail Gusarov  (2009-11-17) (inbox signed unread)
-  Lars Kellogg-Stedman  (2009-11-17) (inbox signed)
+Mikhail Gusarov  (2009-11-17) (inbox signed unread)
+Lars Kellogg-Stedman  (2009-11-17) (inbox signed)
 Subject: Re: [notmuch] Working with Maildir storage?
 To: Mikhail Gusarov 
 Cc: notmuch@notmuchmail.org
@@ -57,9 +57,9 @@ It doesn't look like the patch is in git yet.
 [ application/pgp-signature ]
 [ text/plain ]
 [ 4-line signature. Click/Enter to show. ]
-   Mikhail Gusarov  (2009-11-17) (inbox unread)
-   Keith Packard  (2009-11-17) (inbox unread)
-Lars Kellogg-Stedman  (2009-11-18) (inbox signed 
unread)
+Mikhail Gusarov  (2009-11-17) (inbox unread)
+Keith Packard  (2009-11-17) (inbox unread)
+Lars Kellogg-Stedman  (2009-11-18) (inbox signed unread)
 Subject: Re: [notmuch] Working with Maildir storage?
 To: Keith Packard 
 Cc: notmuch@notmuchmail.org
@@ -79,4 +79,4 @@ missing "#include " (for the uint32_t on line 466).
 [ application/pgp-signature ]
 [ text/plain ]
 [ 4-line signature. Click/Enter to show. ]
- Carl Worth  (2009-11-18) (inbox unread)
+Carl Worth  (2009-11-18) (inbox unread)
-- 
2.20.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 1/2] Emacs: Add a new function for balancing bidi control chars

2020-08-15 Thread Teemu Likonen
The following Unicode's bidirectional control chars are modal so that
they push a new bidirectional rendering mode to a stack:

U+202A LEFT-TO-RIGHT EMBEDDING
U+202B RIGHT-TO-LEFT EMBEDDING
U+202D LEFT-TO-RIGHT OVERRIDE
U+202E RIGHT-TO-LEFT OVERRIDE

Every mode must be terminated with with character U+202C POP
DIRECTIONAL FORMATTING which pops the mode from the stack. The stack
is per paragraph. A new text paragraph resets the rendering mode
changed by these control characters.

This change adds a new function "notmuch-balance-bidi-ctrl-chars"
which reads its STRING argument and ensures that all push
characters (U+202A, U+202B, U+202D, U+202E) have a pop character
pair (U+202C). The function may add more U+202C characters at the end
of the returned string, or it may remove some U+202C characters. The
returned string is safe in the sense that it won't change the
surrounding bidirectional rendering mode. This function should be used
when sanitizing arbitrary input.
---
 emacs/notmuch-lib.el | 54 
 1 file changed, 54 insertions(+)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 118faf1e..e6252c6c 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -469,6 +469,60 @@ be displayed."
"[No Subject]"
   subject)))
 
+
+(defun notmuch-balance-bidi-ctrl-chars (string)
+  "Balance bidirectional control chars in STRING.
+
+The following Unicode's bidirectional control chars are modal so
+that they push a new bidirectional rendering mode to a stack:
+U+202A LEFT-TO-RIGHT EMBEDDING, U+202B RIGHT-TO-LEFT EMBEDDING,
+U+202D LEFT-TO-RIGHT OVERRIDE and U+202E RIGHT-TO-LEFT OVERRIDE.
+Every mode must be terminated with with character U+202C POP
+DIRECTIONAL FORMATTING which pops the mode from the stack. The
+stack is per paragraph. A new text paragraph resets the rendering
+mode changed by these control characters.
+
+This function reads the STRING argument and ensures that all push
+characters (U+202A, U+202B, U+202D, U+202E) have a pop character
+pair (U+202C). The function may add more U+202C characters at the
+end of the returned string, or it may remove some U+202C
+characters. The returned string is safe in the sense that it
+won't change the surrounding bidirectional rendering mode. This
+function should be used when sanitizing arbitrary input."
+
+  (let ((new-string nil)
+   (stack-count 0))
+
+(cl-flet ((push-char-p (c)
+   ;; U+202A LEFT-TO-RIGHT EMBEDDING
+   ;; U+202B RIGHT-TO-LEFT EMBEDDING
+   ;; U+202D LEFT-TO-RIGHT OVERRIDE
+   ;; U+202E RIGHT-TO-LEFT OVERRIDE
+   (cl-find c '(?\u202a ?\u202b ?\u202d ?\u202e)))
+ (pop-char-p (c)
+   ;; U+202C POP DIRECTIONAL FORMATTING
+   (eql c ?\u202c)))
+
+  (cl-loop for char across string
+  do (cond ((push-char-p char)
+(cl-incf stack-count)
+(push char new-string))
+   ((and (pop-char-p char)
+ (cl-plusp stack-count))
+(cl-decf stack-count)
+(push char new-string))
+   ((and (pop-char-p char)
+ (not (cl-plusp stack-count)))
+;; The stack is empty. Ignore this pop character.
+)
+   (t (push char new-string)
+
+;; Add possible missing pop characters.
+(cl-loop repeat stack-count
+do (push ?\x202c new-string))
+
+(seq-into (nreverse new-string) 'string)))
+
 (defun notmuch-sanitize (str)
   "Sanitize control character in STR.
 
-- 
2.20.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 0/2] Balance bidi control chars

2020-08-15 Thread Teemu Likonen
These patches continue the ideas written in message:

id:87sgcuuzio@iki.fi

The first patch adds an new function which can be used to balance
Unicode's bidirectional control characters in its string argument. The
seconds patch modifies old "notmuch-sanitize" function so that it
calls the new function.


Teemu Likonen (2):
  Emacs: Add a new function for balancing bidi control chars
  Emacs: Call notmuch-balance-bidi-ctrl-chars in notmuch-sanitize

 emacs/notmuch-lib.el | 57 +++-
 1 file changed, 56 insertions(+), 1 deletion(-)

-- 
2.20.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 2/2] Emacs: Call notmuch-balance-bidi-ctrl-chars in notmuch-sanitize

2020-08-15 Thread Teemu Likonen
---
 emacs/notmuch-lib.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index e6252c6c..e0122f7a 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -527,7 +527,8 @@ function should be used when sanitizing arbitrary input."
   "Sanitize control character in STR.
 
 This includes newlines, tabs, and other funny characters."
-  (replace-regexp-in-string "[[:cntrl:]\x7f\u2028\u2029]+" " " str))
+  (notmuch-balance-bidi-ctrl-chars
+   (replace-regexp-in-string "[[:cntrl:]\x7f\u2028\u2029]+" " " str)))
 
 (defun notmuch-escape-boolean-term (term)
   "Escape a boolean term for use in a query.
-- 
2.20.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v2 2/3] emacs/tree: enable moving to next thread in search results

2020-08-15 Thread David Bremner
William Casarin  writes:

> This introduces a new function called
> notmuch-tree-next-thread-from-search which is analogous to
> notmuch-show-next-thread. It will switch to the next or previous
> thread from the parent search results.
>

This seems to work, and is pretty slick. If there are no objections
today, I'll apply to master,

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 0/2] Balance bidi control chars

2020-08-15 Thread Teemu Likonen
* 2020-08-15 12:30:34+03, Teemu Likonen wrote:

> These patches continue the ideas written in message:
>
> id:87sgcuuzio@iki.fi

Here is a nice and relatively short reference for anyone who is
interested in the subject:

https://www.iamcal.com/understanding-bidirectional-text

-- 
/// Teemu Likonen - .-.. http://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450


signature.asc
Description: PGP signature
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] Fix database instructions in test/README: make download-corpus

2020-08-15 Thread Teemu Likonen
---
 test/README | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Currently test/README file instructs user to download database files
with command:

make download-test-databases

That doesn't work for me. I got tests running after executing "make
download-corpus" instead. So maybe that's the correct Makefile target.
If so, this patch should go in.


diff --git a/test/README b/test/README
index 3f54af58..d2a1fdb3 100644
--- a/test/README
+++ b/test/README
@@ -82,7 +82,7 @@ The following command-line options are available when running 
tests:
 Certain tests require precomputed databases to complete. You can fetch these
 databases with
 
-   make download-test-databases
+   make download-corpus
 
 If you do not download the test databases, the relevant tests will be
 skipped.
-- 
2.20.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v3] Emacs: Indent first header line only when indentation is turned on

2020-08-15 Thread David Bremner
Teemu Likonen  writes:

> Previously in message-show mode message's first header line (From
> header) was always indented, even if user had turned thread
> indentation off with "<" (notmuch-show-toggle-thread-indentation)
> command.
>
> This change modifies notmuch-show-insert-headerline function so that
> it doesn't indent the first header line if notmuch-show-indent-content
> variable is nil.
>
> This change also modifies tests so that they expect this new output
> format:
> test/emacs-show.expected-output/notmuch-show-indent-thread-content-off

Applied to master

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 3/3] test: Explicitly state that we want to sign with sender

2020-08-15 Thread David Bremner
Jonas Bernoulli  writes:

> Since Emacs 27 'mml-secure-epg-sign' errors out if we don't opt-in to
> signing as the sender using 'mml-secure-openpgp-sign-with-sender'.
> ---
>  test/test-lib.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 8c331b88..90e26639 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -414,7 +414,8 @@ emacs_fcc_message ()
>  (message-goto-body)
>  (insert \"${body}\")
>  $*
> -(notmuch-mua-send-and-exit))" || return 1
> +(let ((mml-secure-openpgp-sign-with-sender t))
> +  (notmuch-mua-send-and-exit)))" || return 1
>  notmuch new $nmn_args >/dev/null

It seems that notmuch-emacs users will have to set this variable, or
perform some other configuration to keep signing working when upgrading
to 27.1. Should notmuch be helping this transition somehow?

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] test: update README to reflect dropping upgrade tests

2020-08-15 Thread David Bremner
These test databases have been unneeded since ee897cab8.
---

 You're correct that the README needs updating, but download-corpus is
 for the performance tests.

 test/README | 8 
 1 file changed, 8 deletions(-)

diff --git a/test/README b/test/README
index 3f54af58..11eaf18f 100644
--- a/test/README
+++ b/test/README
@@ -79,14 +79,6 @@ The following command-line options are available when 
running tests:
As the names depend on the tests' file names, it is safe to
run the tests with this option in parallel.
 
-Certain tests require precomputed databases to complete. You can fetch these
-databases with
-
-   make download-test-databases
-
-If you do not download the test databases, the relevant tests will be
-skipped.
-
 When invoking the test suite via "make test" any of the above options
 can be specified as follows:
 
-- 
2.28.0
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v2 1/3] emacs/tree: introduce notmuch-tree-parent-buffer variable

2020-08-15 Thread David Bremner
William Casarin  writes:

> This variable will be used in a similar fashion to
> notmuch-show-parent-buffer. It will be used to navigate between
> threads from the parent search buffer.
>
> Signed-off-by: William Casarin 

Can someone explain the difference in behaviour before and after this
patch?

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v2 1/3] emacs/tree: introduce notmuch-tree-parent-buffer variable

2020-08-15 Thread David Bremner
David Bremner  writes:

> William Casarin  writes:
>
>> This variable will be used in a similar fashion to
>> notmuch-show-parent-buffer. It will be used to navigate between
>> threads from the parent search buffer.
>>
>> Signed-off-by: William Casarin 
>
> Can someone explain the difference in behaviour before and after this
> patch?

Ah, reading ahead I see the main point is to use it in the next
patch. That's fine. I guess in general a hint in the commit message is
nice, but not worth respinning the series just for that.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer

2020-08-15 Thread David Bremner
Sean Whitton  writes:

> This means that notmuch commands obey display-buffer-alist so the user
> can customize how buffers show up.
>
> It also permits the use of C-x 4 4, C-x 5 5 and C-x t t, available in
> Emacs 28.  For example, one can use C-x 4 4 M-x notmuch-jump-search RET
> to open a saved search in another window rather than the current window.
> Or in notmuch-search mode, C-x 5 5 RET to view the message at point in
> a new frame.
>
> notmuch-tree has custom buffer display logic, so bind
> display-buffer-overriding-action to make pop-to-buffer-same-window
> behave exactly as switch-to-buffer while that function is running.

I only tested this in emacs 26.3, but I think I hit all the modified
code paths and it didn't crash.  It would be nice to have one or two
more people try it out before I apply to master; I tend to be somewhat
oblivious to subtle changes in emacs window behaviour.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org