Sunday, September 21, 2014

Force kill buffer

Occasionally I want to kill a buffer without prompt even it is modified or related with a process.
 (defun kill-buffer-no-prompt (&optional BUFFER-OR-NAME)
   "Kill current buffer, even if it has been modified."
   (interactive)
   (let* ((buffer (if BUFFER-OR-NAME (get-buffer BUFFER-OR-NAME)
                    (window-buffer)))
          (process (get-buffer-process buffer)))
     (if process (delete-process process))
     (when buffer
       (switch-to-buffer buffer)
       (set-buffer-modified-p nil)
       (kill-buffer buffer))))

No comments: