Re: [PATCH v4] emacs: customizable names for search buffers

2022-01-16 Thread Jose A Ortega Ruiz
On Sun, Jan 16 2022, Kyle Meyer wrote:

[...]

> Here's the last statement about the minimum Emacs version I see in
> Notmuch's NEWS (for v0.31):
>
>   The minimum supported major version of GNU Emacs is now 25.1.
>
> The example in my last message used 25.3 because that's the closest
> version to 25.1 for which I had a local working tree checked out and
> built.  But, as I mentioned, format-spec has been present since Emacs
> 21.1.

Thanks for checking.  v6 of the patch submitted.

Cheers,
jao
-- 
It is a truism of escape plans that the problem with going anywhere is
that you take yourself with you -- Emma Brockes
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v6] emacs: customizable names for search buffers

2022-01-16 Thread jao
Customizable names for buffers presenting search results, via two
custom variables (notmuch-search-buffer-name-format and
notmuch-saved-search-buffer-name-format), defaulting to values
currently used for plain searches and including too tree and
unthreaded search buffers.

---

This is a much improved version of the patch in
id:20220108204121.1053932-1-...@gnu.org, according to discussion on
that thread.

This version always uses format-spec, since it's available since
ancient times (see discussion in id:875yqjmgaq@kyleam.com).

