Dino's .emacs file
[I'm going to try to keep this up to date, because I periodically change tweak and improve flymake setup... Latest is 15 April 2008]
This includes all my setup for C# development, including yasnippet, hideshow, flymake, htmlize, defaultcontent, timestamp, csharp-mode, and so on. The flymake is pulled out, you can find it here.
;;
;; Dino's .emacs setup file.
;; Time-stamp: <Tuesday, April 15, 2008 17:59:13 (by dinoch)>
;;
;; Works with v22.2 of emacs.
;;
;; total re-organization April 2008.
;; use byte-compile-file to compile this file into emacs.elc.
;;
;;
(message "Running emacs.el...")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; directory to load additional libraries from :
; This dir contains:
; yasnippet.el defaultcontent.el, csharp-mode.el,
; powershell-mode.el, powershell.el, htmlize.el
; javascript.el
(setq load-path
(append '("c:/users/dinoch/elisp") load-path ))
; csense is junk
;(setq load-path
; (append '("c:/users/dinoch/elisp/csense") load-path ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Global settings
;
(global-set-key "\C-xw" 'dino-fixup-linefeeds)
(global-set-key "\C-c1" 'just-one-space)
(global-set-key "\C-cw" 'where-is)
(global-set-key "\M-\C-^" 'describe-variable)
(global-set-key "\C-^" 'describe-key-briefly)
(global-set-key "\C-xd" 'delete-window)
(global-set-key "\C-x\C-d" 'delete-window)
(global-set-key "\C-x\C-r" 'dino-resize-big)
(global-set-key "\C-xx" 'copy-to-register)
(global-set-key "\C-xg" 'insert-register)
(global-set-key "\C-xp" 'previous-window)
(global-set-key "\C-x\C-p" 'previous-window)
(global-set-key "\C-xn" 'other-window)
(global-set-key "\C-x\C-e" 'compile)
(global-set-key "\C-x\C-g" 'auto-fill-mode)
(global-set-key "\C-x\C-n" 'next-error)
(global-set-key "\C-xt" 'toggle-truncation)
(global-set-key "\M-\C-y" 'yank-pop)
(global-set-key "\M-g" 'goto-line)
(global-set-key "\M- " 'set-mark-command)
(global-set-key "\M-\C-h" 'backward-kill-word)
(global-set-key "\C-c\C-c" 'center-paragraph) ; good for text mode
(global-set-key "\C-ck" 'global-set-key)
(global-set-key "\C-cs" 'search-forward-regexp)
(global-set-key "\C-cq" 'query-replace)
(global-set-key "\C-cc" 'goto-char)
(global-set-key "\C-cr" 'replace-regexp)
(global-set-key "\C-ct" 'dino-insert-timeofday)
(global-set-key "\C-c\C-t" 'dino-insert-timestamp)
(global-set-key "\C-cw" 'where-is)
(global-set-key "\C-c\C-w" 'compare-windows)
(global-set-key "\C-c!" 'revert-buffer-unconditionally)
;;the help key is assigned to Ctrl-\, or Esc-Ctrl-\
(global-set-key "\M-\C-\\" 'help-for-help)
(global-set-key "\C-\\" 'help-for-help)
; handle text end-of-line conventions the way it oughta be:
(setq inhibit-eol-conversion nil)
; turn on font-lock globally
(global-font-lock-mode 1 'ON)
(setq-default fill-column 72)
(setq auto-save-interval 500)
(setq case-fold-search nil)
; helpful for debugging lisp code:
(setq messages-buffer-max-lines 2500)
;; for fontification in emacs progmodes:
(load "font-lock")
(setq font-lock-maximum-decoration t)
(setq completion-auto-help nil)
(put 'eval-expression 'disabled nil)
; set truncation on side-by-side windows to nil.
(setq truncate-partial-width-windows nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Frames preferences: initial and default frames
;; see https://www.gnu.org/software/emacs/windows/big.html#windows-frames
(setq default-frame-alist
'(
(top . 10) (left . 860)
(width . 100) (height . 28)
(cursor-color . "Blue")
(cursor-type . box)
(foreground-color . "Black")
(background-color . "White")
(mouse-color . "sienna3")
(font . "-*-Lucida Console-normal-r-*-*-11-82-96-96-c-*-iso8859-1")
)
)
; initial frame is 128 wide x 72 high
(setq initial-frame-alist '(
(top . 40) (left . 10)
(width . 128) (height . 68)
)
)
;; what should a frame look like
(setq frame-title-format '("%f [mode: %m]" ) ; "filename [mode]" in title bar
icon-title-format '("emacs: %b")) ; "emacs: buffername" in icon
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; adjustment to mode mappings
;
; In the regexp's, the trailing \\' represents "end of string".
; The $ represents the zero-width place before newline.
; They are equivalent unless there is a filename with a new line in it.
;
(setq auto-mode-alist
(append '(
("\\.\\(war\\|ear\\|WAR\\|EAR\\)\\'" . archive-mode) ; java archives
("\\.s?html?\\'" . html-helper-mode)
("\\.asp$" . html-helper-mode)
("\\.aspx$" . html-helper-mode)
("\\.html$" . html-helper-mode)
("\\.htm$" . html-helper-mode)
("\\.md$" . emacs-lisp-mode) ; what the hell is an .md file?
("\\.el$" . emacs-lisp-mode)
("\\.js\\'" . javascript-mode)
("\\.txt$" . text-mode)
("\\.asmx$" . csharp-mode) ; maybe, could be any language tho
) auto-mode-alist ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; htmlize
(require 'htmlize)
(setq htmlize-output-type 'inline-css)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; yasnippet
;; grabbed 2008 april 11
;; see https://code.google.com/p/yasnippet/downloads/list
; you need to create a new yasnippet-bundle.el each time you add
; new snippets! see yasnippet-CreateBundle.el for the tool.
(require 'yasnippet-bundle)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; defaultcontent
;;
;; This package inserts "default content" into a new file of a given
;; type, when it is first edited in emacs.
;; See the elisp/defaultcontent directory for templates.
;;
(require 'defaultcontent)
;; specify the directory to look in for templates
(setq dc-auto-insert-directory "c:/users/dinoch/elisp/defaultcontent/")
(setq dc-fast-variable-handling t)
;; specify the template to use for .cs files:
(add-to-list 'dc-auto-insert-alist '("\\.cs$" . "template.cs" ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; configure external utilities
(setq archive-zip-use-pkzip nil) ;i.e. use unzip instead
(setq archive-zip-extract '("unzip" "-"))
(setq-default compile-command "nmake")
(setq-default grep-command "grep -i ")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; timestamp
;
; put this in a file in the first N lines to get an auto-updated timestamp:
; Time-stamp: <>
;
(setq
time-stamp-active t ; do enable time-stamps
time-stamp-line-limit 24 ; check first N buffer lines for Time-stamp: <>
time-stamp-format "%:a, %:b %02d, %04y %02H:%02M:%02S %Z (by %u)") ; date format
(add-hook 'before-save-hook 'time-stamp) ; update time stamps when saving
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Text mode
(add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; flymake-for-csharp
;
; tweaks to flymake.el for csharp.
;
(require 'flymake-for-csharp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (require 'csense-cs-frontend)
;; (setq csense-cs-source-files (csense-get-files-recursive "." ".+\\.cs$"))
;; (setq csense-cs-assembly-parser-program "c:\\users\\dinoch\\elisp\\csense\\netsense.exe")
;; (setq csense-cs-assemblies '("c:\\.net2.0\\System.dll" "c:\\.net2.0\\System.XML.dll" "c:\\.net2.0\\System.Data.dll"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; csharp mode
;
;; csharp mode was originally from Brad Merrill, bmerrill@microsoft.com
;; but then Dennis Haney (I think) <davh@davh.dk> updated it.
;; https://davh.dk/script/
;;
;; I then found what I think is a later version? better integrated with cc-modes.?
;; maintained by Dylan Moonfire. Most recently updated September 2007.
;; https://mfgames.com/linux/csharp-mode
;;
(require 'csharp-mode)
(require 'hideshow) ; builtin to emacs
;(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(c-add-style "C#"
'("Java"
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
(c-offsets-alist
. (
(access-label . -)
(arglist-close . c-lineup-arglist)
(arglist-cont . 0)
(arglist-cont-nonempty . c-lineup-arglist)
(arglist-intro . c-lineup-arglist-intro-after-paren)
(block-close . 0)
(block-open . 0)
(brace-entry-open . 0)
(brace-list-close . 0)
(brace-list-entry . 0)
(brace-list-intro . +)
(brace-list-open . +)
(c . c-lineup-C-comments)
(case-label . 0)
(catch-clause . 0)
(class-close . 0)
(class-open . 0)
(comment-intro . c-lineup-comment)
(cpp-macro . 0)
(cpp-macro-cont . c-lineup-dont-change)
(defun-block-intro . +)
(defun-close . 0)
(defun-open . 0)
(do-while-closure . 0)
(else-clause . 0)
(extern-lang-close . 0)
(extern-lang-open . 0)
(friend . 0)
(func-decl-cont . +)
(inclass . +)
(inexpr-class . +)
(inexpr-statement . 0)
(inextern-lang . +)
(inher-cont . c-lineup-multi-inher)
(inher-intro . +)
(inlambda . c-lineup-inexpr-block)
(inline-close . 0)
(inline-open . 0)
(innamespace . +)
(knr-argdecl . 0)
(knr-argdecl-intro . 5)
(label . 0)
(lambda-intro-cont . +)
(member-init-cont . c-lineup-multi-inher)
(member-init-intro . +)
(namespace-close . 0)
(namespace-open . 0)
(objc-method-args-cont . c-lineup-ObjC-method-args)
(objc-method-call-cont . c-lineup-ObjC-method-call)
(objc-method-intro . [0])
(statement . 0)
(statement-block-intro . +)
(statement-case-intro . +)
(statement-case-open . +)
(statement-cont . +)
(stream-op . c-lineup-streamop)
(string . c-lineup-dont-change)
(substatement . +)
(substatement-open . 0)
(template-args-cont c-lineup-template-args +)
(topmost-intro . 0)
(topmost-intro-cont . 0)
))
))
(c-add-style "myC#Style"
'("C#" ; this must be defined elsewhere
(c-basic-offset . 2)
(c-echo-syntactic-information-p . t)
(c-comment-only-line-offset . (0 . 0))
(c-offsets-alist . (
(c . c-lineup-C-comments)
(namespace-open . 0)
(namespace-close . 0)
(innamespace . +)
(class-open . 0)
(class-close . 0)
(inclass . +)
(block-open . -) ; eg, open a block under a function name or if stmt;
; want this to be flush with prev line.
(arglist-cont . +)
(substatement-open . 0) ; I think this is for a try {} or if{} or etc. why this is not block open, I don't know!
(defun-open . 0) ; method defn? (but no!)
(defun-block-intro . +) ;0 ; block within a function????
(inline-open . 0) ; eg, opening a function? ??
(statement-block-intro . +) ; unknown what this is
(brace-list-open . 0) ; list open (like an enum, array initializer)
(brace-list-intro . +) ; first item in the list
(brace-list-entry . 0) ; subsequent items in the list
(brace-list-close . 0) ; list close
(statement-cont . (dinoch-csharp-lineup-string-cont +)) ; align long strings
))
))
; this aligns long strings broken across multiple lines.
; need (statement-cont . (dinoch-csharp-lineup-string-cont +)) in the styles list
(defun dinoch-csharp-lineup-string-cont (langelem)
"Like `c-lineup-string-cont' but works with csharp string continuations."
(save-excursion
(back-to-indentation)
(and (looking-at "@?\\s\"")
(let ((quote (if (equal (char-after) ?@)
(char-after (1+ (point)))
(char-after)))
pos)
(while (and (progn (c-backward-syntactic-ws)
(when (eq (char-before) ?+)
(backward-char)
(c-backward-syntactic-ws))
(eq (char-before) quote))
(c-safe (c-backward-sexp) t)
;; uncomment this to lineup under the @
;;(progn (if (eq (char-before) ?@) (backward-char)) t)
(/= (setq pos (point)) (c-point 'boi))))
(when pos
(goto-char pos)
(vector (current-column)))))))
;(debug-on-entry 'hs-hide-level-recursive)
;; for hideshow.el
(defun csharp-hs-forward-sexp (&optional arg)
"I set hs-forward-sexp-func to this function.
I found this customization necessary to do the hide/show magic in C#
code, when dealing with region/endregion. This routine
goes forward one s-expression, whether it is defined by curly braces
or region/endregion. It handles nesting, too.
The forward-sexp method takes an arg which can be negative, which
indicates the move should be backward. Therefore, to be fully
correct this function should also handle a negative arg. However,
the hideshow.el package never uses negative args to its
hs-forward-sexp-func, so it doesn't matter that this function does not
do negative numbers.
The arg can also be greater than 1, which means go forward
multiple times. This function doesn't handle that EITHER. But
again, I haven't see that as a problem."
(let ((nestlevel 0)
(mark1 (point))
(done nil)
)
;(show-match-data)
(if (and arg (< arg 0))
;; a negative argument; we want to back up!
(message "negative arg (%d) is not supported..." arg)
;; else, we have a positive argument, hence move forward.
;; simple case is just move forward one brace
(if (looking-at "{")
(and
(forward-sexp arg)
)
; The more complex case is dealing with a "region/endregion" block.
; We have to deal with nested regions!
(and
(while (not done)
(re-search-forward "^[ \\t]*#[ \\t]*\\(region\\|endregion\\)\\b"
(point-max) 'move)
(cond
((eobp)) ; do nothing if at end of buffer
((and
(match-beginning 1)
;; if the match is longer than 6 chars, we know it is "endregion"
(if (> (- (match-end 1) (match-beginning 1)) 6)
(setq nestlevel (1- nestlevel))
(setq nestlevel (1+ nestlevel))
)
)))
(setq done (not (and (> nestlevel 0) (not (eobp)))))
) ; while
(if (= nest 0)
(goto-char (match-end 2)))
)
)
)
)
)
;; more for hideshow.el
(unless (assoc 'csharp-mode hs-special-modes-alist)
(push '(csharp-mode
; "\\(^\\s*#\\s*region\\b\\)\\|{" ; regexp for start block
"\\(^[ \\t]*#[ \\t]*region\\b\\)\\|{" ; regexp for start block
; "\\(^\\s*#\\s*endregion\\b\\)\\|}" ; regexp for end block
"\\(^[ \\t]*#[ \\t]*endregion\\b\\)\\|}" ; regexp for end block
"/[*/]" ; regexp for comment start
csharp-hs-forward-sexp ; hs-forward-sexp-func
hs-c-like-adjust-block-beginning ;c-like adjust (1 char)
;csharp-hs-adjust-block-beginning ;csharp adjust ?
)
hs-special-modes-alist))
(defun dino-csharp-mode-fn ()
(cond (window-system
(turn-on-font-lock)
(c-set-style "myC#Style")
(local-set-key "\M-\C-R" 'indent-region)
(local-set-key "\M-#" 'dino-indent-buffer)
(local-set-key "\M-s" 'dino-insert-csharp-gettersetter)
(local-set-key "\C-cp" 'dino-convert-csharp-field-to-property)
(local-set-key "\C-c\C-p" 'dino-convert-csharp-field-to-property)
; for skeleton stuff? do I need this now?
;(make-local-variable skeleton-pair)
(setq skeleton-pair t)
(local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "[") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
;; for snippets support:
(yas/minor-mode-on)
;; for flymake support:
(flymake-mode)
; for hide/show support
(hs-minor-mode 1)
(setq hs-isearch-open t)
; with point inside the block, use these keys to hide/show
(local-set-key "\C-c>" 'hs-hide-block)
(local-set-key "\C-c<" 'hs-show-block)
; autorevert.el is built-in to emacs; if files
; are changed outside of emacs, the buffer auto-reverts.
(turn-on-auto-revert-mode)
)))
(add-hook 'csharp-mode-hook 'dino-csharp-mode-fn)
;; to allow next-error to work with csc.exe:
(setq compilation-scroll-output t)
(setq-default compilation-error-regexp-alist
; (append
'(
; Microsoft VJC??:
;sample.java(6,1) : error J0020: Expected 'class' or 'interface'
("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)[,]\\([0-9]+\\)): \\(error\\|warning\\) VJS[0-9]+:" 1 3 4)
;; dinoch - Wed, 04 Aug 2004 09:29
;; handle whitespace at beginning of line (for nant output)
;;
;C# Compiler
;t.cs(6,18): error SC1006: Name of constructor must match name of class
;
("[ \t]*\\(\\([_a-zA-Z:\]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)[,]\\([0-9]+\\)): \\(error\\|warning\\) CS[0-9]+:" 1 3 4)
; Microsoft C/C++:
; keyboard.c(537) : warning C4005: 'min' : macro redefinition
; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
;VC EEi
;e:\projects\myce40\tok.h(85) : error C2236: unexpected 'class' '$S1'
;myc.cpp(14) : error C3149: 'class System::String' : illegal use of managed type 'String'; did you forget a '*'?
("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
: \\(error\\|warning\\) C[0-9]+:" 1 3)
)
; compilation-error-regexp-alist)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; XML mode
;;
(add-hook 'sgml-mode-hook (lambda () (turn-on-auto-revert-mode)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; elisp mode
;;
(defun dino-elisp-mode-fn ()
(local-set-key "\r" 'newline-and-indent)
(local-set-key "\C-c\C-c" 'comment-region)
(local-set-key "\M-\C-R" 'indent-region)
(local-set-key "\C-ce" 'eval-buffer)
(local-set-key "\C-c\C-e" 'eval-region)
(local-set-key "\C-x\C-e" 'byte-compile-file)
)
(add-hook 'emacs-lisp-mode-hook 'dino-elisp-mode-fn)
; This is for scratch buffer
(add-hook 'lisp-interaction-mode-hook 'dino-elisp-mode-fn)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; JavaScript
(autoload 'javascript-mode "javascript" nil t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Java
(defun dino-java-mode-hook ()
(c-set-style "myJavaStyle")
(font-lock-mode)
(local-set-key "\M-\C-R" 'indent-region)
)
(setq java-mode-hook 'dino-java-mode-hook)
(c-add-style "myJavaStyle"
'("Java" ; this must be defined elsewhere - it is in cc-modes.el
(c-basic-offset . 2)
(c-echo-syntactic-information-p . t)
(c-comment-only-line-offset . (0 . 0))
(c-offsets-alist . (
(c . c-lineup-C-comments)
(statement-case-open . 0)
(case-label . +)
(substatement-open . 0)
))
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; C Programming language
(defun dino-c-mode-hook ()
(c-set-style "myCStyle")
;for re-tabbing an entire region of code:
(local-set-key "\M-\C-R" 'indent-region)
; don't think I still need this!
;(set-backspace-keys-conditionally)
; turn off the c-indent-region thing; I don't like the indents it gives me!
; by using nil here, I get indent-according-to-mode, which is what works for me.
(setq indent-region-function nil)
(setq c-auto-newline nil)
;two comment procedures (see above)
; (local-set-key "\M-/" 'dino-start-c-comment)
; (local-set-key "\M-?" 'dino-end-c-comment)
)
(setq c-mode-hook 'dino-c-mode-hook)
(c-add-style "myCStyle"
'("bsd" ; this must be defined elsewhere - it is in cc-modes.el
(c-basic-offset . 2)
(c-echo-syntactic-information-p . t)
(c-comment-only-line-offset . (0 . 0))
(c-offsets-alist . (
(c . c-lineup-C-comments)
(statement-case-open . 0)
(case-label . +)
(substatement-open . 0)
))
))
(fset 'dino-start-c-comment "/* ")
(fset 'dino-end-c-comment " */")
(fset 'dino-end-block-comment
[escape ?\C-b escape ? ?\C-a ?\C-w ?\C-y escape ?\C-f ? ?/ ?/ ? ?\C-y ?\C-x ?\C-x ?\C-c ?1])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; perl mode
;
(defalias 'perl-mode 'cperl-mode)
(autoload 'perl-mode "c:/emacs/lisp/progmodes/cperl-mode" "" t)
;(autoload 'perl-mode "c:/emacs/lisp/progmodes/perl-mode" "" t)
;(setq
; cperl-comment-column 44) ; must these be set globally?
(defconst my-cperl-style
'( ("MyPerl"
(cperl-indent-level . 0)
(cperl-brace-offset . 2)
(cperl-continued-statement-offset . 2)
(cperl-continued-brace-offset . -2)
(cperl-label-offset . -2)
(cperl-close-paren-offset . -1))))
(defun cperl-mode-hook-fn ()
"My hook for perl"
(set-variable 'c-indent-level 0) ; required for c-outline
(turn-on-font-lock)
)
(add-hook 'cperl-mode-hook 'cperl-mode-hook-fn)
(make-local-variable 'cperl-style-alist)
(setq cperl-style-alist 'my-cperl-style)
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Powershell
(autoload 'powershell-mode "powershell-mode"
"Major mode for editing powershell code." t)
(setq auto-mode-alist (cons '( "\\.ps1\\'" . powershell-mode ) auto-mode-alist ))
(autoload 'powershell "powershell"
"Run powershell as a shell within emacs." t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; handy utility functions for various purposes
;
; when copying binary files into a clipboard buffer
(fset 'dinoch-b64-copy
[escape ? escape ?> escape ?x ?b ?a ?s ?e ?6 ?4 ?- ?e ?n ?c tab return ?\C-w ?\C-y])
; when pasting the base64 stuff from binary files
(fset 'dinoch-b64-paste
[escape ?x ?r backspace ?e ?r ?a ?s ?e ?- ?b ?u tab return ?\C-y escape ?x ?b ?a ?s ?e ?6 ?4 ?- ?d ?e ?c ?o tab return ?\C-x ?\C-s])
(defun dino-fixup-linefeeds ()
"Dino's function to replace the CR-LF of a DOS ASCII file to a LF for Unix."
(interactive)
(save-excursion
(while (search-forward "
" nil t)
(replace-match "
" nil t))
)
)
(defun dino-indent-buffer ()
"Dino's function to re-indent an entire buffer; helpful in progmodes like XML mode or csharp mode."
(interactive)
(indent-region (point-min) (point-max))
)
; put an href around the url at point.
(fset 'dino-href-url
[?< ? backspace ?a ? ?h ?r ?e ?f ?= ?\" ?\C-s ? ?\C-b ?\" ?> ?\C-r ?/ ?\C-f escape ? ?\C-s ?\" ?\C-b ?\C-w ?\C-y ?\C-f ?\C-f ?\C-y ?< ?/ ?a ?> ?< ?b ?r ?> return])
(defun revert-buffer-unconditionally ()
"revert the current buffer unconditionally,"
(interactive)
(revert-buffer t t)
)
(defun dino-resize-big ()
"quick resize to 128x72"
(interactive)
(set-frame-height (selected-frame) 72)
(set-frame-width (selected-frame) 128)
)
(defun dino-toggle-truncation ()
"Joe's function to toggle the state of the truncate-lines variable"
(interactive)
(setq truncate-lines (not truncate-lines))
(redraw-display)
)
(defun dino-remove-trailing-whitespace ()
"For each line in region, Convert multiple spaces at end of line to just one."
(interactive)
(let ((beg (point-min))
(end (point-max)))
(save-excursion
(goto-char beg)
(while (and (< (point) end)
(re-search-forward " +$" end t))
(just-one-space)
(backward-delete-char-untabify 1)
)
)))
(defun dino-insert-timestamp ()
"function to insert timestamp at point. format: DayOfWeek, Date Month Year 24hrTime"
(interactive)
(let (localstring mytime)
(setq localstring (current-time-string))
(setq mytime (concat "....dinoch...."
(substring localstring 0 3) ;day-of-week
", "
(substring localstring 8 10) ;day number
" "
(substring localstring 4 7) ;month
" "
(substring localstring 20 24 ) ;4-digit year
"...."
(substring localstring 11 16 ) ;24-hr time
"....\n"
))
(insert mytime))
)
(defun dino-insert-timeofday ()
"function to insert time of day at point . format: DayOfWeek, Date Month Year 24hrTime"
(interactive)
(let (localstring mytime)
(setq localstring (current-time-string))
; example:
; Mon, 17 Jun 96 12:52
(setq mytime (concat (substring localstring 0 3) ;day-of-week
", "
(substring localstring 8 10) ;day number
" "
(substring localstring 4 7) ;month
" "
(substring localstring 20 24 ) ;4-digit year
" "
(substring localstring 11 16 ) ;24-hr time
"\n"
))
(insert mytime))
)
; The following function (scarfed off an emacs bboard) will allow you to
; see what emacs is seeing when you press any key.
(defun dino-see-chars ()
"Displays characters typed, terminated by a 3-second timeout."
(interactive)
(let ((chars "")
(inhibit-quit t))
(message "Enter characters, terminated by 3-second timeout.")
(while (not (sit-for 3))
(setq chars (concat chars (list (read-char)))
quit-flag nil)) ; quit-flag maybe set by C-g
(message "Characters entered: %s" (key-description chars))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message "Done with emacs.el...")
Comments
Anonymous
April 14, 2008
Thank you for this great series. I'm looking forward to taking all this apart and figuring out how to reuse it all, both for C# and for F#. I'll also be trying it out with Mono on Linux, so I'll probably follow up with a post about how that goes.Anonymous
April 14, 2008
PingBack from http://microsoftnews.askpcdoc.com/?p=2337Anonymous
April 14, 2008
Some bits are interesting, adding some more to my 1500 lines .emacs. As you mentioned previously, it's impossible to work with other's emacs, I didn't like your bound keys :) Thanks.Anonymous
May 22, 2008
People have asked about this. This is the regular expression I use to allow emacs' next-error function