直到昨天,重新启动 emacs 会自动识别 .org 文件并在查看 .org 缓冲区时切换到 org 模式。现在我必须在每个文件上调用 M-x 组织模式。最初,每个 .org 模式现在都处于“基本”模式。
我的 ~/.emacs 文件包含:
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) ; not needed since Emacs 22.2
(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(put 'downcase-region 'disabled nil)
我在 Gnome Ubuntu 12.04 LTS 下运行 emacs 23.3.1。
不知道emacs是不是12.04刚更新的,之前确实不小心运行了xemacs。
我的 ~/.emacs 文件中的其他 org-mode 相关行,看起来换行符没有保留在堆栈溢出中,所以我将省略它们。
我想我明白了。我使用桌面保存。我认为 xemacs 在基本模式下使用桌面保存(当我退出时)保存了所有 org 文件(因为我没有在 xemacs 中设置 org-mode - 我真的应该卸载它)。在我的 .emacs-desktop 文件中,org 文件以“基本”模式列出。
删除的 .emacs-desktop 文件在某些 org 文件中打开 org-mode 后运行 M-x desktop-save。我打开 org-mode 的那些 .org 文件在 org-mode 中用 emacs 打开,而那些我没有访问和激活 org-mode 的文件在我重新启动 emacs 时保持基本模式。
有没有办法在缓冲区列表中选择多个文件并同时更改它们的模式?
要更改多个缓冲区的模式,请在
dolist
上使用 (buffer-list)
进行迭代,可能首先使用 cl-remove-if-not
过滤该列表。对于每次迭代,使用 with-current-buffer
和缓冲区名称,然后调用模式函数(例如 (org-mode 1)
):
(100% 未经测试。)
(defun org-them ()
"Put BUFFERS in Org mode."
(interactive)
(dolist (buf (cl-remove-if-not #'SOME-TEST (buffer-list)))
(with-current-buffer buf
(org-mode 1))))
例如,SOME-TEST 可能要求最后修改日期比某个截止日期更近。或者您可能只对文件缓冲区感兴趣——例如
buffer-file-name
与正则表达式匹配的缓冲区,例如 \\.org\'
.
我的情况也有类似的经历,现在我可以使用以下功能解决它:
(defun my/switch-opened-org-files-to-org-mode ()
"Switch all open buffers that end with .org to org-mode, skipping buffers that are already in org-mode."
(interactive)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (and (buffer-file-name)
(string= (file-name-extension (buffer-file-name)) "org")
(not (eq major-mode 'org-mode)))
(org-mode)
(message "Switched %s to org-mode." (buffer-name))))))