Subject: Re: bug#75543: 30.0.93; Turn remember mode into a minor mode

From: Matthias Meulien <[email-masked]>
Date: Sun, 23 Feb 2025 11:53:02 +0100

Since people started working on a major mode for Markdown, these minor
changes may have gained some interest...

I attach an updated patch.

Le sam. 25 janv. 2025 à 10:00, Eli Zaretskii <[email-masked]> a écrit :

> > From: Matthias Meulien <[email-masked]>
> > Date: Mon, 13 Jan 2025 23:16:48 +0100
> >
> > Remember Mode is great but I encountered two limitations:
> >
> > - The major mode to edit data to remember is hard-coded to `text-mode'
> >   where one may want to use Enriched text, Markdown, etc. modes
> >
> > - A possible workflow is to select the file to store the data
> >   dynamically, after the data to remember has been edited
> >
> > A patch is attached that turn `remember-mode' into a minor mode and
> > define a customizable variable `remember-initial-major-mode' to select
> > the major mode used to edit data to remember.
> >
> > It also defines the `remember-append-in-data-directory' handler that
> > covers the second limitation.
> >
> > Finally, a prefix map is defined for the `remember',
> > `remember-clipboard', and `remember-notes' commands.
> >
> > I am using analogous modifications to maintain my personnal notes in
> > Markdown format. I don't claim the patch is to be used as is, but I
> think it illustrate
> > possible evolutions of the simple but great Remember mode.
> >
> > Are such changes acceptable and pertinent? Is it worth to fine tune the
> patch? Comments welcome!
>
> I don't see why we won't want to extend Remember mode along these
> lines.  Stefan, WDYT?
>
> If Stefan agrees, please do finalize the patch and resubmit.  The few
> minor issues I saw is that all the new defcustoms should have the
> :version tag, and this needs a NEWS entry.
>

-- 
Matthias
From c23f6f1b45b2f4acadbfebb2cf9bb24c105bd1d2 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <[email-masked]>
Date: Mon, 13 Jan 2025 23:04:54 +0100
Subject: [PATCH] Turn remember-mode into a minor mode

* lisp/textmodes/remember.el (remember-initial-major-mode):
Major mode for remember buffer
(remember-data-files-regex): Regular expression to filter files
(remember-append-in-data-directory): Handler to append data to
files
(remember-mode): Change to a minor mode
---
 etc/NEWS                   | 20 ++++++++++++
 lisp/textmodes/remember.el | 63 +++++++++++++++++++++++++++++++++-----
 2 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ccde4ed4b70..7b6cefedb24 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1290,6 +1290,26 @@ Major-mode authors can customize the variables
 'yank-media-autoselect-function' and/or 'yank-media-preferred-types' to
 change the selection rules.
 
+** Remember
+
+---
+*** `remember-mode' is now a minor mode.
+The `remember' command enables the major mode set in
+`remember-initial-major-mode' and then the `remember-mode' minor mode in
+the `remember-buffer'.  This allows users to customize the major mode
+used to write notes.
+
+---
+*** New handler that append remember data in directory.
+The `remember-append-in-data-directory' handler appends remember data in
+a file, that file being choosen by the user through the minibuffer.
+
+---
+*** New prefix map for remember commands.
+Meant to be given a global binding convenient to the user.  Example:
+
+    (keymap-global-set "C-x M-r" 'remember-prefix-map)
+
 ** Miscellaneous
 
 ---
diff --git a/lisp/textmodes/remember.el b/lisp/textmodes/remember.el
index f04e0603885..64de199319a 100644
--- a/lisp/textmodes/remember.el
+++ b/lisp/textmodes/remember.el
@@ -182,6 +182,12 @@ remember
 
 ;;; User Variables:
 
+(defcustom remember-initial-major-mode 'text-mode
+  "Major mode to use in the `remember-buffer'."
+  :type '(choice (const    :tag "Use `initial-major-mode'" nil)
+		 (function :tag "Major mode" text-mode))
+  :version "31.0")
+
 (defcustom remember-mode-hook nil
   "Functions run upon entering `remember-mode'."
   :type 'hook
@@ -210,7 +216,8 @@ remember-handler-functions
   :options '(remember-store-in-mailbox
              remember-append-to-file
              remember-store-in-files
-             remember-diary-extract-entries))
+             remember-diary-extract-entries
+             remember-append-in-data-directory))
 
 (defcustom remember-all-handler-functions nil
   "If non-nil every function in `remember-handler-functions' is called."
@@ -283,6 +290,8 @@ remember
         (set-window-dedicated-p
          (get-buffer-window (current-buffer) (selected-frame)) t))
     (setq buffer-offer-save t)
