bug#81342: [PATCH] viper-cmd: Simplify quoting by using comment-region
Joshua Murphy <[email protected]> Fri, 07 Aug 2026 16:02:27 +0000
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
> Sounds reasonable, though if you want me to assess properly I think I'd > need to see a patch showing what you propose. I've added it to the patch. I've set it so it is just directly bound to the character rather than getting set indirectly when Viper loads through viper-buffer-search-char. The functionality should be identical. I also noticed a todo in viper.el that seems to want what I'm doing in the patch: "Some of the code that is inherited from VIP-3.5 is rather convoluted. Instead of viper-command-argument, keymaps should bind the actual commands. E.g., "dw" should be bound to a generic command viper-delete that will delete things based on the value of last-command-event. This would greatly simplify the logic and the code." There's definitely a lot of stuff in Viper that seems overly complex. Eventually, I'd like to simplify the rest of the commands like it states, which should make it way easier to add stuff like text objects. But that's a later issue ;) -- Joshua Murphy [email protected]
0001-viper-cmd-add-buffer-prefix.patch
(text/x-patch, 6.2 KB)
From dc98de340a12c3372d4504effbb991c078a2fafa Mon Sep 17 00:00:00 2001 From: Joshua Murphy <[email protected]> Date: Wed, 22 Jul 2026 15:34:54 -0400 Subject: [PATCH] viper-cmd: add buffer prefix * lisp/emulation/viper-cmd.el (viper-buffer-search-enable): Remove function (viper-buffer-prefix): Add function to handle buffer prefix * lisp/emulation/viper-keym.el (viper-vi-basic-map): Bind g to viper-buffer-prefix * lisp/emulation/viper.el (viper-mode): Remove viper-buffer-search-enable * lisp/emulation/viper-init.el (viper-buffer-search-char): Remove variable --- lisp/emulation/viper-cmd.el | 48 +++++++++++++++++++----------------- lisp/emulation/viper-init.el | 5 ---- lisp/emulation/viper-keym.el | 2 +- lisp/emulation/viper.el | 2 -- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el index 3cbdcddac0a..85b4db56ffc 100644 --- a/lisp/emulation/viper-cmd.el +++ b/lisp/emulation/viper-cmd.el @@ -1035,8 +1035,7 @@ as a Meta key and any number of multiple escapes are allowed." cmd-to-exec-at-end) (while (and cont (memq char - (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" - viper-buffer-search-char))) + (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"))) (if com ;; this means that we already have a command character, so we ;; construct a com list and exit while. however, if char is " @@ -1083,7 +1082,6 @@ as a Meta key and any number of multiple escapes are allowed." (viper-digit-command-p char) (viper-regsuffix-command-p char) (viper= char ?!) ; bang command - (viper= char ?g) ; the gg command (like G0) (user-error viper-ViperBell)) (setq cmd-to-exec-at-end (viper-exec-form-in-vi @@ -1116,8 +1114,6 @@ as a Meta key and any number of multiple escapes are allowed." ((equal com '(?> . ?>)) (viper-line (cons value ?>))) ((equal com '(?! . ?!)) (viper-line (cons value ?!))) ((equal com '(?= . ?=)) (viper-line (cons value ?=))) - ;; gg acts as G0 - ((equal (car com) ?g) (viper-goto-line 0)) (t (user-error viper-ViperBell))))) (if cmd-to-exec-at-end @@ -3762,23 +3758,6 @@ Null string will repeat previous search." (viper-execute-com 'viper-search-Next val com))))) -;; Search contents of buffer defined by one of Viper's motion commands. -;; Repeatable via `n' and `N'. -(defun viper-buffer-search-enable (&optional c) - (cond (c (setq viper-buffer-search-char c)) - ((null viper-buffer-search-char) - ;; ?g acts as a default value for viper-buffer-search-char - (setq viper-buffer-search-char ?g))) - (define-key viper-vi-basic-map - (cond ((characterp viper-buffer-search-char) - (char-to-string viper-buffer-search-char)) - (t (error "viper-buffer-search-char: Wrong value type, %S" - viper-buffer-search-char))) - #'viper-command-argument) - (aset viper-exec-array viper-buffer-search-char #'viper-exec-buffer-search) - (setq viper-prefix-commands - (cons viper-buffer-search-char viper-prefix-commands))) - ;; This is a Viper wrapper for isearch-forward. (defun viper-isearch-forward (arg) "Do incremental search forward." @@ -4239,6 +4218,31 @@ type \\[help-command] at that time." (t (user-error viper-ViperBell)) ))) +(defun viper-buffer-prefix (arg) + "Do buffer prefix command with ARG." + (interactive "P") + (let ((char (read-char))) + (cond ((viper= char ?g) + (viper-goto-line (or arg 1))) + ((viper= char ?c) + (if (use-region-p) + (comment-region (region-beginning) (region-end)) + (let ((movement (read-char))) + (cond ((viper-movement-command-p movement) + (push-mark nil t t) + (funcall (viper-exec-form-in-vi + `(key-binding (char-to-string ,movement))) + arg) + (comment-region (region-beginning) (region-end))) + (t (user-error viper-ViperBell)))))) + ((viper-movement-command-p char) + (setq viper-com-point (point)) + (funcall (viper-exec-form-in-vi + `(key-binding (char-to-string ,char))) + arg) + (viper-exec-buffer-search nil nil)) + (t (user-error viper-ViperBell))))) + ;; Algorithm: If first invocation of this command save mark on ring, goto ;; mark, M0, and pop the most recent elt from the mark ring into mark, ;; making it into the new mark, M1. diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el index 6336495e570..5e7b0febdb6 100644 --- a/lisp/emulation/viper-init.el +++ b/lisp/emulation/viper-init.el @@ -682,11 +682,6 @@ If nil, the cursor will move backwards without deleting anything." :type 'boolean :group 'viper) -(defcustom viper-buffer-search-char nil - "Key used for buffer-searching. Must be a character type, e.g., ?g." - :type '(choice (const nil) character) - :group 'viper-search) - (defcustom viper-search-wrap-around t "If t, search wraps around." :type 'boolean diff --git a/lisp/emulation/viper-keym.el b/lisp/emulation/viper-keym.el index f0c4129b9ab..f2afedeb873 100644 --- a/lisp/emulation/viper-keym.el +++ b/lisp/emulation/viper-keym.el @@ -381,7 +381,7 @@ In insert mode, this key also functions as Meta." (define-key viper-vi-basic-map "d" 'viper-command-argument) (define-key viper-vi-basic-map "e" 'viper-end-of-word) (define-key viper-vi-basic-map "f" 'viper-find-char-forward) -(define-key viper-vi-basic-map "g" 'viper-nil) +(define-key viper-vi-basic-map "g" 'viper-buffer-prefix) (define-key viper-vi-basic-map "h" 'viper-backward-char) (define-key viper-vi-basic-map [backspace] 'viper-backward-char) (define-key viper-vi-basic-map "i" 'viper-insert) diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el index 8a381d7ed8c..1630e34fb70 100644 --- a/lisp/emulation/viper.el +++ b/lisp/emulation/viper.el @@ -1198,8 +1198,6 @@ These two lines must come in the order given.")) (when viper-mode (viper-set-minibuffer-style) - (if viper-buffer-search-char - (viper-buffer-search-enable)) (viper-update-syntax-classes 'set-default) ;; Familiarize Viper with some minor modes that have their own keymaps -- 2.55.0