zap-to-char: case sensitive for upper-case characters
In interactive calls, behave case-sensitively if the given char is an upper-case character. Same for zap-up-to-char (Bug#54804). This is analog to what the user-level incremental search feature does. * lisp/misc.el (zap-up-to-char): Add an optional arg INTERACTIVE. Perform a case-sensitive search when INTERACTIVE is non-nil and CHAR is an upper-case character. * lisp/simple.el (zap-to-char): Same. * etc/NEWS (Editing Changes in Emacs 29.1): Announce this change. * test/lisp/misc-tests.el (misc-test-zap-up-to-char): Add test cases. * test/lisp/simple-tests.el (with-zap-to-char-test): Add helper macro. (simple-tests-zap-to-char): Add a test.
This commit is contained in:
6
etc/NEWS
6
etc/NEWS
@@ -698,6 +698,12 @@ Formerly it invoked 'just-one-space'. The actions performed by
|
||||
'cycle-spacing' and their order can now be customized via the user
|
||||
option 'cycle-spacing-actions'.
|
||||
|
||||
---
|
||||
** 'zap-to-char' and 'zap-up-to-char' are case-sensitive for upper-case chars.
|
||||
These commands now behave as case-sensitive for interactive calls when
|
||||
are invoked with an uppercase argument, regardless of the
|
||||
`case-fold-search' value.
|
||||
|
||||
---
|
||||
** 'scroll-other-window' and 'scroll-other-window-down' now respect remapping.
|
||||
These commands (bound to 'C-M-v' and 'C-M-V') used to scroll the other
|
||||
|
||||
15
lisp/misc.el
15
lisp/misc.el
@@ -64,15 +64,22 @@ The characters copied are inserted in the buffer before point."
|
||||
;; Variation of `zap-to-char'.
|
||||
|
||||
;;;###autoload
|
||||
(defun zap-up-to-char (arg char)
|
||||
(defun zap-up-to-char (arg char &optional interactive)
|
||||
"Kill up to, but not including ARGth occurrence of CHAR.
|
||||
When run interactively, the argument INTERACTIVE is non-nil.
|
||||
Case is ignored if `case-fold-search' is non-nil in the current buffer.
|
||||
Goes backward if ARG is negative; error if CHAR not found.
|
||||
Ignores CHAR at point."
|
||||
Ignores CHAR at point.
|
||||
If called interactively, do a case sensitive search if CHAR
|
||||
is an upper-case character."
|
||||
(interactive (list (prefix-numeric-value current-prefix-arg)
|
||||
(read-char-from-minibuffer "Zap up to char: "
|
||||
nil 'read-char-history)))
|
||||
(let ((direction (if (>= arg 0) 1 -1)))
|
||||
nil 'read-char-history)
|
||||
t))
|
||||
(let ((direction (if (>= arg 0) 1 -1))
|
||||
(case-fold-search (if (and interactive (char-uppercase-p char))
|
||||
nil
|
||||
case-fold-search)))
|
||||
(kill-region (point)
|
||||
(progn
|
||||
(forward-char direction)
|
||||
|
||||
@@ -6342,21 +6342,26 @@ then gives correct answers only for ASCII characters."
|
||||
(characterp (get-char-code-property char 'lowercase)))
|
||||
((and (>= char ?A) (<= char ?Z)))))
|
||||
|
||||
(defun zap-to-char (arg char)
|
||||
(defun zap-to-char (arg char &optional interactive)
|
||||
"Kill up to and including ARGth occurrence of CHAR.
|
||||
When run interactively, the argument INTERACTIVE is non-nil.
|
||||
Case is ignored if `case-fold-search' is non-nil in the current buffer.
|
||||
Goes backward if ARG is negative; error if CHAR not found.
|
||||
See also `zap-up-to-char'."
|
||||
See also `zap-up-to-char'.
|
||||
If called interactively, do a case sensitive search if CHAR
|
||||
is an upper-case character."
|
||||
(interactive (list (prefix-numeric-value current-prefix-arg)
|
||||
(read-char-from-minibuffer "Zap to char: "
|
||||
nil 'read-char-history)))
|
||||
nil 'read-char-history))
|
||||
t)
|
||||
;; Avoid "obsolete" warnings for translation-table-for-input.
|
||||
(with-no-warnings
|
||||
(if (char-table-p translation-table-for-input)
|
||||
(setq char (or (aref translation-table-for-input char) char))))
|
||||
(kill-region (point) (progn
|
||||
(search-forward (char-to-string char) nil nil arg)
|
||||
(point))))
|
||||
(let ((case-fold-search (if (and interactive (char-uppercase-p char))
|
||||
nil
|
||||
case-fold-search)))
|
||||
(kill-region (point) (search-forward (char-to-string char) nil nil arg))))
|
||||
|
||||
;; kill-line and its subroutines.
|
||||
|
||||
|
||||
@@ -44,7 +44,14 @@
|
||||
(zap-up-to-char 1 ?c))
|
||||
(with-misc-test "abcde abc123" "c123"
|
||||
(goto-char (point-min))
|
||||
(zap-up-to-char 2 ?c)))
|
||||
(zap-up-to-char 2 ?c))
|
||||
(let ((case-fold-search t))
|
||||
(with-misc-test "abcdeCXYZ" "cdeCXYZ"
|
||||
(goto-char (point-min))
|
||||
(zap-up-to-char 1 ?C))
|
||||
(with-misc-test "abcdeCXYZ" "CXYZ"
|
||||
(goto-char (point-min))
|
||||
(zap-up-to-char 1 ?C 'interactive))))
|
||||
|
||||
(ert-deftest misc-test-upcase-char ()
|
||||
(with-misc-test "abcde" "aBCDe"
|
||||
|
||||
@@ -1004,6 +1004,27 @@ See Bug#21722."
|
||||
(yank-in-context)
|
||||
(buffer-string))
|
||||
"echo 'f'\\''bar'\\''oo'")))
|
||||
|
||||
;;; Tests for `zap-to-char'
|
||||
|
||||
(defmacro with-zap-to-char-test (original result &rest body)
|
||||
(declare (indent 2) (debug (stringp stringp body)))
|
||||
`(with-temp-buffer
|
||||
(insert ,original)
|
||||
(goto-char (point-min))
|
||||
,@body
|
||||
(should (equal (buffer-string) ,result))))
|
||||
|
||||
(ert-deftest simple-tests-zap-to-char ()
|
||||
(with-zap-to-char-test "abcde" "de"
|
||||
(zap-to-char 1 ?c))
|
||||
(with-zap-to-char-test "abcde abc123" "123"
|
||||
(zap-to-char 2 ?c))
|
||||
(let ((case-fold-search t))
|
||||
(with-zap-to-char-test "abcdeCXYZ" "deCXYZ"
|
||||
(zap-to-char 1 ?C))
|
||||
(with-zap-to-char-test "abcdeCXYZ" "XYZ"
|
||||
(zap-to-char 1 ?C 'interactive))))
|
||||
|
||||
(provide 'simple-test)
|
||||
;;; simple-tests.el ends here
|
||||
|
||||
Reference in New Issue
Block a user