+    (funcall (or remember-initial-major-mode
+                 initial-major-mode))
     (remember-mode)
     (when (= (point-max) (point-min))
       (when initial (insert initial))
@@ -450,7 +459,8 @@ remember-region
 
 (defcustom remember-data-directory "~/remember"
   "The directory in which to store remember data as files.
-Used by `remember-store-in-files'."
+Used by `remember-store-in-files' and
+`remember-append-in-data-directory'."
   :type 'directory
   :version "24.4")
 
@@ -472,6 +482,28 @@ remember-store-in-files
       (write-file (convert-standard-filename
                    (format "%s/%s" remember-data-directory name))))))
 
+(defcustom remember-data-files-regex nil
+  "Regular expression for specifying which files to append data.
+If non-nil, keep only files whose non-directory part match the regexp.
+Used by `remember-append-in-data-directory'."
+  :type '(choice (const :tag "Any file" nil) regexp)
+  :version "31.0")
+
+(defun remember-append-in-data-directory ()
+  "Append remember data to a file in `remember-data-directory'.
+The file name is read from minibuffer.
+
+If you want to filter proposed files, configure
+`remember-data-files-regex'."
+  (let* ((name
+        (completing-read "Remember in file: "
+                         (directory-files
+                          (expand-file-name remember-data-directory)
+                          nil
+                          remember-data-files-regex)))
+         (remember-data-file (expand-file-name name remember-data-directory)))
+    (remember-append-to-file)))
+
 ;;;###autoload
 (defun remember-clipboard ()
   "Remember the contents of the current clipboard.
@@ -560,15 +592,20 @@ remember-mode-map
   "C-c C-c" #'remember-finalize
   "C-c C-k" #'remember-destroy)
 
-(define-derived-mode remember-mode text-mode "Remember"
-  "Major mode for output from \\[remember].
+(define-minor-mode remember-mode
+  "Minor mode for output from \\[remember].
 This buffer is used to collect data that you want to remember.
 \\<remember-mode-map>
 Just hit \\[remember-finalize] when you're done entering, and it will file
 the data away for latter retrieval, and possible indexing.
 
 \\{remember-mode-map}"
-  (set-keymap-parent remember-mode-map nil))
+  :lighter " Remember"
+  :keymap remember-mode-map
+  (setq header-line-format
+        (substitute-command-keys
+         "Edit, then exit with `\\[remember-finalize]' or abort with \
+  `\\[remember-destroy]'")))
 
 ;; Notes buffer showing the notes:
 
@@ -583,7 +620,9 @@ remember-notes-initial-major-mode
   "Major mode to use in the notes buffer when it's created.
 If this is nil, use `initial-major-mode'."
   :type '(choice (const    :tag "Use `initial-major-mode'" nil)
-		 (function :tag "Major mode" text-mode))
+                 (const    :tag "Use `remember-initial-major-mode'"
+                           remember-initial-major-mode)
+                 (function :tag "Major mode" text-mode))
   :version "24.4")
 
 (defcustom remember-notes-bury-on-kill t
@@ -598,8 +637,6 @@ remember-notes-save-and-bury-buffer
     (save-buffer))
   (bury-buffer))
 
-
-
 (defvar-keymap remember-notes-mode-map
   :doc "Keymap used in `remember-notes-mode'."
   "C-c C-c" #'remember-notes-save-and-bury-buffer)
@@ -670,6 +707,16 @@ remember-notes--kill-buffer-query
         nil)
     t))
 
+;; Prefix map
+
+(define-prefix-command 'remember-prefix-map)
+;; Use with for example:
+;; (keymap-global-set "C-x M-r" 'remember-prefix-map)
+
+(keymap-set remember-prefix-map "r" 'remember)
+(keymap-set remember-prefix-map "c" 'remember-clipboard)
+(keymap-set remember-prefix-map "n" 'remember-notes)
+
 ;; Obsolete
 
 (defconst remember-version "2.0" "This version of remember.")
-- 
2.39.5