Libs
Links
.emacs
;; setq and setq-default
(setq inhibit-startup-message t
mark-ring-max 256)
(setq-default transient-mark-mode t)
;;; Fancy ` and @ stuff
(setq-default ac-sources `(,@ac-sources ac-source-words-in-all-buffer))
;; Lists
(length "Hello, World")
(add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode))
;; Tests
(null value)
(not value)
(boundp 'declare-function)
(fboundp 'menu-bar-mode)
(file-readable-p custom-file)
(file-exists-p custom-file)
(numberp 12)
;; Conditionals
(unless (eolp) (end-of-line))
(when window-system (require 'hexrgb))
;; Loops
(dolist (f ck-delete-frame-functions)
(when (fboundp f) (funcall f)))
;; defmacro
(defmacro declare-function (fn file &optional arglist fileonly) nil)
;; defun, declare
(declare ck-set-gui-font (font-name &rest fallback-fonts)) ;; recursive call via apply needs this symbol defined.
(defun ck-first-non-empty (&rest values)
"Returns the first non-empty param."
(setq result nil
rest values)
(while (and (not-null rest)
(or (null result) (string= result "")))
(setq result (car rest)
rest (cdr rest)))
result)
;; Compound statements
(progn (setq a 1) (setq b 2))
;; Functions
(autoload 'markdown-mode "markdown-mode.el"
"Major mode for editing Markdown files" t)
(expand-file-name "~chirayu")
(load-file custom-file)
(pymacs-call "ck.refs.default_environment_facade.browse_url" url)
(setenv "PATH" (concat "/opt/local/bin:" (getenv "PATH")))
;; Hooks
(add-hook 'auto-save-hook (lambda () (desktop-save-in-desktop-dir)))
;; Keys
(define-key global-map "(" 'skeleton-pair-insert-maybe)
(global-set-key "\M-p" 'ck-vim-map)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key [delete] 'delete-char)
;; Available keys:
;; M-p M-c M-t / C-t M-u M-i
;; C-<digit>
;; My keymaps
;; Vim-ish keymap
(define-prefix-command 'ck-vim-map)
(global-set-key "\M-p" 'ck-vim-map)
(define-key ck-vim-map "l" 'lazy-search-menu)
;; Ignoring errors / exceptions
(ignore-errors (require 'color-theme))
;; Exception handling
;; Use `condition-case' because if `mb-depth.el' can't be found,
;; then `mb-depth+.el' is not provided.
(condition-case
nil (require 'mb-depth+ nil t)
(error nil))
(condition-case exception (progn
(set-default-font font-name)
(set-frame-font font-name)
(setq default-frame-alist (append default-frame-alist `((font . ,font-name)))))
('error (if fallback-fonts
(apply 'ck-set-gui-font fallback-fonts))))
;; Misc
(put 'narrow-to-region 'disabled nil)
(fset 'yes-or-no-p 'y-or-n-p) ;replace y-e-s by y
(when window-system
(mwheel-install) ;; enable wheelmouse support by default
(set-selection-coding-system 'compound-text-with-extensions)) ;; use extended compound-text coding for X clipboard
(make-variable-buffer-local 'completion-popup-frame-parent-frame)
;; keywords
;; let
(let* ((a 1) (b 2)) (message "hello"))
;; funcall
;; message, error
;; defmacro
;; defvar, defcustom, defgroup,
;; save-excursion
(defconst ediff-ignore-similar-regions t)
;; Lists / Arrays / etc.
;; elt - access an element of a list.
(elt list-variable index)
;; Append
(setq default-frame-alist (append default-frame-alist `((font . ,font-name)))))
;; Test OS - windows / os x, etc.
(defvar mswindows-p (string-match "windows" (symbol-name system-type)))
(defvar macosx-p (string-match "darwin" (symbol-name system-type)))
(if mswindows-p
(progn
;; Windows Execute from dired
(define-key dired-mode-map "w"
(function
(lambda ()
(interactive)
(setq w32-shellex-no-dired-hook t)
(require 'w32-shellex)
(w32-shellex-dired-on-objects))))
(if macosx-p
(progn
;; Custom code to open browser on Mac OS X
(setq browse-url-browser-function
'(lambda (url &optional new-win)
(do-applescript (concat "open location \""
url "\""))))))
Sample code
;; From http://cl-cookbook.sourceforge.net/.emacs
(defun remove-balanced-comments ()
"Remove a set of Common Lisp balanced comments enclosing point."
(interactive "*")
(save-excursion
(when (search-backward "#|" nil t)
(delete-char 2)
(while (and (< (point) (point-max)) (not (looking-at " *|#")))
(forward-sexp))
(replace-match ""))))
(defadvice fi:indent-sexp (around indent-defun ())
"Indent the enclosing defun (or top-level sexp)."
(interactive)
(save-excursion
(beginning-of-defun)
ad-do-it))
(ad-activate 'fi:indent-sexp)
(defun insert-balanced-comments (arg)
"Insert a set of Common Lisp balanced comments around the s-expression
containing point. If this command is invoked repeatedly (without any
other command occurring between invocations), the comment region
progressively moves outward over enclosing expressions."
(interactive "*p")
(save-excursion
(when (eq last-command this-command)
(when (search-backward "#|" nil t)
(save-excursion
(delete-char 2)
(while (and (< (point) (point-max)) (not (looking-at " *|#")))
(forward-sexp))
(replace-match ""))))
(while (> arg 0)
(backward-char 1)
(cond ((looking-at ")") (incf arg))
((looking-at "(") (decf arg))))
(insert "#|")
(forward-sexp)
(insert "|#")))