Difference between revisions of "Emacs"

From BRL-CAD
(add some functions, style, and behavior setups)
 
(pre markers so [] display)
Line 1: Line 1:
 
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.
 
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>
 +
; indent case statements ala BSD KNF / K&R style regardless of mode
 +
(c-set-offset 'case-label '+)
 +
(c-set-offset 'statement-case-open '+)
  
; indent case statements ala BSD KNF / K&R style regardless of mode
+
;; Support font-locking large files
(c-set-offset 'case-label '+)
+
(set-variable 'font-lock-maximum-size 18024000)  
(c-set-offset 'statement-case-open '+)
+
(global-font-lock-mode t)
+
(transient-mark-mode t)
;; Support font-locking large files
+
(turn-on-font-lock)
(set-variable 'font-lock-maximum-size 18024000)  
 
(global-font-lock-mode t)
 
(transient-mark-mode t)
 
(turn-on-font-lock)
 
 
; display column numbers in addition to line numbers
 
(set-variable 'column-number-mode t)
 
  
;;;;;;;;;;;;;;;;
+
; display column numbers in addition to line numbers
; key bindings ;
+
(set-variable 'column-number-mode t)
;;;;;;;;;;;;;;;;
 
 
; so that M-TAB inserts a real tab while editing code
 
(global-set-key "� " (quote self-insert-command " "))
 
 
; bind "C-x g" to be M-x goto-line
 
(global-set-key "\C-xg" 'goto-line)
 
  
;;;;;;;;;;;;;
+
;;;;;;;;;;;;;;;;
; functions ;
+
; key bindings ;
;;;;;;;;;;;;;
+
;;;;;;;;;;;;;;;;
+
 
(defun dos-unix ()
+
; so that M-TAB inserts a real tab while editing code
  "Convert DOS CR-LF to UNIX NL"
+
(global-set-key "� " (quote self-insert-command " "))
  (interactive)
+
 
  (save-excursion
+
; bind "C-x g" to be M-x goto-line
    (goto-char (point-min))
+
(global-set-key "\C-xg" 'goto-line)
    (while (search-forward "\r" nil t) (replace-match ""))))
+
 
+
;;;;;;;;;;;;;
(defun unix-dos ()
+
; functions ;
  "Convert UNIX NL to DOS CR-LF"
+
;;;;;;;;;;;;;
  (interactive)
+
 
  (save-excursion
+
(defun dos-unix ()
    (goto-char (point-min))
+
  "Convert DOS CR-LF to UNIX NL"
    (while (search-forward "\n" nil t) (replace-match "\r\n"))))
+
  (interactive)
+
  (save-excursion
(defun ws ()
+
    (goto-char (point-min))
  "Make sure there is a space after every comma"
+
    (while (search-forward "\r" nil t) (replace-match ""))))
  (interactive)
+
 
  (save-excursion
+
(defun unix-dos ()
    (goto-char (point-min))
+
  "Convert UNIX NL to DOS CR-LF"
    (while (re-search-forward ",\\([^[:space:]\n,]\\)" nil t) (replace-match ", \\1"))
+
  (interactive)
    (goto-char (point-min))
+
  (save-excursion
    (while (search-forward "( " nil t) (replace-match "("))
+
    (goto-char (point-min))
    (goto-char (point-min))
+
    (while (search-forward "\n" nil t) (replace-match "\r\n"))))
    (while (search-forward " )" nil t) (replace-match ")"))
+
 
    (goto-char (point-min))
+
(defun ws ()
    (while (search-forward "if(" nil t) (replace-match "if ("))
+
  "Make sure there is a space after every comma"
    (goto-char (point-min))
+
  (interactive)
    (while (search-forward "for(" nil t) (replace-match "for ("))
+
  (save-excursion
    (goto-char (point-min))
+
    (goto-char (point-min))
    (while (search-forward "while(" nil t) (replace-match "while ("))
+
    (while (re-search-forward ",\\([^[:space:]\n,]\\)" nil t) (replace-match ", \\1"))
    (goto-char (point-min))
+
    (goto-char (point-min))
    (while (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 ")[[:space:]]+{" nil t) (replace-match ") {"))
+
    (while (search-forward " )" nil t) (replace-match ")"))
    (c-set-offset 'case-label '+)
+
    (goto-char (point-min))
    (c-set-offset 'statement-case-open '+)
+
    (while (search-forward "if(" nil t) (replace-match "if ("))
    (indent-region (point-min) (point-max) nil)
+
    (goto-char (point-min))
    ))
+
    (while (search-forward "for(" nil t) (replace-match "for ("))
+
    (goto-char (point-min))
; custom bindings to support our style idiosyncrasies
+
    (while (search-forward "while(" nil t) (replace-match "while ("))
(global-set-key "\M-0" 'ws)
+
    (goto-char (point-min))
 +
    (while (search-forward "){" nil t) (replace-match ") {"))
 +
    (goto-char (point-min))
 +
    (while (re-search-forward ")[[:space:]]+{" nil t) (replace-match ") {"))
 +
    (c-set-offset 'case-label '+)
 +
    (c-set-offset 'statement-case-open '+)
 +
    (indent-region (point-min) (point-max) nil)
 +
    ))
 +
 
 +
; custom bindings to support our style idiosyncrasies
 +
(global-set-key "\M-0" 'ws)
 +
</pre>

Revision as of 11:30, 2 April 2009

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.

; indent case statements ala BSD KNF / K&R style regardless of mode
(c-set-offset 'case-label '+)
(c-set-offset 'statement-case-open '+)

;; Support font-locking large files
(set-variable 'font-lock-maximum-size 18024000) 
(global-font-lock-mode t)
(transient-mark-mode t)
(turn-on-font-lock)

; display column numbers in addition to line numbers
(set-variable 'column-number-mode t)

;;;;;;;;;;;;;;;;
; key bindings ;
;;;;;;;;;;;;;;;;

; so that M-TAB inserts a real tab while editing code
(global-set-key "�	" (quote self-insert-command "	"))

; bind "C-x g" to be M-x goto-line
(global-set-key "\C-xg" 'goto-line)

;;;;;;;;;;;;;
; functions ;
;;;;;;;;;;;;;

(defun dos-unix ()
  "Convert DOS CR-LF to UNIX NL"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "\r" nil t) (replace-match ""))))

(defun unix-dos ()
  "Convert UNIX NL to DOS CR-LF"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "\n" nil t) (replace-match "\r\n"))))

(defun ws ()
  "Make sure there is a space after every comma"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward ",\\([^[:space:]\n,]\\)" nil t) (replace-match ", \\1"))
    (goto-char (point-min))
    (while (search-forward "( " nil t) (replace-match "("))
    (goto-char (point-min))
    (while (search-forward " )" nil t) (replace-match ")"))
    (goto-char (point-min))
    (while (search-forward "if(" nil t) (replace-match "if ("))
    (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 ") {"))
    (c-set-offset 'case-label '+)
    (c-set-offset 'statement-case-open '+)
    (indent-region (point-min) (point-max) nil)
    ))

; custom bindings to support our style idiosyncrasies
(global-set-key "\M-0" 'ws)