]> git.eshelyaron.com Git - emacs.git/commitdiff
Turn 'remember-mode' into a minor mode
authorMatthias Meulien <orontee@gmail.com>
Mon, 13 Jan 2025 22:04:54 +0000 (23:04 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 15 Mar 2025 15:27:37 +0000 (16:27 +0100)
* 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.
(remember-prefix-map): New.  (Bug#75543)

(cherry picked from commit e937167253208c7e9d22350795e72818dfa2f35b)

lisp/textmodes/remember.el

index f04e0603885b97dd6d1392c62e9a89e7c47e92a3..7a378fed68e029f01f3c539bed23411bc783edfe 100644 (file)
 
 ;;; 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 @@ recorded somewhere by that function."
   :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 @@ With a prefix or a visible region, use the region as INITIAL."
         (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 @@ If you want to remember a region, supply a universal prefix to
 
 (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 @@ The file is named by calling `format-time-string' using
       (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 @@ If this is nil, then `diary-file' will be used instead."
   "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 @@ purpose of storing notes."
   "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 @@ If this is nil, use `initial-major-mode'."
     (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 @@ is non-nil, bury it and return nil; otherwise return t."
         nil)
     t))
 
+;; Prefix map
+
+(define-prefix-command 'remember-prefix-map)
+;; Use with for example:
+;; (keymap-global-set "C-c 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.")