如何在没有回答确认的情况下杀死emacs中的缓冲区?

时间:2011-06-24 11:18:59

标签: emacs

如何在没有被质疑的情况下杀死emacs中的缓冲区。

5 个答案:

答案 0 :(得分:27)

除非已修改缓冲区,否则这将在不确认的情况下终止当前可见缓冲区。在最后一种情况下,您必须回答y / n。

(global-set-key [(control x) (k)] 'kill-this-buffer)

答案 1 :(得分:5)

我用这个

(defun volatile-kill-buffer ()
   "Kill current buffer unconditionally."
   (interactive)
   (let ((buffer-modified-p nil))
     (kill-buffer (current-buffer))))

(global-set-key (kbd "C-x k") 'volatile-kill-buffer)     ;; Unconditionally kill unmodified buffers.

除非经过修改,否则它会杀死缓冲区。

答案 2 :(得分:4)

好的,我已经在Emacs手册中做了一些讨论并找到了一个可行的解决方案(从Emacs 23.4.1开始)。它与Noufal的解决方案几乎相同:

(defun kill-this-buffer-volatile ()
    "Kill current buffer, even if it has been modified."
    (interactive)
    (set-buffer-modified-p nil)
    (kill-this-buffer))

我稍微重命名了这个函数,使其成为kill-this-buffer的近亲。

显然,EmacsWiki在http://www.emacswiki.org/emacs/KillBufferUnconditionally(2007年修改)上有一个关于此主题的页面,但代码只是Noufal的副本。

答案 3 :(得分:2)

我使用下面这段代码 - 与Noufal忽略被修改的缓冲区的解决方案不同,这将保存缓冲区然后将其删除。当你有多个子窗口显示时,它还会删除会产生差异的窗口 - 默认情况下它将删除窗口而不是切换到其他缓冲区。 (要方便地使用它,当然需要绑定一些键。)

;; Kill the current buffer immediatly, saving it if needed.
(defvar kill-save-buffer-delete-windows t
  "*Delete windows when `kill-save-buffer' is used.
If this is non-nil, then `kill-save-buffer' will also delete the corresponding
windows.  This is inverted by `kill-save-buffer' when called with a prefix.")
(defun kill-save-buffer (arg)
  "Save the current buffer (if needed) and then kill it.
Also, delete its windows according to `kill-save-buffer-delete-windows'.
A prefix argument ARG reverses this behavior."
  (interactive "P")
  (let ((del kill-save-buffer-delete-windows))
    (when arg (setq del (not del)))
    (when (and (buffer-file-name) (not (file-directory-p (buffer-file-name))))
      (save-buffer))
    (let ((buf (current-buffer)))
      (when del (delete-windows-on buf))
      (kill-buffer buf))))

答案 4 :(得分:0)

如果要将(kill-current-buffer)绑定到某个键,请使用(kill-this-buffer)而不是(kill-this-buffer)。请参阅(kill-current-buffer)

的文档
  

...

     

只能从菜单栏中可靠地调用此命令,   否则它可能会决定不做任何事。

init.el

  

...

     

这就像“ kill-this-buffer”,但不必调用   通过菜单栏,而无需注意菜单栏的框架。

所以我将以下内容放入我的(global-set-key (kbd "C-x k") 'kill-current-buffer)

  onSelectDate(event): void {
    this.selectedReport = new Report()
    this.selectedDate = formatDate(event, 'dd/MM/yyyy', 'en-US') // Try to convert here
  }

至少在emacs 26.1中有效。