Subject: 30.0.93; Turn remember mode into a minor mode
From: Matthias Meulien <[email-masked]>
To: [email-masked]
Date: Mon, 13 Jan 2025 23:16:48 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

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 know of Org Capture mode but don't understand why capturing notes
relates to Org mode and I am not interested in Org markup langage; No
judgement, just used to Makdown).

In GNU Emacs 30.0.93 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2025-01-01 built on peitho
Repository revision: 7acfea19358da3a02e5884f5e7d56c87d7b16616
Repository branch: emacs-30
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-pgtk CFLAGS=-O3'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM GTK3 ZLIB

Important settings:
  value of $LANG: fr_FR.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Shell

Minor modes in effect:
  goto-address-mode: t
  highlight-changes-visible-mode: t
  pulsar-global-mode: t
  pulsar-mode: t
  breadcrumb-mode: t
  desktop-save-mode: t
  spacious-padding-mode: t
  savehist-mode: t
  server-mode: t
  pixel-scroll-precision-mode: t
  save-place-mode: t
  shell-dirtrack-mode: t
  comint-fontify-input-mode: t
  electric-pair-mode: t
  global-corfu-mode: t
  corfu-mode: t
  marginalia-mode: t
  vertico-mode: t
  global-display-fill-column-indicator-mode: t
  global-so-long-mode: t
  global-auto-revert-mode: t
  auto-insert-mode: t
  which-key-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-layout-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  window-divider-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/matthias/.config/emacs/elpa/which-key-20240620.2145/which-key hides
/usr/local/share/emacs/30.0.93/lisp/which-key
/home/matthias/.config/emacs/elpa/modus-themes-20250107.1034/theme-loaddefs
hides /usr/local/share/emacs/30.0.93/lisp/theme-loaddefs

Features:
(shadow sort mail-extr emacsbug pcmpl-unix pcmpl-gnu vc-hg vc-bzr vc-src
vc-sccs vc-svn vc-cvs vc-rcs log-view pcvs-util tramp-cache time-stamp
shortdoc find-dired ffap dabbrev hl-line grep quail rng-xsd xsd-regexp
rng-cmpct rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse
rng-match rng-dt rng-util rng-pttrn nxml-ns nxml-mode nxml-outln
nxml-rap nxml-util nxml-enc xmltok mhtml-mode css-mode js sgml-mode
facemenu make-mode generic disp-table cmake-mode rst yaml-ts-mode tabify
cus-start help-fns radix-tree mule-util etags fileloop misearch
multi-isearch dired-aux vc-dir vc oc-basic ol-eww eww url-queue mm-url
ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect gnus-art mm-uu mml2015
mm-view mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku
url-file svg dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml
gnus-cloud nnimap nnmail mail-source utf7 nnoo gnus-spec gnus-int
gnus-range message sendmail yank-media puny rfc822 mml mml-sec epa epg
rfc6068 epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231
rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus-win gnus
nnheader gnus-util mail-utils range mm-util mail-prsvr ol-docview
doc-view image-mode exif ol-bibtex bibtex ol-bbdb ol-w3m ol-doi
org-link-doi gptel-org org-element org-persist org-id org-refile
org-element-ast inline avl-tree generator org ob ob-tangle ob-ref ob-lob
ob-table ob-exp org-macro org-src sh-script smie executable ob-comint
org-pcomplete org-list org-footnote org-faces org-entities ob-emacs-lisp
ob-core ob-eval org-cycle org-table ol org-fold org-fold-core org-keys
oc org-loaddefs cal-menu calendar cal-loaddefs org-version org-compat
org-macs jka-compr goto-addr texinfo texinfo-loaddefs bug-reference
display-line-numbers hilit-chg pulsar eglot external-completion jsonrpc
flymake ert ewoc debug backtrace breadcrumb pulse imenu gptel-ollama
gptel gptel-openai peitho-custom cus-edit cus-load wid-edit dired-x
dired dired-loaddefs xref reftex reftex-loaddefs reftex-vars tex-mode
compile markdown-mode edit-indirect color sql view thingatpt scheme
info-look python project pcase c++-ts-mode c-ts-mode c-ts-common treesit
skeleton find-file gdb-mi bindat gud noutline outline ediff ediff-merg
ediff-mult ediff-wind ediff-diff ediff-help ediff-init ediff-util
smerge-mode diff vc-git diff-mode track-changes vc-dispatcher glasses
whitespace guess-language flyspell find-func ispell comp comp-cstr
cl-extra warnings comp-run comp-common desktop frameset spacious-padding
modus-vivendi-tritanopia-theme modus-vivendi-deuteranopia-theme
modus-vivendi-tinted-theme modus-vivendi-theme
modus-operandi-tritanopia-theme modus-operandi-deuteranopia-theme
modus-operandi-tinted-theme modus-operandi-theme modus-themes savehist
server bookmark text-property-search pp pixel-scroll cua-base time
tar-mode arc-mode archive-mode saveplace tramp-sh tramp trampver
tramp-integration files-x tramp-message help-mode tramp-compat xdg shell
pcomplete comint ansi-osc ring parse-time iso8601 time-date format-spec
ansi-color tramp-loaddefs elec-pair corfu marginalia vertico compat
easy-mmode display-fill-column-indicator so-long autorevert filenotify
autoinsert cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs generic-x derived remember diminish which-key
face-remap CMake-doc-autoloads Python-doc-autoloads breadcrumb-autoloads
cmake-mode-autoloads consult-autoloads corfu-autoloads debbugs-autoloads
devhelp-autoloads diminish-autoloads edit-indirect-autoloads
git-link-autoloads gnu-elpa-keyring-update-autoloads gptel-autoloads
guess-language-autoloads marginalia-autoloads markdown-mode-autoloads
meson-mode-autoloads modus-themes-autoloads nginx-mode-autoloads
powershell-autoloads pulsar-autoloads restclient-autoloads
rfc-mode-autoloads info spacious-padding-autoloads speechd-el-autoloads
systemd-autoloads rx tldr-autoloads vertico-autoloads
which-key-autoloads package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs icons password-cache json subr-x map byte-opt
gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl
tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/pgtk-win pgtk-win term/common-win
touch-screen pgtk-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify dynamic-setting system-font-setting
font-render-setting cairo gtk pgtk lcms2 multi-tty move-toolbar
make-network-process native-compile emacs)

Memory information:
((conses 16 1069376 162349) (symbols 48 45056 0)
 (strings 32 184191 10737) (string-bytes 1 6917497) (vectors 16 85172)
 (vector-slots 8 1880049 212634) (floats 8 1010 1581)
 (intervals 56 33362 1873) (buffers 992 143))

-- 
Matthias
From 3cdbedcc4f0842e54f3697b94f7f68d3ec4412df 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
---
 lisp/textmodes/remember.el | 62 +++++++++++++++++++++++++++++++++-----
 1 file changed, 54 insertions(+), 8 deletions(-)

diff --git a/lisp/textmodes/remember.el b/lisp/textmodes/remember.el
index cc3496da33c..24c20d7653e 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,27 @@ 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))
+
+(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 +591,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 +619,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 +636,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 +706,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