Emacs

From BRL-CAD
Revision as of 10:30, 2 April 2009 by Sean (talk | contribs) (pre markers so [] display)

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)