[CMake] More Emacs goodness (buffer names)
James Bigler
jamesbigler at gmail.com
Tue Apr 28 13:05:08 EDT 2009
While there is some interest in cmake-mode.el I have another useful thing to
share.
I've been long irritated with having to deal with multiple buffers all name
CMakeLists.txt. Emacs by default will call them CMakeLists.txt,
CMakeLists.txt<2>, CMakeLists.txt<3>, etc.. This is really hard to switch
back and forth when the buffer names are difficult to associate with
location.
I've found a couple of solutions to this problem.
1. Use uniquify emacs package. This gives several options to automatically
rename buffers based on their location on disk.
;; uniquify.el is a helper routine to help give buffer names a better unique
name.
(when (load "uniquify" 'NOERROR)
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;(setq uniquify-buffer-name-style 'post-forward)
)
2. Rename the buffer as part of the cmake-mode
(defun cmake-rename-buffer ()
"Renames a CMakeLists.txt buffer to cmake-<directory name>."
(interactive)
;(print (concat "buffer-filename = " (buffer-file-name)))
;(print (concat "buffer-name = " (buffer-name)))
(when (and (buffer-file-name) (string-match "CMakeLists.txt"
(buffer-name)))
;(setq file-name (file-name-nondirectory (buffer-file-name)))
(setq parent-dir (file-name-nondirectory (directory-file-name
(file-name-directory (buffer-file-name)))))
;(print (concat "parent-dir = " parent-dir))
(setq new-buffer-name (concat "cmake-" parent-dir))
;(print (concat "new-buffer-name= " new-buffer-name))
(rename-buffer new-buffer-name t)
)
)
(add-hook 'cmake-mode-hook (function cmake-rename-buffer))
I actually prefer renaming my buffers with my cmake-rename-buffer function,
because the buffer names start with a lower case letter. ;)
I added this to the wiki:
http://www.vtk.org/Wiki/CMake_Editors_Support#CMake_Editor_Modes
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090428/df644fec/attachment.htm>
More information about the CMake
mailing list