带框架的新框架(文本模式) - 关闭,但没有雪茄。 。

时间:2013-04-26 06:15:55

标签: emacs elisp

以下代码仅在基本模式下生成新缓冲区,并且我无法弄清楚如何让新的临时缓冲区在文本模式下自动生成。 。 。任何帮助将不胜感激。

(setq initial-major-mode 'text-mode)

(defun new-frame-with-scratch ()
  "Open a new frame with scratch buffer selected"
  (interactive)
  (let ((frame (make-frame)))
    (select-frame-set-input-focus frame)
    (if (get-buffer-create "*lawlist*" )
        (switch-to-buffer "*lawlist*" 'norecord))))

2 个答案:

答案 0 :(得分:2)

您可以简单地删除(if (get-buffer-create "*lawlist*" ),因为switch-to-buffer将创建缓冲区(如果它尚不存在),如果它已创建缓冲区,则会调用set-buffer-major-mode。但请注意,initial-major-mode仅适用于名为*scratch*的缓冲区,您应该(setq-default major-mode 'text-mode)。更容易明确地调用所需的主模式,如Francesco提出的解决方案。

答案 1 :(得分:1)

initial-major-mode仅在创建初始*scratch*缓冲区时使用,因此我认为它对您没有帮助。您必须在新创建的*lawlist*缓冲区中显式更改模式:

(defun new-frame-with-scratch ()
  "Open a new frame with scratch buffer selected"
  (interactive)
  (let ((frame (make-frame))
        (scratch-name "*lawlist*"))
    (select-frame-set-input-focus frame)
    (unless (get-buffer scratch-name)
      (with-current-buffer (get-buffer-create scratch-name)
        (text-mode)))
    (switch-to-buffer scratch-name 'norecord)))

如果您想在每次调用*lawlist*时无条件地将text-mode缓冲区设置为new-frame-with-scratch,则可以简化逻辑。