unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Foldable "cut here" snippets in notmuch-show
@ 2019-03-19 10:31 Pierre Neidhardt
  2019-03-19 16:41 ` [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here' David Edmondson
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre Neidhardt @ 2019-03-19 10:31 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

Hi,

It'd be nice if notmuch-show could treat the snippets produced by Emacs'
`message-mark-inserted-region' specially, e.g.:

--8<---------------cut here---------------start------------->8---
foo
--8<---------------cut here---------------end--------------->8---

and make them foldable.

(Note that the enclosing lines are defined in ‘message-mark-insert-begin’
and ‘message-mark-insert-end’.)

Thoughts?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here'
  2019-03-19 10:31 Foldable "cut here" snippets in notmuch-show Pierre Neidhardt
@ 2019-03-19 16:41 ` David Edmondson
  2019-03-20  8:52   ` Pierre Neidhardt
  2019-04-25 22:17   ` David Bremner
  0 siblings, 2 replies; 6+ messages in thread
From: David Edmondson @ 2019-03-19 16:41 UTC (permalink / raw)
  To: notmuch

Add `notmuch-wash-cut-here' as a washing function that can be added to
`notmuch-show-insert-text/plain-hook' to excerpt 'cut here' sections,
such as those generated by `message-mark-inserted-region'.
---
 emacs/notmuch-wash.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 54108d93..2ca9c108 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -426,6 +426,37 @@ for error."
 
 ;;
 
+(defcustom notmuch-wash-button-cut/here-hidden-format
+  "[ %d-line cut here. Click/Enter to show. ]"
+  "String used to construct button text for hidden 'cut here' sections.
+Can use up to one integer format parameter, i.e. %d."
+  :type 'string
+  :group 'notmuch-wash)
+
+(defcustom notmuch-wash-button-cut/here-visible-format
+  "[ %d-line cut here. Click/Enter to hide. ]"
+  "String used to construct button text for visible 'cut here' sections.
+Can use up to one integer format parameter, i.e. %d."
+  :type 'string
+  :group 'notmuch-wash)
+
+(define-button-type 'notmuch-wash-button-cut/here-toggle-type
+  'help-echo "mouse-1, RET: Show original message"
+  :supertype 'notmuch-wash-button-invisibility-toggle-type)
+
+(defconst notmuch-wash--cut-here-start (concat "^" message-mark-insert-begin))
+(defconst notmuch-wash--cut-here-end (concat "^" message-mark-insert-end))
+
+(defun notmuch-wash-cut-here (msg depth)
+  "Excerpt 'cut here' sections, hiding them by default."
+  (goto-char (point-min))
+  (while (re-search-forward notmuch-wash--cut-here-start nil t)
+    (let ((start (match-beginning 0)))
+      (when (re-search-forward notmuch-wash--cut-here-end nil t)
+	(notmuch-wash-region-to-button msg start (point) "cut/here")))))
+
+;;
+
 (provide 'notmuch-wash)
 
 ;;; notmuch-wash.el ends here
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here'
  2019-03-19 16:41 ` [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here' David Edmondson
@ 2019-03-20  8:52   ` Pierre Neidhardt
  2019-03-20 10:20     ` David Edmondson
  2019-04-25 22:17   ` David Bremner
  1 sibling, 1 reply; 6+ messages in thread
From: Pierre Neidhardt @ 2019-03-20  8:52 UTC (permalink / raw)
  To: David Edmondson, notmuch

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

I've added notmuch-wash-cut-here to notmuch-show-insert-text/plain-hook, and
this works great, thanks for the prompt solution! :)

Question: Is is possible to configure the wash function to be expanded
by default?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here'
  2019-03-20  8:52   ` Pierre Neidhardt
@ 2019-03-20 10:20     ` David Edmondson
  2019-04-03  7:54       ` Pierre Neidhardt
  0 siblings, 1 reply; 6+ messages in thread
From: David Edmondson @ 2019-03-20 10:20 UTC (permalink / raw)
  To: Pierre Neidhardt, notmuch

On Wednesday, 2019-03-20 at 09:52:24 +01, Pierre Neidhardt wrote:

> Question: Is is possible to configure the wash function to be expanded
> by default?

Probably the simplest approach would be to have
`notmuch-wash-region-to-button' return the button it creates to the
caller, which could then call `notmuch-wash-toggle-invisible-action' to
cause the button to be visible.

dme.
-- 
I'm in a backless dress on a pastel ward that's shining.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here'
  2019-03-20 10:20     ` David Edmondson
@ 2019-04-03  7:54       ` Pierre Neidhardt
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre Neidhardt @ 2019-04-03  7:54 UTC (permalink / raw)
  To: David Edmondson, notmuch

[-- Attachment #1: Type: text/plain, Size: 200 bytes --]

That'd be great!
Would you like to implement this?

Either way, the patch looks good to me and it'd be great to see it
merged upstream.

Thanks!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here'
  2019-03-19 16:41 ` [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here' David Edmondson
  2019-03-20  8:52   ` Pierre Neidhardt
@ 2019-04-25 22:17   ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2019-04-25 22:17 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> Add `notmuch-wash-cut-here' as a washing function that can be added to
> `notmuch-show-insert-text/plain-hook' to excerpt 'cut here' sections,
> such as those generated by `message-mark-inserted-region'.

How hard would it be to test this? Usually we like to have a test added
to the test suite for a new feature.

d

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-04-25 22:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 10:31 Foldable "cut here" snippets in notmuch-show Pierre Neidhardt
2019-03-19 16:41 ` [PATCH v1 1/1] emacs: Add `notmuch-wash-cut-here' David Edmondson
2019-03-20  8:52   ` Pierre Neidhardt
2019-03-20 10:20     ` David Edmondson
2019-04-03  7:54       ` Pierre Neidhardt
2019-04-25 22:17   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).