IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changes between Initial Version and Version 1 of Dot_Emacs_File


Ignore:
Timestamp:
Feb 24, 2009, 4:23:54 PM (17 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Dot_Emacs_File

    v1 v1  
     1The following .emacs excerpt was mostly provided by Robert Lupton.  The intent was to help coders comply with the IPP coding standards.
     2
     3 ;;
     4 ;; Support code for the Pan-STARRS C coding standards
     5 ;;
     6 ;; The basic tool is a "panstarrs-c" mode derived from c-mode.
     7 ;;
     8 ;; To activate, add:
     9 ;;   (add-to-list 'auto-mode-alist (cons "\\.[ch]$" 'panstarrs-c-mode))
     10 ;; to your .emacs file
     11 ;;
     12 ;; You might want to copy some of these add-hook lines to your .emacs file too:
     13 ;;  (add-hook 'panstarrs-c-mode-hook 'panstarrs-c99-comments)
     14 ;;  (add-hook 'panstarrs-c-mode-hook 'panstarrs-set-width)
     15 ;;  (add-hook 'panstarrs-c-mode-hook
     16 ;;          '(lambda ()
     17 ;;             (set (make-variable-buffer-local 'comment-indent-function)
     18 ;;                  'panstarrs-comment-indent)))
     19 ;; These respectively:
     20 ;;   use C99-style comments (i.e. // to end of line)
     21 ;;   have your emacs window set to 110 characters wide
     22 ;;   somewhat improve (or spoil?) the handling of re-indenting comments
     23 (define-derived-mode panstarrs-c-mode
     24   c-mode "Pan-STARRS C"
     25   "Major mode for editing Pan-STARRS C source.
     26           \\{panstarrs-c-mode-map}
     27 "
     28                                                                                 
     29   (let ( (our-mode-name mode-name) )
     30     (c-mode)                            ; get correct font-lock behaviour
     31     (setq mode-name our-mode-name))     ; keep our desired name
     32                                                                                 
     33   (setq c-default-style '((other . "k&r")))
     34   (setq c-basic-offset 4)
     35                                                                                 
     36   (setq comment-column 40)
     37   (setq fill-column 110)
     38                                                                                 
     39   (add-to-list 'c-offsets-alist (cons 'statement-case-intro 2))
     40   (add-to-list 'c-offsets-alist (cons 'statement-case-open 2))
     41   (add-to-list 'c-offsets-alist (cons 'case-label 2)))
     42 ;;
     43 ;; Various useful commands for writing panstarrs code
     44 ;;
     45 (defun panstarrs-c99-comments ()
     46   "Use C99-style // comments"
     47   (setq comment-start "// ")
     48   (setq comment-end ""))
     49 ;;
     50 (defun panstarrs-set-width ()
     51   "Set frame width to fill-column + 1 ( + 1 to allow for wrap column)"
     52   (set-frame-width default-minibuffer-frame (1+ fill-column)))
     53 ;;
     54 ;;
     55 (defun panstarrs-comment-indent (&optional delete)
     56   "Make ESC; indent new comments to comment-column even if previous line
     57 has a comment indented further to the right"
     58 
     59   (interactive "p")
     60   (let ( (indent (c-comment-indent)) )
     61     (if (> indent comment-column)
     62         (save-excursion
     63           (beginning-of-line)
     64           (if (not (looking-at (concat "^[ \t]*" comment-start)))
     65               (setq indent comment-column))))
     66     indent))
     67 ;; END support code for the Pan-STARRS C coding standards
     68 
     69 ;; Remove tabs from files, from http://www.jwz.org/doc/tabs-vs-spaces.html
     70 (defun panstarrs-mode-untabify ()
     71   (save-excursion
     72     (goto-char (point-min))
     73     (while (re-search-forward "[ \t]+$" nil t)
     74       (delete-region (match-beginning 0) (match-end 0)))
     75     (goto-char (point-min))
     76     (if (search-forward "\t" nil t)
     77        (untabify (1- (point)) (point-max))))
     78   nil)
     79 
     80 ;; Activate Pan-STARRS coding standard stuff.
     81 (add-to-list 'auto-mode-alist (cons "\\.[ch]$" 'panstarrs-c-mode))
     82 (add-hook 'panstarrs-c-mode-hook 'panstarrs-c99-comments)
     83 (add-hook 'panstarrs-c-mode-hook 'panstarrs-set-width)
     84 (add-hook 'panstarrs-c-mode-hook
     85          '(lambda ()
     86             (set (make-variable-buffer-local 'comment-indent-function)
     87                  'panstarrs-comment-indent)))
     88 (add-hook 'panstarrs-c-mode-hook
     89          '(lambda ()
     90             (make-local-variable 'write-contents-hooks)
     91             (add-hook 'write-contents-hooks 'panstarrs-mode-untabify)))
     92 
     93 ;; Untabify Perl code as well.
     94 (add-hook 'perl-mode-hook
     95          '(lambda ()
     96             (make-local-variable 'write-contents-hooks)
     97             (add-hook 'write-contents-hooks 'panstarrs-mode-untabify)))