Reputation: 71
Until yesterday, restarting emacs would automatically recognize .org files and switch to org-mode when viewing a .org buffer. Now I have to invoke M-x org-mode on each file. Initially, each .org mode is now in "fundamental" mode.
My ~/.emacs file contains:
(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)
I am running emacs 23.3.1 under Gnome Ubuntu 12.04 LTS.
I don't know whether emacs just got an update in 12.04, but I did accidentally run xemacs just before.
Other org-mode related lines in my ~/.emacs file are, well it appears that the line breaks aren't preserved in stack-overflow so I will omit them.
I think I figured it out. I use desktop-save. I think xemacs saved all the org files with desktop-save (when I exited) in fundamental-mode (because I don't have org-mode set up in xemacs - I really should uninstall it). In my .emacs-desktop file the org files were listed with mode "fundamental".
Deleted .emacs-desktop file ran M-x desktop-save after turning on org-mode in some org files. Those .org files for which I turned org-mode on opened with emacs in org-mode, while those I did not visit and activate org-mode stayed in fundamental mode when I restarted emacs.
Is there a way to select multiple files in the buffer list and change their modes all at once?
Upvotes: 1
Views: 805
Reputation: 23
I had a similar experience with my situation, now I am able to resolve it by using the following function:
(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))))))
Upvotes: 0
Reputation: 30701
To change the modes of multiple buffers, iterate using dolist
over (buffer-list)
, possibly first filtering that list using, say, cl-remove-if-not
. For each iteration, use with-current-buffer
with the buffer name, and then call the mode function (e.g. (org-mode 1)
):
(100% untested.)
(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))))
For example, SOME-TEST could require the last modification date to be more recent than some cutoff. Or you might be interested only in file buffers --- e.g. buffers whose buffer-file-name
is matched by a regexp such as \\.org\'
.
Upvotes: 0