0

When I delete the current buffer's file (in spacemacs via SPC f D, a prompt shows up in the minibuffer:

Are you sure you want to delete this file? (y or n)

I would find it safer if that warning displayed the file name / path:

Are you sure you want to delete /path/to/current/buffers/file ? (y or n)

What I do now is check whether the focus is really on the buffer of the file I want to delete but the prompt could allow another way of double checking.

How could one achieve this?

  • Sounds like you are suggesting an enhancement to Spacemacs. Maybe report that suggestion to the Spacemacs maintainers? Your question itself is unclear (to me): how could one achieve what? – Drew Feb 9 '18 at 16:12
1

Function spacemacs/delete-current-buffer-file is defined in spacemacs-base/funcs.el.

You can override it with the desired function. Note that I just changed the prompt of the yes-or-no-p question.

(defun my-spacemacs/delete-current-buffer-file ()
  "Removes file connected to current buffer and kills buffer."
  (interactive)
  (let ((filename (buffer-file-name))
        (buffer (current-buffer))
        (name (buffer-name)))
    (if (not (and filename (file-exists-p filename)))
        (ido-kill-buffer)
      (when (yes-or-no-p (format "Are you sure you want to delete %S? " filename))
        (delete-file filename t)
        (kill-buffer buffer)
        (when (and (configuration-layer/package-usedp 'projectile)
                   (projectile-project-p))
          (call-interactively #'projectile-invalidate-cache))
        (message "File '%s' successfully removed" filename)))))

(advice-add 'spacemacs/delete-current-buffer-file :override #'my-spacemacs/delete-current-buffer-file)

DISCLAIMER: I don't use spacemacs. The lisp code is currently untested. You need to test it for yourself.

Note further that there is also the very similar function spacemacs\delete-file. You can adopt the same changes to that function if you like.

As Drew suggested you should add an enhancement issue at the spacemacs project page.

  • Thank you, this is exactly what I was looking for. I tested the prompt and deletion and that works. Is the advice-add a general way to override functions? The alternative is to define the function in dotspacemacs/user-config which will override default spacemacs definitions. – user905686 Apr 19 '18 at 9:04
  • @user905686 Yes advising is the way to override functions. It has the advantage that it is reversible. If you need the original behavior you can use advice-remove. Furthermore, the original doc-string is retained and the documentation of the advising function is added. – Tobias Apr 19 '18 at 9:09

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.