Editing Emacs

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
There are a variety of settings that you can put into your '''.emacs''' configuration file that will make life easier when working with BRL-CAD sources.  Additionally, installing [http://cmake.org/gitweb?p=cmake.git;a=blob_plain;f=Docs/cmake-mode.el;hb=ab9824e1 cmake-mode.el] into your ~/.emacs.d/ directory will help with editing of build system files.
+
There are a variety of settings that you can put into your '''.emacs''' configuration file that can make life easier when working with the BRL-CAD sources.
  
 
<pre>
 
<pre>
Line 5: Line 5:
 
(c-set-offset 'case-label '+)
 
(c-set-offset 'case-label '+)
 
(c-set-offset 'statement-case-open '+)
 
(c-set-offset 'statement-case-open '+)
(c-set-offset 'innamespace 0)
 
(c-set-offset 'inline-open 0)
 
  
 
;; Support font-locking large files
 
;; Support font-locking large files
Line 13: Line 11:
 
(transient-mark-mode t)
 
(transient-mark-mode t)
 
(turn-on-font-lock)
 
(turn-on-font-lock)
 
; quell initialization warnings due to Local Variable block bug
 
(setq inhibit-startup-message t)
 
 
; Stop at the end of the file, not just add lines
 
(setq next-line-add-newlines nil)
 
 
; make sure goto labels can be placed on column 0
 
(setq c-label-minimum-indentation 0)
 
  
 
; display column numbers in addition to line numbers
 
; display column numbers in addition to line numbers
 
(set-variable 'column-number-mode t)
 
(set-variable 'column-number-mode t)
 
; to not read-only lock other people's cvs files (and not go into vc-mode)
 
(set-variable 'vc-handle-cvs nil)
 
  
 
;;;;;;;;;;;;;;;;
 
;;;;;;;;;;;;;;;;
Line 61: Line 47:
 
   (interactive)
 
   (interactive)
 
   (save-excursion
 
   (save-excursion
    (set-variable 'case-fold-search nil)
 
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward "\\([,(]\\)\\([^[:space:]\n,]\\)" nil t) (replace-match "\\1 \\2"))
+
     (while (re-search-forward ",\\([^[:space:]\n,]\\)" nil t) (replace-match ", \\1"))
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward "COMMA ', '" nil t) (replace-match "COMMA ','"))
+
     (while (search-forward "( " nil t) (replace-match "("))
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward "([ ]+" nil t) (replace-match "("))
+
     (while (search-forward " )" nil t) (replace-match ")"))
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward "[ ]+)" nil t) (replace-match ")"))
+
     (while (search-forward "if(" nil t) (replace-match "if ("))
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward ")[ ]+\\([a-zA-Z]\\)" nil t) (replace-match ") \\1"))
+
     (while (search-forward "for(" nil t) (replace-match "for ("))
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward "}[ ]*else[ ]*{" nil t) (replace-match "} else {"))
+
     (while (search-forward "while(" nil t) (replace-match "while ("))
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (search-forward "if[ ]*(" nil t) (replace-match "if ("))
+
     (while (search-forward "){" nil t) (replace-match ") {"))
    (goto-char (point-min))
 
    (while (search-forward "for[ ]*(" nil t) (replace-match "for ("))
 
    (goto-char (point-min))
 
    (while (search-forward "while[ ]*(" nil t) (replace-match "while ("))
 
    (goto-char (point-min))
 
    (while (search-forward ")[ ]*{" nil t) (replace-match ") {"))
 
    (goto-char (point-min))
 
    (while (re-search-forward ")[[:space:]]*{" nil t) (replace-match ") {"))
 
    (goto-char (point-min))
 
    (while (re-search-forward "
 
\\(};?\\)[ ]*
 
[
 
]+" nil t) (replace-match "
 
\\1
 
 
 
 
 
"))
 
 
     (goto-char (point-min))
 
     (goto-char (point-min))
     (while (re-search-forward "
+
     (while (re-search-forward ")[[:space:]]+{" nil t) (replace-match ") {"))
[ ]*
 
[
 
]+
 
" nil t) (replace-match "
 
 
 
 
 
"))
 
 
     (c-set-offset 'case-label '+)
 
     (c-set-offset 'case-label '+)
 
     (c-set-offset 'statement-case-open '+)
 
     (c-set-offset 'statement-case-open '+)
    (c-set-offset 'innamespace 0)
 
    (c-set-offset 'inline-open 0)
 
 
     (indent-region (point-min) (point-max) nil)
 
     (indent-region (point-min) (point-max) nil)
    ))
 
 
(defun ws2 ()
 
  "Removes embedded white space (particularly tabs)"
 
  (interactive)
 
  (save-excursion
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "\\([[:alnum:]_*(\[{@<>+#!\"'-]\\)[ ]* [ ]*\\([[:alnum:]_*(\[{@<>+#!\"'-][[:alnum:]_*(\[{@<>+#!\"'-]?\\)[ ]+" "\\1 \\2 "))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "\\([[:alnum:]_*(\[{@<>+#!\"'-]\\)[ ]* [ ]*\\([[:alnum:]_*(\[{@<>+#!\"'-]\\)" "\\1 \\2"))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "\\([[:alnum:]_*(\[{@<>+#!\"'-]\\)[ ]+ +[ ]*\\([[:alnum:]_*(\[{@<>+#!\"'-]\\)" "\\1 \\2"))
 
    ))
 
 
(defun ws3 ()
 
  "collapses multiple empty lines and ensures two after every global block"
 
  (interactive)
 
  (save-excursion
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "
 
\\(};?\\)[ ]*
 
[
 
]+" "
 
\\1
 
 
 
"))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "
 
[ ]*
 
[
 
]+
 
" "
 
 
 
"))
 
    ))
 
 
(defun embrace ()
 
  "fix else statements and braces to be K&R style"
 
  (interactive)
 
  (save-excursion
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "}[[:space:]]*
 
[[:space:]]+else" "} else"))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "[[:space:]]*
 
[[:space:]]+{" " {"))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "[[:space:]]*\\(/\\*.*\\*/\\)[[:space:]]*{
 
\\([[:space:]]+\\)" " {
 
\\2\\1
 
\\2"))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "[[:space:]]*\\(/\\*.*\\*/\\)[[:space:]]*
 
\\([[:space:]]+\\){" " {
 
\\2\\1"))
 
    (goto-char (point-min))
 
    (while (query-replace-regexp "[[:space:]]*{[[:space:]]*\\(/\\*.*\\*/\\)[[:space:]]*
 
\\([[:space:]]+\\)" " {
 
\\2\\1
 
\\2"))
 
 
     ))
 
     ))
  
 
; custom bindings to support our style idiosyncrasies
 
; custom bindings to support our style idiosyncrasies
 
(global-set-key "\M-0" 'ws)
 
(global-set-key "\M-0" 'ws)
(global-set-key "\M-9" 'ws2)
 
(global-set-key "\M-8" 'embrace)
 
(global-set-key "\M-7" 'ws3)
 
 
</pre>
 
 
If you install the aforementioned cmake-mode, you'll need these extra lines in your .emacs file in order to enable the mode:
 
 
<pre>
 
(add-to-list 'load-path "~/.emacs.d")
 
 
(require 'cmake-mode)
 
(setq auto-mode-alist
 
      (append '(("CMakeLists\\.txt\\'" . cmake-mode)
 
                ("\\.cmake\\'" . cmake-mode))
 
              auto-mode-alist))
 
 
</pre>
 
</pre>

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)