0

It's about deleting minibuffer input without trying to also delete some of the minibuffer prompt (which is read-only).

When I do C-x C-f for find-file and delete all the way of the given path. Now, I keep seeing Text is read-only warning message in the minibuffer.

Is it possible to prevent this warning message and let minibuffer remain as Find file: text?


Find file: /home/alper/foder/  ;; Pressing C-h to remove all characters
Find file:
           ^ Here when I press C-h one last time

I am seeing Text is read-only.

6
  • 3
    I think I just do C-a C-k to go to the beginning of the file name, and then to delete all of it. But, your experience will depend on whether you use any of the common completion helpers (s.a. Ido or Helm), because they handle this situation differently.
    – wvxvw
    Jul 4 at 14:33
  • In naitive bash, in some cases I get used to do C-h and bash shell remains as it is. I actuall use ido-find-file which has the same issue.
    – alper
    Jul 4 at 14:44
  • The question (apparently) has nothing particular to do with C-x C-f. It's about deleting minibuffer input without trying to also delete some of the minibuffer prompt (which is read-only).
    – Drew
    Jul 4 at 17:12
  • @Drew In minibuffer, could we suppress that warning message?
    – alper
    Jul 4 at 18:01
  • For me, C-h doesn't do anything in Ido mode. I understand that this was supposed to be the "select all" action, right? As in, C-x h? In which case, again, Ido doesn't do anything. In Ido, Backspace removes one path fragment, pressing it a few times will delete the whole path. Alternatively, you may press C-f again to escape Ido completion entirely.
    – wvxvw
    Jul 4 at 20:52
3

You can bind the following function backward-delete-char-stop-at-read-only to the key of your choice (maybe C-h, but that binding overrides the default help key-binding). The function is essentially backward-delete-char but stops before deleting read-only text. No indication is given if the function is ineffective (as you want it).

(defun backward-delete-char-stop-at-read-only (n &optional killflag)
  "Do as `backward-delete-char' but stop at read-only text."
  (interactive "p\nP")
  (unless (or (get-text-property (point) 'read-only)
          (eq (point) (point-min))
          (get-text-property (1- (point)) 'read-only))
    (setq n (min (- (point) (point-min)) n))
    (setq n (- (point) (previous-single-property-change (point) 'read-only nil (- (point) n))))
    (backward-delete-char n killflag)))

You can bind that function to C-h in the minibuffer by the following form:

(define-key minibuffer-local-map (kbd "C-h") #'backward-delete-char-stop-at-read-only)
12
  • This is smart, but I was not able to make it work during ido-find-file. The way I set binding is: (global-set-key (kbd "C-h") 'backward-delete-char-stop-at-read-only)
    – alper
    Jul 5 at 12:24
  • Your solution brings another question. // Can we also stops before deleting / character? (Find file (./): ~/.emacs.d/ C-h won't remove / and stops ). I was trying to act in find-file most like I was in a shell, where I can only remove the entered characters.
    – alper
    Jul 5 at 12:34
  • @alper I appended an instruction how to define the key binding.
    – Tobias
    Jul 5 at 19:26
  • I have added your updated solution but still I am seeing Text is read-onlyin ido-search :( I am having same issue in using emacs -Q too
    – alper
    Jul 6 at 14:57
  • @alper It works for me with GNU Emacs 27.1.90 and option -Q. I copy the code inclusive the binding definition from the answer into the scratch buffer, evaluate it there and call M-x ido-find-file. There are no warnings anymore when point bumps into the read-only text while using C-h repeatedly.
    – Tobias
    Jul 6 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.