[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement bc275caa8d 26/30: Add compose buffer history navi
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement bc275caa8d 26/30: Add compose buffer history navigation commands bound to M-p and M-n |
Date: |
Sun, 3 Mar 2024 06:58:18 -0500 (EST) |
branch: externals/ement
commit bc275caa8d50ae208c5504e496fe8c60dc147b3b
Author: Phil Sainty <phil@catalyst.net.nz>
Commit: Phil Sainty <phil@catalyst.net.nz>
Add compose buffer history navigation commands bound to M-p and M-n
Navigate `ement-room-message-history'.
New commands:
- ement-room-compose-message-history-prev-message
- ement-room-compose-message-history-next-message
- ement-room-compose-abort-no-history
(ement-room-init-compose-buffer) Update key bindings.
---
ement-room.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 57 insertions(+), 5 deletions(-)
diff --git a/ement-room.el b/ement-room.el
index f3f54209ac..3ea9854429 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -4277,12 +4277,14 @@ See also `ement-room-compose-send'."
(ement--original-event-for
replying-to-event
session)))))))
-(defun ement-room-compose-abort ()
- "Kill the compose buffer and window."
- (interactive)
+(defun ement-room-compose-abort (&optional no-history)
+ "Kill the compose buffer and window.
+With prefix arg NO-HISTORY, do not add to `ement-room-message-history'."
+ (interactive "P")
(let ((body (ement-room-compose-buffer-string-trimmed))
(room ement-room))
- (add-to-history 'ement-room-message-history body)
+ (unless no-history
+ (add-to-history 'ement-room-message-history body))
(kill-buffer)
(delete-window)
;; Make sure we end up with the associated room buffer selected.
@@ -4296,6 +4298,11 @@ See also `ement-room-compose-send'."
(throw 'room-win win))))))))
(select-window win))))
+(defun ement-room-compose-abort-no-history ()
+ "Kill the compose buffer and window without adding to the history."
+ (interactive)
+ (ement-room-compose-abort t))
+
(defun ement-room-init-compose-buffer (room session)
"Set up the current buffer as a compose buffer.
Sets ROOM and SESSION buffer-locally, binds `save-buffer' in
@@ -4318,8 +4325,10 @@ a copy of the local keymap, and sets
`header-line-format'."
(use-local-map (if (current-local-map)
(copy-keymap (current-local-map))
(make-sparse-keymap)))
+ ;; When `ement-room-self-insert-mode' is enabled, deleting the final
character of the
+ ;; message aborts and kills the compose buffer.
(local-set-key [remap delete-backward-char]
- `(menu-item "" ement-room-compose-abort
+ `(menu-item "" ement-room-compose-abort-no-history
:filter ,(lambda (cmd)
(and ement-room-self-insert-mode
(<= (buffer-size) 1)
@@ -4327,6 +4336,8 @@ a copy of the local keymap, and sets
`header-line-format'."
cmd))))
(local-set-key [remap save-buffer] #'ement-room-dispatch-send-message)
(local-set-key (kbd "C-c C-k") #'ement-room-compose-abort)
+ (local-set-key (kbd "M-n") #'ement-room-compose-history-next-message)
+ (local-set-key (kbd "M-p") #'ement-room-compose-history-prev-message)
(setq header-line-format
(concat (substitute-command-keys
(format " Press \\[save-buffer] to send message to room (%s),
or \\[ement-room-compose-abort] to cancel."
@@ -4413,6 +4424,47 @@ Used with `dabbrev-friend-buffer-function'."
(with-current-buffer buffer
(derived-mode-p 'ement-room-mode)))
+;;; Message history for compose buffers.
+
+(defvar-local ement-room--compose-message-history-index -1)
+(defvar-local ement-room--compose-message-history-initial "")
+
+(defun ement-room-compose-history-prev-message (arg)
+ "Cycle backward through message history, after saving current message.
+With a numeric prefix ARG, go back ARG messages."
+ (interactive "*p")
+ (let ((len (length ement-room-message-history)))
+ (cond ((<= len 0)
+ (user-error "Empty message history"))
+ ((eql arg 0)) ;; No-op.
+ ((and (> arg 0) (>= ement-room--compose-message-history-index (1-
len)))
+ (user-error "Beginning of history; no preceding item"))
+ ((and (< arg 0) (< ement-room--compose-message-history-index 0))
+ (user-error "End of history; no next item"))
+ (t
+ ;; Store the not-from-history buffer message.
+ (when (< ement-room--compose-message-history-index 0)
+ (setq ement-room--compose-message-history-initial
+ (ement-room-compose-buffer-string-trimmed)))
+ ;; Update the index.
+ (setq ement-room--compose-message-history-index
+ (let ((newidx (+ arg
ement-room--compose-message-history-index)))
+ (cond ((>= newidx len) (1- len))
+ ((< newidx -1) -1)
+ (t newidx))))
+ ;; Update the buffer.
+ (erase-buffer)
+ (insert (if (< ement-room--compose-message-history-index 0)
+ ement-room--compose-message-history-initial
+ (nth ement-room--compose-message-history-index
+ ement-room-message-history)))))))
+
+(defun ement-room-compose-history-next-message (arg)
+ "Cycle forward through message history, after saving current message.
+With a numeric prefix ARG, go forward ARG messages."
+ (interactive "*p")
+ (ement-room-compose-history-prev-message (- arg)))
+
;;;;; Widgets
(require 'widget)
- [elpa] externals/ement f9aaf13436 16/30: Add command `ement-room-compose-edit', (continued)
- [elpa] externals/ement f9aaf13436 16/30: Add command `ement-room-compose-edit', ELPA Syncer, 2024/03/03
- [elpa] externals/ement a8a15f64d1 19/30: Auto-resize for the compose buffer window height, ELPA Syncer, 2024/03/03
- [elpa] externals/ement 5f17b30f1f 17/30: Add command `ement-room-compose-reply', ELPA Syncer, 2024/03/03
- [elpa] externals/ement 942203912c 20/30: Add user option `ement-room-compose-method', ELPA Syncer, 2024/03/03
- [elpa] externals/ement d40a532733 22/30: Provide prefix key labels for `which-key' (and similar) to display, ELPA Syncer, 2024/03/03
- [elpa] externals/ement 5690ee4f4b 15/30: Change: Enable event highlighting for compose buffers, ELPA Syncer, 2024/03/03
- [elpa] externals/ement b23874e736 18/30: Add user option `ement-room-compose-buffer-display-action', ELPA Syncer, 2024/03/03
- [elpa] externals/ement db55c046d7 21/30: Add `ement-room-self-insert-mode', ELPA Syncer, 2024/03/03
- [elpa] externals/ement 7f8e3662b7 23/30: Add targeted dabbrev support for compose buffers, ELPA Syncer, 2024/03/03
- [elpa] externals/ement 4f7e433d07 24/30: ement-room-compose-message: Minimise scrolling in other windows, ELPA Syncer, 2024/03/03
- [elpa] externals/ement bc275caa8d 26/30: Add compose buffer history navigation commands bound to M-p and M-n,
ELPA Syncer <=
- [elpa] externals/ement 2a79d91374 28/30: Docs: Changelog entries for compose buffer enhancements, ELPA Syncer, 2024/03/03
- [elpa] externals/ement 0d9451a253 29/30: Fix: completion-at-point in compose buffers, ELPA Syncer, 2024/03/03
- [elpa] externals/ement 91f29046de 25/30: Change: (ement-room-init-compose-buffer): Set yank-excluded-properties, ELPA Syncer, 2024/03/03
- [elpa] externals/ement b5db22cd58 27/30: Add compose buffer history search commands bound to M-r and C-M-r, ELPA Syncer, 2024/03/03
- [elpa] externals/ement efb6005c10 30/30: Merge: Compose buffer enhancements, etc., ELPA Syncer, 2024/03/03