While there is some interest in cmake-mode.el I have another useful thing to share.<br><br>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.<br>
<br>I've found a couple of solutions to this problem.<br><br>1. Use uniquify emacs package. This gives several options to automatically rename buffers based on their location on disk.<br><br><span style="font-family: courier new,monospace;">;; uniquify.el is a helper routine to help give buffer names a better unique name.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">(when (load "uniquify" 'NOERROR)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (require 'uniquify)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq uniquify-buffer-name-style 'forward)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;(setq uniquify-buffer-name-style 'post-forward)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br>2. Rename the buffer as part of the cmake-mode<br><br><span style="font-family: courier new,monospace;">(defun cmake-rename-buffer ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> "Renames a CMakeLists.txt buffer to cmake-<directory name>."</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (interactive)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ;(print (concat "buffer-filename = " (buffer-file-name)))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;(print (concat "buffer-name = " (buffer-name)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (when (and (buffer-file-name) (string-match "CMakeLists.txt" (buffer-name)))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;(setq file-name (file-name-nondirectory (buffer-file-name)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq parent-dir (file-name-nondirectory (directory-file-name (file-name-directory (buffer-file-name)))))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;(print (concat "parent-dir = " parent-dir))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq new-buffer-name (concat "cmake-" parent-dir))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;(print (concat "new-buffer-name= " new-buffer-name))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (rename-buffer new-buffer-name t)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(add-hook 'cmake-mode-hook (function cmake-rename-buffer))</span><br style="font-family: courier new,monospace;">
<br>I actually prefer renaming my buffers with my cmake-rename-buffer function, because the buffer names start with a lower case letter. ;)<br><br>I added this to the wiki:<br><a href="http://www.vtk.org/Wiki/CMake_Editors_Support#CMake_Editor_Modes">http://www.vtk.org/Wiki/CMake_Editors_Support#CMake_Editor_Modes</a><br>
<br>James<br>