Skip to main content
edited tags; edited title
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

Make delete-region apply to the isearch buffer Delete portion of Isearch string that does not match, or last char if complete match

Add syntax highlighting
Source Link
Kaushal Modi
  • 26k
  • 4
  • 83
  • 191

I have the following

(defun isearch-del-fail-or-char ()
  "Delete failed isearch text, or if there is none, a single character."
  (interactive)
  (if (isearch-fail-pos)
      (delete-region (isearch-fail-pos) (point))
    (isearch-del-char)))

(define-key isearch-mode-map (kbd "DEL") 'isearch-del-fail-or-char)
(defun isearch-del-fail-or-char ()
  "Delete failed isearch text, or if there is none, a single character."
  (interactive)
  (if (isearch-fail-pos)
      (delete-region (isearch-fail-pos) (point))
    (isearch-del-char)))

(define-key isearch-mode-map (kbd "DEL") 'isearch-del-fail-or-char)

The purpose of the code is to make delete in isearch delete the entire failed string (or if there is no failed string just a single character).

However, delete-region is deleting text from the buffer isearch is searching in, not the isearch buffer itself.

What is the proper way to do this? Critique on the rest of my emacs lisp style is also welcome :)

I have the following

(defun isearch-del-fail-or-char ()
  "Delete failed isearch text, or if there is none, a single character."
  (interactive)
  (if (isearch-fail-pos)
      (delete-region (isearch-fail-pos) (point))
    (isearch-del-char)))

(define-key isearch-mode-map (kbd "DEL") 'isearch-del-fail-or-char)

The purpose of the code is to make delete in isearch delete the entire failed string (or if there is no failed string just a single character).

However, delete-region is deleting text from the buffer isearch is searching in, not the isearch buffer itself.

What is the proper way to do this? Critique on the rest of my emacs lisp style is also welcome :)

I have the following

(defun isearch-del-fail-or-char ()
  "Delete failed isearch text, or if there is none, a single character."
  (interactive)
  (if (isearch-fail-pos)
      (delete-region (isearch-fail-pos) (point))
    (isearch-del-char)))

(define-key isearch-mode-map (kbd "DEL") 'isearch-del-fail-or-char)

The purpose of the code is to make delete in isearch delete the entire failed string (or if there is no failed string just a single character).

However, delete-region is deleting text from the buffer isearch is searching in, not the isearch buffer itself.

What is the proper way to do this? Critique on the rest of my emacs lisp style is also welcome :)

Source Link
asmeurer
  • 1.6k
  • 13
  • 33

Make delete-region apply to the isearch buffer

I have the following

(defun isearch-del-fail-or-char ()
  "Delete failed isearch text, or if there is none, a single character."
  (interactive)
  (if (isearch-fail-pos)
      (delete-region (isearch-fail-pos) (point))
    (isearch-del-char)))

(define-key isearch-mode-map (kbd "DEL") 'isearch-del-fail-or-char)

The purpose of the code is to make delete in isearch delete the entire failed string (or if there is no failed string just a single character).

However, delete-region is deleting text from the buffer isearch is searching in, not the isearch buffer itself.

What is the proper way to do this? Critique on the rest of my emacs lisp style is also welcome :)