Signed-off-by: jao 
---
 emacs/notmuch-hello.el | 11 +
 emacs/notmuch-tree.el  | 10 
 emacs/notmuch.el   | 53 ++
 3 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index fc007c4c..44341dd6 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -486,11 +486,14 @@ diagonal."
 (defun notmuch-hello-widget-search (widget  _ignore)
   (cl-case (widget-get widget :notmuch-search-type)
(tree
-(notmuch-tree (widget-get widget :notmuch-search-terms)
- nil nil nil nil nil nil
- (widget-get widget :notmuch-search-oldest-first)))
+(let ((n (notmuch-search-format-buffer-name (widget-value widget) "tree" 
t)))
+  (notmuch-tree (widget-get widget :notmuch-search-terms)
+   nil nil n nil nil nil
+   (widget-get widget :notmuch-search-oldest-first
(unthreaded
-(notmuch-unthreaded (widget-get widget :notmuch-search-terms)))
+(let ((n (notmuch-search-format-buffer-name (widget-value widget)
+   "unthreaded" t)))
+  (notmuch-unthreaded (widget-get widget :notmuch-search-terms) nil nil 
n)))
(t
 (notmuch-search (widget-get widget :notmuch-search-terms)
(widget-get widget :notmuch-search-oldest-first)
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index d7486904..303c6fad 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1191,11 +1191,11 @@ The arguments are:
 (setq query (notmuch-read-query (concat "Notmuch "
(if unthreaded "unthreaded " "tree 
")
"view search: "
-  (let ((buffer (get-buffer-create (generate-new-buffer-name
-   (or buffer-name
-   (concat "*notmuch-"
-   (if unthreaded "unthreaded-" 
"tree-")
-   query "*")
+  (let* ((name
+ (or buffer-name
+ (notmuch-search-buffer-title query
+  (if unthreaded "unthreaded" 
"tree"
+(buffer (get-buffer-create (generate-new-buffer-name name)))
(inhibit-read-only t))
 (pop-to-buffer-same-window buffer))
   ;; Don't track undo information for this buffer
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 85a54706..ef3af899 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -915,7 +915,39 @@ See `notmuch-tag' for information on the format of 
TAG-CHANGES."
  (notmuch-search-get-tags-region (point-min) (point-max)) "Tag all")))
   (notmuch-search-tag tag-changes (point-min) (point-max) t))
 
-(defun notmuch-search-buffer-title (query)
+(defcustom notmuch-search-buffer-name-format "*notmuch-%t-%s*"
+  "Format for the name of search results buffers.
+
+In this spec, %s will be replaced by a description of the search
+query and %t by its type (search, tree or unthreaded).  The
+buffer name is formatted using `format-spec': see its docstring
+for additional parameters for the s and t format specifiers.
+
+See also `notmuch-saved-search-buffer-name-format'"
+  :type 'string
+  :group 'notmuch-search)
+
+(defcustom notmuch-saved-search-buffer-name-format "*notmuch-saved-%t-%s*"
+  "Format for the name of search results buffers.
+
+In this spec, %s will be replaced by the saved search name and %t
+by its type (search, tree or unthreaded).  The buffer name is
+formatted using `format-spec': see its docstring for additional
+parameters for the s and t format specifiers.
+
+See also `notmuch-search-buffer-name-format'"
+  :type 'string
+  :group 'notmuch-search)
+
+(defun notmuch-search-format-buffer-name (query type saved)
+  "Compose a buffer name for the given QUERY, TYPE (search, tree,
+unthreaded) and whether it's SAVED (t or nil)."
+  (let ((fmt (if saved
+notmuch-saved-search-buffer-name-format
+  notmuch-search-buffer-name-format)))
+(format-spec fmt `((?t . ,(or type "search")) (?s . ,query)
+
+(defun notmuch-search-buffer-title (query  type)
   "Returns the title for a buffer with notmuch search results."
   (let* ((saved-search
  (let (longest
@@ -930,19 +962,20 @@ See `notmuch-tag' for information on the format of 

Re: [PATCH v4] emacs: customizable names for search buffers

2022-01-16 Thread Kyle Meyer
Jose A Ortega Ruiz writes:

> In very recent emacs (i'm using its master branch, actually), if one M-x
> describe-function RET format-spec one sees in the help buffer:
>
>  Probably introduced at or before Emacs version 27.1.
>
> that's where my misconception came from.  

I see.  If I recall correctly, that help string is generated by
searching NEWS* files for the name of interest.  While that often works
okay, in this case format-spec is first mentioned in the NEWS for 27.1:

  $ git describe
  emacs-28.0.91-28-ge4886018496
  $ git grep -c format-spec -- 'etc/NEWS*'
  etc/NEWS:5
  etc/NEWS.27:1

> I guess that's potentially good news: i don't see an emacs version
> specified in notmuch's package: is it supposed to be compatible with
> emacs < 25.3?  If not, we can just forget about the regexp branch.

Here's the last statement about the minimum Emacs version I see in
Notmuch's NEWS (for v0.31):

  The minimum supported major version of GNU Emacs is now 25.1.

The example in my last message used 25.3 because that's the closest
version to 25.1 for which I had a local working tree checked out and
built.  But, as I mentioned, format-spec has been present since Emacs
21.1.
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v4] emacs: customizable names for search buffers

2022-01-16 Thread Jose A Ortega Ruiz
On Sun, Jan 16 2022, Kyle Meyer wrote:

> Jose A Ortega Ruiz writes:
>
>> yeah, that's what i use and didn't notice my error above.  format-spec
>> is much nicer than a plain regexp subs, one can use format specifiers
>> like %3t and many others, but unfortunately seems to have been
>> introduced in emacs 27.
>
> format-spec has been present in Emacs since version 21.1, specifically
> c113de23613 (2000-09-19).  (Some parameters have been added since then,
> but you only use FORMAT and SPECIFICATION in your patch.)
>
> Here's a test with Emacs 25, Notmuch's current minimum (if I grep
> correctly):
>
>   (emacs-version) ; => "GNU Emacs 25.3.50.1 ..."
>   (require 'format-spec)
>   (format-spec "%b" '((?b . "fine"))) ; => "fine"
>
> At first I thought you were getting confused by the fact that
> format-spec has been marked as autoloaded only recently, but it looks
> like that was in 0185d76e742 (Fix and extend format-spec (bug#41758),
> 2020-06-18), which will be part of the 28.1 release.  So that's not
> consistent with "introduced in emacs 27".

In very recent emacs (i'm using its master branch, actually), if one M-x
describe-function RET format-spec one sees in the help buffer:

 Probably introduced at or before Emacs version 27.1.

that's where my misconception came from.  

I guess that's potentially good news: i don't see an emacs version
specified in notmuch's package: is it supposed to be compatible with
emacs < 25.3?  If not, we can just forget about the regexp branch.

Thanks a lot for checking,
jao
-- 
"The evil that is in the world almost always comes of ignorance, and
good intentions may do as much harm as malevolence if they lack understanding."
 - Albert Camus
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v4] emacs: customizable names for search buffers

2022-01-16 Thread Kyle Meyer
Jose A Ortega Ruiz writes:

> yeah, that's what i use and didn't notice my error above.  format-spec
> is much nicer than a plain regexp subs, one can use format specifiers
> like %3t and many others, but unfortunately seems to have been
> introduced in emacs 27.

format-spec has been present in Emacs since version 21.1, specifically
c113de23613 (2000-09-19).  (Some parameters have been added since then,
but you only use FORMAT and SPECIFICATION in your patch.)

Here's a test with Emacs 25, Notmuch's current minimum (if I grep
correctly):

  (emacs-version) ; => "GNU Emacs 25.3.50.1 ..."
  (require 'format-spec)
  (format-spec "%b" '((?b . "fine"))) ; => "fine"

At first I thought you were getting confused by the fact that
format-spec has been marked as autoloaded only recently, but it looks
like that was in 0185d76e742 (Fix and extend format-spec (bug#41758),
2020-06-18), which will be part of the 28.1 release.  So that's not
consistent with "introduced in emacs 27".
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v4] emacs: customizable names for search buffers

2022-01-16 Thread Jose A Ortega Ruiz
On Sun, Jan 16 2022, Tomi Ollila wrote:

> On Fri, Jan 14 2022, Jose A. Ortega Ruiz wrote:

>> on second thought, i think we could perhaps just go for the simpler
>> "%t", which would allow inserting the type anywhere, even in the middle
>> of a word... i think a problem here is that "word" or "symbol" (which is
>> what my suggestion used) constituent depend on the definition of what's
>> a word or symbol in the active mode.
>>
>> although that would prevent fancy things like "%type: %t", but that's a
>> bit of a corner case, don't you think?
>
> Yes, simpler; the cases where is breaks are (probably?) seldom enough.

agreed then.  v5 of the patch should be doing just that, if i didn't
mess up.

thanks,
jao
-- 
The enjoyment of one's tools is an essential ingredient of successful
work. – Donald E. Knuth
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v4] emacs: customizable names for search buffers

2022-01-16 Thread Tomi Ollila
On Fri, Jan 14 2022, Jose A. Ortega Ruiz wrote:

> on second thought, i think we could perhaps just go for the simpler
> "%t", which would allow inserting the type anywhere, even in the middle
> of a word... i think a problem here is that "word" or "symbol" (which is
> what my suggestion used) constituent depend on the definition of what's
> a word or symbol in the active mode.
>
> although that would prevent fancy things like "%type: %t", but that's a
> bit of a corner case, don't you think?

Yes, simpler; the cases where is breaks are (probably?) seldom enough.

Also for reference,

(replace-regexp-in-string "\\_<%t\\_>" "repl" "foo-%t-bar") ;; does not work

(replace-regexp-in-string "\\_<%t\\_>" "repl" "foo %%%t bar") ;; neither...

(replace-regexp-in-string "\\_<%t\\_>" "repl" "foo %t bar") ;; worked, but...

Tomi

>
> cheers,
> jao
> -- 
> The surest way to corrupt a youth is to instruct him to hold in higher
> esteem those who think alike than those who think
> differently. -Friedrich Nietzsche, philosopher (1844-1900)
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] test: fix deprecation warning in symbol-test

2022-01-16 Thread David Bremner
David Bremner  writes:

> Reduce the amount of noise in the build log.
> ---

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


[PATCH] contrib/notmuch-web: single user web front end using python-cffi

2022-01-16 Thread David Bremner
Originally contributed by Brian Sniffen. Quite a few unpublished fixes
from Daniel Kahn Gilmour. We've been running it a few years now as the
"official" archive of the notmuch mailing list. There also a few fixes
from myself and Austin Ray. Finally I converted it to the new python
bindings.

This commit squashes the several years of development history and
moves it under devel, in recognition of the now established role it
plays in the project infrastructure.

[1]: id:87tvyvp4f2@istari.evenmere.org
---

This has lived for several years in a private repo on
nmbug.notmuchmail.org. It is now in a branch on git.notmuchmail.org,
but I don't think that's really a sustainable model. The code is still
pretty rough around the edges (and my quick and dirty conversion to
the new bindings has not improved that). On the other hand, if we are
going to deploy it in production, then we should also publish it, and
get more people poking at it.

My plan is to deploy this (or some improved version) using the new
python bindings after the release of 0.35. At that point I will apply
this (or some improved version) to master.


 NEWS |  12 +
 devel/notmuch-web/nmgunicorn.py  |  11 +
 devel/notmuch-web/nmweb.py   | 366 +++
 devel/notmuch-web/static/css/jquery-ui.css   |   1 +
 devel/notmuch-web/static/css/notmuch-0.1.css |  15 +
 devel/notmuch-web/static/js/jquery-ui.js |   1 +
 devel/notmuch-web/static/js/jquery.js|   1 +
 devel/notmuch-web/static/js/notmuch-0.1.js   |  35 ++
 devel/notmuch-web/templates/base.html|  39 ++
 devel/notmuch-web/templates/index.html   |   9 +
 devel/notmuch-web/templates/search.html  |  10 +
 devel/notmuch-web/templates/show.html|  15 +
 devel/notmuch-web/todo   |  14 +
 13 files changed, 529 insertions(+)
 create mode 100644 devel/notmuch-web/nmgunicorn.py
 create mode 100755 devel/notmuch-web/nmweb.py
 create mode 12 devel/notmuch-web/static/css/jquery-ui.css
 create mode 100644 devel/notmuch-web/static/css/notmuch-0.1.css
 create mode 12 devel/notmuch-web/static/js/jquery-ui.js
 create mode 12 devel/notmuch-web/static/js/jquery.js
 create mode 100644 devel/notmuch-web/static/js/notmuch-0.1.js
 create mode 100644 devel/notmuch-web/templates/base.html
 create mode 100644 devel/notmuch-web/templates/index.html
 create mode 100644 devel/notmuch-web/templates/search.html
 create mode 100644 devel/notmuch-web/templates/show.html
 create mode 100644 devel/notmuch-web/todo

diff --git a/NEWS b/NEWS
index e39af344..9928ffa3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,15 @@
+New add-on tool: notmuch-web
+-
+
+The new contrib/ tool `notmuch-web` is a very thin web client.  It
+supports a full search interface for one user: there is no facility
+for multiple users provided today.  See the notmuch-web README file
+for more information.
+
+Be careful about running it on a network-connected system: it will
+expose a web interface that requires no authentication but exposes
+your mail store.
+
 Notmuch 0.34.3 (2022-01-09)
 ===
 
diff --git a/devel/notmuch-web/nmgunicorn.py b/devel/notmuch-web/nmgunicorn.py
new file mode 100644
index ..e71ba12a
--- /dev/null
+++ b/devel/notmuch-web/nmgunicorn.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+
+# to launch nmweb from gunicorn.
+
+from nmweb import urls, index, search, show
+import web
+
+app = web.application(urls, globals())
+
+# get the wsgi app from web.py application object
+wsgiapp = app.wsgifunc()
diff --git a/devel/notmuch-web/nmweb.py b/devel/notmuch-web/nmweb.py
new file mode 100755
index ..928e4863
--- /dev/null
+++ b/devel/notmuch-web/nmweb.py
@@ -0,0 +1,366 @@
+#!/usr/bin/env python
+
+from __future__ import absolute_import
+
+try:
+  from urllib.parse import quote_plus
+  from urllib.parse import unquote_plus
+except ImportError:
+  from urllib import quote_plus
+  from urllib import unquote_plus
+
+from datetime import datetime
+from mailbox import MaildirMessage
+import mimetypes
+import email
+import re
+import html
+import os
+
+import bleach
+import web
+from notmuch2 import Database
+from jinja2 import Environment, FileSystemLoader # FIXME to PackageLoader
+from jinja2 import Markup
+try:
+  import bjoern # from https://github.com/jonashaag/bjoern/
+  use_bjoern = True
+except:
+  use_bjoern = False
+
+# Configuration options
+safe_tags = bleach.sanitizer.ALLOWED_TAGS + \
+[u'div', u'span', u'p', u'br', u'table', u'tr', u'td', u'th']
+linkify_plaintext = True # delays page load by about 0.02s of 0.20s budget
+show_thread_nav = True   # delays page load by about 0.04s of 0.20s budget
+
+prefix = os.environ.get('NMWEB_PREFIX', "http://localhost:8080;)
+webprefix = os.environ.get('NMWEB_STATIC', prefix + "/static")
+cachedir = os.environ.get('NMWEB_CACHE', "static/cache") # special for webpy 
server; changeable if using your 

[PATCH] test: known broken test for top level .notmuch in split configs

2022-01-16 Thread David Bremner
In split configurations there is no special significance to a top
level directory called .notmuch in the mail root. Users should
therefore be able to have mail stored underneath it.
---

My only worry was residual .notmuch directories after people switch
from legacy layout to split, but I tested by copying .notmuch to
.foobar and running notmuch new. It cleverly deduced that none of the
xapian database files were mail files, so this seems fine to me.

 test/T055-path-config.sh | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 1df240dd..40009d09 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -316,6 +316,17 @@ db=Database(config=Database.CONFIG.SEARCH)
 m=db.find('20091117232137.ga7...@griffis1.net')
 to=m.header('To')
 print(to)
+EOF
+  test_expect_equal_file EXPECTED OUTPUT
+
+  test_begin_subtest ".notmuch not ignored in split config ($config)"
+  test_subtest_known_broken
+  generate_message '[dir]=.notmuch/cur' '[subject]="Do not ignore, 
very important"'
+  NOTMUCH_NEW > OUTPUT
+  notmuch search subject:Do-not-ignore | notmuch_search_sanitize >> 
OUTPUT
+  cat < EXPECTED
+Added 1 new message to the database.
+thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Do not ignore, very 
important (inbox unread)
 EOF
   test_expect_equal_file EXPECTED OUTPUT
   ;;
-- 
2.34.1

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


Re: [PATCH 1/2] test: add known broken test for ignoring non-toplevel .notmuch

2022-01-16 Thread David Bremner
David Bremner  writes:

> In [1] Rob observed that notmuch new ignored directories called
> .notmuch everywhere in the tree, where they should only (and now, with
> split configs, at most) be ignored at the top level. Add a test to
> demonstrate the problem.
>
> [1]: id:87mwhifu9a@trouble.defaultvalue.org

Series applied to master.

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