Table of Contents
Customizing Emacs is difficult, but this task is needed — as a simple text editor isn't enough anymore for modern interactive development. That's why I'm sharing my config file, hoping it can help you getting what you want.
My Emacs init file is really huge, but very well commented. You should find lots of interesting things in it. It runs on Windows and Unix platforms, and it works well with both GNU Emacs and XEmacs. I keep on updating it quite frequently, so visit this page often!
Init File
If you do not already have an .emacs file, just download mine and put it in
your home directory:
cd ~
wget http://www.mygooglest.com/fni/.emacs
Make sure you modify the paths in the .emacs file so that they point to the
location of your files.
If you already have an .emacs file, you can look through mine to take parts
you could find useful for you.
Also, don't forget to keep learning, by subscribing to gnu.emacs.help and
comp.emacs. And check out the EmacsWiki as well.
;;; .emacs --- my Emacs Init File ;; Copyright (C) 1999-2008 Fabrice Niessen ;; Time-stamp: <Thu 2008-12-04 10:23 sva on mundaneum> ;; Author: Fabrice Niessen <(concat "fni" at-symbol "mygooglest.com")> ;; Keywords: emacs, dotfile, config ;; $Revision: 1925 $ ;; $Date: 2008-11-24 09:25:29 +0100 (Mon, 24 Nov 2008) $ ;; ;; ___ _ __ ___ __ _ ___ ___ ;; / _ \ '_ ` _ \ / _` |/ __/ __| ;; | __/ | | | | | (_| | (__\__ \ ;; (_)___|_| |_| |_|\__,_|\___|___/ ;; ;; This file is NOT part of GNU Emacs. ;; This file is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of ;; the License, or (at your option) any later version. ;; This file is distributed in the hope that it will be ;; useful, but WITHOUT ANY WARRANTY; without even the implied ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. See the GNU General Public License for more details. ;; You should have received a copy of the GNU General Public ;; License along with this file; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. ;;; Commentary: ;; "Show me your ~/.emacs and I will tell you who you are." ;; [Bogdan Maryniuk] ;; ;; "Emacs is like a laser guided missile. It only has to be slightly ;; mis-configured to ruin your whole day." ;; [Sean McGrath] ;; ;; "While any text editor can save your files, only Emacs can save your ;; soul." ;; [Per Abrahamsen] ;; ;; HOME variable ;; ;; Use `Z:' instead of `Z:\' for server to work under Windows (HOME ;; var). Otherwise, `~/emacs.d/server' gets translated by ;; `Z://emacs.d/server'!! ;; ;; Pre-Requisites ;; ;; You should use the `folding.el' package to see this file properly. ;; `folding.el' hides sections by folding them into a single line. ;; ;; Help ;; ;; For help on The Emacs Editor, see: ;; (info "(emacs)") ;; Place the cursor right after `)' and press `C-x C-e'. ;;; Code: ;; This file is only provided as an example. Customize it to your own taste! (message "{{{ --[ Loading my Emacs init file ]--") ;; uptimes (setq emacs-load-start-time (current-time)) ;; Identify what parts of your `.emacs' take so long. You can do ;; this e.g. by starting emacs with "emacs -q", set up your ;; load-path, and then evaluate ;; ;; (benchmark-run ;; (require 'package)) ;; ;; The first number appearing in the echo area will be the time needed to ;; run that command. ;; ;; Use autoloads, which delay the loading of the complete package ;; until one of the interactive functions is used. ;; ;; If you want to set options which need to be evaluated after a package is ;; loaded, you can use `eval-after-load'. ;; turn on Common Lisp support (require 'cl) ;;{{{ --[ Environment determination ]--------------------------------------- ;; OS type --- are we running Microsoft Windows? (defvar running-ms-windows (eq system-type 'windows-nt)) ;; Emacs type --- are we running XEmacs (or GNU Emacs)? (defvar running-xemacs (string-match "XEmacs" emacs-version)) (if running-xemacs ;; don't offer migration of the init file (setq load-home-init-file t)) ;;}}} ;;{{{ --[ Macros ]---------------------------------------------------------- (defmacro GNUEmacs (&rest body) "Execute any number of forms if running under GNU Emacs." (list 'if (not running-xemacs) (cons 'progn body))) (defmacro XEmacs (&rest body) "Execute any number of forms if running under XEmacs." (list 'if running-xemacs (cons 'progn body))) ;;}}} ;;{{{ --[ Loading Libraries of Lisp Code for Emacs ]------------------------ ;; make loaded files give a message (GNUEmacs (defadvice load (before debug-log activate) (message "Loading %s..." (locate-library (ad-get-arg 0))))) ;; load-path enhancement (defun my-add-to-load-path (this-directory &optional with-subdirs recursive) "Add THIS-DIRECTORY at the beginning of the load-path, if it exists. Add all its subdirectories not starting with a '.' if the optional argument WITH-SUBDIRS is not nil. Do it recursively if the third argument is not nil." (when this-directory (when (file-directory-p this-directory) (let* ((this-directory (expand-file-name this-directory)) (files (directory-files this-directory t "^[^\\.]"))) ;; completely canonicalize the directory name (*may not* begin with `~') (while (not (string= this-directory (expand-file-name this-directory))) (setq this-directory (expand-file-name this-directory))) (message "Adding `%s' to load-path..." this-directory) (add-to-list 'load-path this-directory) (if with-subdirs (progn (while files (setq dir-or-file (car files)) (when (file-directory-p dir-or-file) (if recursive (my-add-to-load-path dir-or-file 'with-subdirs) (my-add-to-load-path dir-or-file))) (setq files (cdr files))))))))) ;; `M-x list-load-path-shadows RET' ;;; ----[ Features ;; ;; REPLACES ORIGINAL in `C source code' (dumped) ;; ;; redefine require to leave a trace of packages being loaded ;; (if (not (fboundp 'orig-require)) ;; (fset 'orig-require (symbol-function 'require)) ;; (message "The code to redefine `require' should not be loaded twice")) ;; ;; (defvar my-require-depth 0) ;; ;; (defun require (feature &optional file) ;; "Leave a trace of packages being loaded." ;; (cond ((member feature features) ;; (message "%sRequiring `%s' (already loaded)" ;; (concat (make-string (* 2 my-require-depth) ?-) "> ") ;; feature) ;; (sit-for 0)) ;; (t ;; (message "%sRequiring `%s'" ;; (concat (make-string (* 2 my-require-depth) ?-) "> ") ;; feature) ;; (sit-for 0) ;; (let ((my-require-depth (+ 1 my-require-depth))) ;; (cond (file ;; (orig-require feature file)) ;; (t ;; (orig-require feature)))) ;; (message "%sRequiring `%s'...done" ;; (concat (make-string (* 2 my-require-depth) ?-) "> ") ;; feature) ;; (sit-for 0)))) (defvar missing-packages-list nil "List of packages that `try-require' can't find.") ;; attempt to load a feature/library, failing silently (defun try-require (feature) "Attempt to load a library or module. Return true if the library given as argument is successfully loaded. If not, instead of an error, just add the package to a list of missing packages." (condition-case err ;; protected form (progn (message "Checking for library `%s'..." feature) (if (stringp feature) (load-library feature) (require feature)) (message "Checking for library `%s'... Found" feature)) ;; error handler (file-error ; condition (progn (message "Checking for library `%s'... Missing" feature) (add-to-list 'missing-packages-list feature)) nil))) ;;; ----[ Library Search ;; The most important directories are the last! ;; 1. (defvar distro-site-lisp-directory (concat (or (getenv "SHARE") "/usr/share") "/emacs/site-lisp/") "Name of directory where additional Emacs goodies Lisp files (from the distro optional packages) reside.") (my-add-to-load-path distro-site-lisp-directory 'with-subdirs) ;; If you put stuff you have installed from tar balls, etc. within the same ;; directory hierarchy as the distro packaged Emacs, you can get problems ;; when upgrading the distro version as many package systems will assume ;; once all the packaged stuff is removed, directories are empty. If they ;; are not, the package management scripts can fail or possibly get into a ;; "confused" state. ;; 2. (defvar local-site-lisp-directory (concat (or (getenv "LOCAL_SHARE") "~/Media/Download") "/emacs/site-lisp/") "Name of directory where additional Emacs goodies Lisp files (from the Internet) reside.") (my-add-to-load-path local-site-lisp-directory 'with-subdirs 'recursive) ;; `local-site-lisp-directory' is there so that you have an easy way of ;; installing your own (possibly not distro packaged) Emacs add-ons which ;; are specific to the version of Emacs your running. This keeps your local ;; add-ons apart from distro supplied ones. If your have a `/usr/local' ;; partition, it also means you can do a complete re-install of Emacs (or ;; even your Linux distro) without impacting on stuff you have added by ;; hand. ;; 3. (defvar my-site-lisp-directory "~/emacs/site-lisp/" "Name of directory where my personal additional Emacs Lisp files reside.") (my-add-to-load-path my-site-lisp-directory 'with-subdirs) ;; 4. ;; automatically compile `.el' files as they're loaded (setq load-source-file-function 'load-with-code-conversion) ; for XEmacs (when (try-require 'byte-code-cache-XXX) (require 'bytecomp) ;; directory in which we store cached byte-compiled files (setq bcc-cache-directory ;; FIXME concat env var (so that it can be stored locally on C:) (if running-ms-windows "~/.emacs.d/byte-cache-ms-windows" "~/.emacs.d/byte-cache-linux")) (my-add-to-load-path bcc-cache-directory)) (defun my-make-directory-yes-or-no (dir) "Ask user to create the DIR, if it does not already exist." (if dir (if (not (file-directory-p dir)) (if (yes-or-no-p (concat "The directory `" dir "' does not exist currently. Create it? ")) (make-directory dir t) (error (concat "Cannot continue without directory `" dir "'")))) (error "my-make-directory-yes-or-no: missing operand"))) (defun my-file-executable-p (file) "Make sure the file FILE exists and is executable." (if file (if (file-executable-p file) file (message "Can't find `%s'" file) ;; sleep 3 s so that you can read the warning (sit-for 3)) (error "my-file-executable-p: missing operand"))) ;;}}} ;;{{{ --[ Debugging ]------------------------------------------------------- ;; 2008-05-23 set it to nil to temporarily avoid the broken vc functions ;; ;; get the backtrace when uncaught errors occur ;; (setq debug-on-error t) ; will be unset at the end (XEmacs (setq stack-trace-on-error t)) ;; ;; hit `C-g' while it's frozen to get an ELisp backtrace ;; (setq debug-on-quit t) ;;}}} ;; ## I m p o r t a n t G e n e r a l C o n c e p t s ################### ;;{{{ --[ 1 The Organization of the (info "(emacs)Screen") ]---------------- (message "1 The Organization of the Screen...") ;;; ----[ 1.2 The (info "(emacs)Echo Area") ;; don't truncate the message log buffer when it becomes large (setq message-log-max t) ;; the `*Messages*' buffer is called the ` *Message-Log*' on XEmacs (note ;; the initial space). To display the message log, execute the command ;; `show-message-log' (message "1 The Organization of the Screen... Done") ;;}}} ;;{{{ --[ 2 Kinds of (info "(emacs)User Input") ]--------------------------- (message "2 Kinds of User Input...") (message "2 Kinds of User Input... Done") ;;}}} ;;{{{ --[ 3 (info "(emacs)Keys") ]------------------------------------------ (message "3 Keys...") (message "3 Keys... Done") ;;}}} ;;{{{ --[ 4 Keys and (info "(emacs)Commands") ]----------------------------- (message "4 Keys and Commands...") (message "4 Keys and Commands... Done") ;;}}} ;;{{{ --[ 5 (info "(emacs)Text Characters") Set ]--------------------------- (message "5 Character Set for Text...") (message "5 Character Set for Text... Done") ;;}}} ;;{{{ --[ 6 (info "(emacs)Entering Emacs") and Exiting Emacs ]-------------- (message "6 Entering and Exiting Emacs...") (message "6 Entering and Exiting Emacs... Done") ;;}}} ;;{{{ --[ 7 (info "(emacs)Exiting") Emacs ]--------------------------------- (message "7 Exiting Emacs...") (message "7 Exiting Emacs... Done") ;;}}} ;; ## F u n d a m e n t a l E d i t i n g C o m m a n d s ############### ;;{{{ --[ 8 (info "(emacs)Basic") Editing Commands ]------------------------ (message "8 Basic Editing Commands...") ;;; ----[ 8.1 (info "(emacs)Inserting Text") ;; use decimal for `C-q' (setq read-quoted-char-radix 10) ;;; ----[ 8.2 (info "(emacs)Moving Point") Location ;; don't add newlines to end of buffer when scrolling (setq next-line-add-newlines nil) ;; XEmacs default for moving point to a given line number (GNUEmacs (global-set-key [(meta g)] 'goto-line)) (global-set-key [(meta shift g)] 'what-line) ;; point motion by screen lines (as opposed to text lines) (when (try-require 'screen-lines) ;; following lines commented out for keeping the original `kill-line' ;; in `screen-lines' minor mode (add-hook 'screen-lines-load-hook (lambda () (ad-disable-advice 'kill-line 'around 'screen-lines) (ad-activate 'kill-line))) ;; TODO screen lines mode enabled by default for all buffers ;; HOW? (Right now, it's done via `custom.el') ;; nothing should appear in the mode line, when the `screen-lines' mode ;; is enabled in a buffer (setq screen-lines-minor-mode-string "")) ;;; ----[ 8.4 (info "(emacs)Basic Undo")ing Changes ;; undo some previous changes (global-set-key [(f11)] 'undo) ;; redo the most recent undo (when (try-require 'redo) (global-set-key [(shift f11)] 'redo)) ;;; ----[ 8.8 (info "(emacs)Continuation Lines") ;; (setq default-truncate-lines nil) ;; (setq truncate-partial-width-windows nil) (defun my-wrap-mode-on () "Minor mode for making buffer not wrap long lines to next line." (interactive) (setq truncate-lines nil)) (defun my-wrap-mode-off () "Minor mode for making buffer wrap long lines to next line." (interactive) (setq truncate-lines t)) (defun my-toggle-wrap-mode () "Switch wrap mode from wrap to non-wrap, or vice-versa." (interactive) (if (eq truncate-lines nil) (my-wrap-mode-off) (my-wrap-mode-on))) ;;; ----[ 8.11 (info "(emacs)Repeating") a Command ;; repeat last command passed to `shell-command' (defun repeat-shell-command () "Repeat most recently executed shell command." (interactive) (save-buffer) (or shell-command-history (error "Nothing to repeat.")) (shell-command (car shell-command-history))) (global-set-key [(control c) (j)] 'repeat-shell-command) (message "8 Basic Editing Commands... Done") ;;}}} ;;{{{ --[ 9 The (info "(emacs)Minibuffer") ]-------------------------------- (message "9 The Minibuffer...") ;;; ----[ 9.1 (info "(emacs)Minibuffer File") Names ;; ignore case when reading a file name completion (setq read-file-name-completion-ignore-case t) ;; dim the ignored part of the file name (GNUEmacs (file-name-shadow-mode 1)) ;;; ----[ 9.2 (info "(emacs)Minibuffer Edit")ing ;; minibuffer window expands vertically as necessary to hold the text that ;; you put in the minibuffer (setq resize-mini-windows t) ;;; ----[ 9.3 (info "(emacs)Completion") ;; allow to type space chars in minibuffer input ;; (for `timeclock-in', for example) (define-key minibuffer-local-completion-map " " nil) (define-key minibuffer-local-must-match-map " " nil) ;; minibuffer completion incremental feedback (GNUEmacs (icomplete-mode)) ;; do not consider case significant in completion (GNU Emacs default) (setq completion-ignore-case t) ;;> I frequently find myself doing `C-M :' for some quick elisp calls, and ;;> find it tedious to type expressions. Is there some way to allow ;;> completion when writing a sexp in the minibuffer? I'd like this to work ;;> similar to the way `M-x' helps you complete some command. ;;;;;;(define-key read-expression-map (kbd "TAB") #'lisp-complete-symbol) (message "9 The Minibuffer... Done") ;;}}} ;;{{{ --[ 10 Running Commands by Name ]------------------------------------- (message "10 Running Commands by Name...") (message "10 Running Commands by Name... Done") ;;}}} ;;{{{ --[ 11 (info "(emacs)Help") ]----------------------------------------- (message "11 Help...") ;; `makewhatis' (in BSD) or `catman' create the database files that are used ;; by `apropos' or `man -k'. ;; You can read the instructions of a file by typing ;; `M-x finder-commentary RET file RET' ;; You might want to check out electric-help (ehelp.el). There is nothing ;; more satisfying than the window disappearing when you think it should! ;;; ----[ 11.4 (info "(emacs)Apropos") ;; You can ask what pertains to a given topic by typing ;; `M-x apropos RET pattern RET' ;; check all variables and non-interactive functions as well (setq apropos-do-all t) ;; add apropos help about variables (bind `C-h A' to `apropos-variable') (GNUEmacs (define-key help-map [(shift a)] 'apropos-variable)) ;;; ----[ 11.8 (info "(emacs)Misc Help") Commands ;; Info documentation browse (when (try-require 'info) ;; enter Info (global-set-key [(f1)] 'info) ;; list of directories to search for Info documentation files ;; (in the order they are listed) (if running-ms-windows (setq Info-directory-list (append Info-default-directory-list `(,(concat (getenv "SHARE") "/info/") "C:/cygwin/usr/info/"))) (setq Info-directory-list '("." "~/info" "/usr/local/share/emacs/23.0.0/lisp" "/usr/local/share/emacs/23.0.0/lisp/textmodes" "/usr/share/info/emacs-snapshot" "/usr/share/info/emacs-21" "/usr/share/info"))) ;; adding TexLive? ;; FIXME (append Info-default-directory-list '("~/Media/Download/emacs/site-lisp/auctex-11.85/doc")) ;; FIXME (append Info-default-directory-list '("~/Media/Download/emacs/site-lisp/emacs-w3m/doc")) ;; The canonical way to do that is to set the environment variable ;; `INFOPATH' outside of Emacs, in the same shell from which you invoke ;; Emacs. `INFOPATH's value should be a list of Info directories in the ;; same format as the `PATH' variable on your system. ;; The environment variable INFOPATH tells GNU Emacs where to look for info ;; files. ;; ;; If you want, you can edit the dir files and remove entries. The utility ;; install-info is used to maintain the dir file. ;; Don't play with `Info-directory-list', it's not intended to be settable ;; by the user ;; display symbol definitions, as found in the relevant manual ;; (for C, Lisp, and other languages that have documentation in Info) (global-set-key [(control f1)] 'info-lookup-symbol)) (GNUEmacs (try-require 'info+)) ;; with `info+.el', you can merge an Info node with its subnodes into ;; the same buffer, by calling `Info-merge-subnodes' (bound to `+') ;; dictem (dict protocol and dictem for a documentation) ;; describe-function ;; get a Unix manual page and put it in a buffer (global-set-key [(shift f1)] 'man-follow) ;; (defun jump-man-page () ;; (interactive) ;; (manual-entry (current-word))) ;; same behavior as woman when manpage is ready (setq Man-notify-method 'newframe) ;; (setq Man-frame-parameters '((foreground-color . "black") ;; (background-color . "grey90") ;; (cursor-color . "black") ;; (mouse-color . "gold") ;; (width . 80) ;; (tool-bar-lines . 0))) ;; browse Unix manual pages "W.o. (without) Man" (when (try-require 'woman) ;; list of directory trees to search for Unix manual files (setq woman-manpath (if running-ms-windows `(,(concat (getenv "SHARE") "/man/") "C:/cygwin/usr/man/" "C:/cygwin/usr/share/man" "C:/cygwin/usr/local/man") '("/usr/share/man/" "/usr/local/man/")))) ;;; ----[ Documentation Basics ;; jump to section in XEmacs Lisp Reference manual (autoload 'lispref-search "lispref") (define-key help-map [(shift l)] 'lispref-search) (message "11 Help... Done") ;;}}} ;; ## I m p o r t a n t T e x t - C h a n g i n g C o m m a n d s ####### ;;{{{ --[ 12 The (info "(emacs)Mark") and the Region ]---------------------- (message "12 The Mark and the Region...") ;;; ----[ 12.2 (info "(emacs)Transient Mark") Mode ;; when the mark is active, the region is highlighted (GNUEmacs (when window-system (transient-mark-mode 1))) (message "12 The Mark and the Region... Done") ;;}}} ;;{{{ --[ 13 (info "(emacs)Killing") and Moving Text ]---------------------- (message "13 Killing and Moving Text...") (message "13 Killing and Moving Text... Done") ;;}}} ;;{{{ --[ 14 (info "(emacs)Yanking") ]-------------------------------------- (message "14 Yanking...") ;;; ----[ 14.1 The (info "(emacs)Kill Ring") ;; auto-indent pasted code (defadvice yank (after indent-region activate) (if (member major-mode '(emacs-lisp-mode scheme-mode lisp-mode c-mode c++-mode objc-mode latex-mode plain-tex-mode python-mode)) (indent-region (region-beginning) (region-end) nil))) (defadvice yank-pop (after indent-region activate) (if (member major-mode '(emacs-lisp-mode scheme-mode lisp-mode c-mode c++-mode objc-mode latex-mode plain-tex-mode python-mode)) (indent-region (region-beginning) (region-end) nil))) ;;; ----[ 14.3 Yanking (info "(emacs)Earlier Kills") ;; interactively insert items from kill-ring (when (try-require 'browse-kill-ring) ;; string separating entries in the `separated' style (setq browse-kill-ring-separator "\n--separator------------------------------") ;; temporarily highlight the inserted `kill-ring' entry (setq browse-kill-ring-highlight-inserted-item t) ;; face in which to highlight the `browse-kill-ring-separator' (defface separator-face '((t (:foreground "Blueviolet" :bold t))) nil) ; slate gray (setq browse-kill-ring-separator-face 'separator-face) ;; use 'M-y' to invoke `browse-kill-ring' (browse-kill-ring-default-keybindings)) (message "14 Yanking... Done") ;;}}} ;;{{{ --[ 15 (info "(emacs)Accumulating Text") ]---------------------------- (message "15 Accumulating Text...") (message "15 Accumulating Text... Done") ;;}}} ;;{{{ --[ 16 (info "(emacs)Rectangles") ]----------------------------------- (message "16 Rectangles...") (message "16 Rectangles... Done") ;;}}} ;;{{{ --[ 17 (info "(emacs)CUA Bindings") ]--------------------------------- (message "17 CUA Bindings...") ;; CUA mode sets up key bindings used in many other applications (`C-x', ;; `C-c', `C-v' and `C-z'). ;; ;; The `C-x' and `C-c' keys only do cut and copy when the region is active, ;; so in most cases, they do not conflict with the normal function of these ;; prefix keys. ;; ;; If you really need to perform a command which starts with one of the ;; prefix keys even when the region is active, you have three options: ;; ;; - press the prefix key twice very quickly (within 0.2 seconds), press the ;; - prefix key and the following key within 0.2 seconds, or use the SHIFT ;; - key with the prefix key, i.e. `C-S-x' or `C-S-c'. ;; ;; You can customize `cua-enable-cua-keys' to completely disable the CUA ;; bindings, or `cua-prefix-override-inhibit-delay' to change the prefix ;; fallback behavior. ;; CUA mode also provides enhanced rectangle support with visible rectangle ;; highlighting. Check "Emacs Column Editing" out at ;; http://www.vimeo.com/1168225?pg=embed&sec=1168225. ;; ;; `C-RET' runs the command `cua-set-rectangle-mark' ;; `M-n' runs the command `cua-sequence-rectangle' ;; ;; activate CUA mode ;; (cua-mode t) ;; standard Windows behavior (setq cua-keep-region-after-copy t) ;; fix funny things of cursor moving commands (add-hook 'cua-mode-hook (lambda () (dolist (cmd '(forward-char backward-char previous-line next-line forward-paragraph backward-paragraph beginning-of-buffer end-of-buffer)) (put cmd 'CUA nil)))) (message "17 CUA Bindings... Done") ;;}}} ;;{{{ --[ 18 (info "(emacs)Registers") ]------------------------------------ (message "18 Registers...") ;;; ----[ 18.7 (info "(emacs)Bookmarks") ;; where to save the bookmarks (setq bookmark-default-file "~/.emacs.d/bookmarks.txt") ;; each command that sets a bookmark will also save your bookmarks (setq bookmark-save-flag 1) ;; repository should be restored when loading `bm' (setq bm-restore-repository-on-load t) (when (try-require 'bm) ;;; (global-set-key (kbd "<M-f2>") 'bm-toggle) ;;; (global-set-key (kbd "<f2>") 'bm-next) ;;; (global-set-key (kbd "<S-f2>") 'bm-previous) ;;; (global-set-key (kbd "<S-f2>") 'bm-toggle-buffer-persistence) ;;; (global-set-key [f5] 'bm-toggle-bookmark) ;;; (global-set-key [C-f5] 'bm-delete-all) ;;; (global-set-key [f6] 'bm-goto-bookmark) ;;; (global-set-key [C-f6] 'bm-goto-bookmark-previous) ;; buffer should be recentered around the bookmark (setq bm-recenter t) ;; make bookmarks persistent as default (setq-default bm-buffer-persistence t) ;; Loading the repository from file when on start up. (add-hook' after-init-hook 'bm-repository-load) ;; Restoring bookmarks when on file find. (add-hook 'find-file-hooks 'bm-buffer-restore) ;; Saving bookmark data on killing a buffer (add-hook 'kill-buffer-hook 'bm-buffer-save) ;; Saving the repository to file when on exit. ;; kill-buffer-hook is not called when emacs is killed, so we ;; must save all bookmarks first. (add-hook 'kill-emacs-hook '(lambda nil (bm-buffer-save-all) (bm-repository-save))) ;; Update bookmark repository when saving the file: (add-hook 'after-save-hook 'bm-buffer-save)) ;; ;; lists all bookmarks in all buffers ;; (try-require 'bm-ext) (message "18 Registers... Done") ;;}}} ;;{{{ --[ 19 Controlling the (info "(emacs)Display") ]---------------------- (message "19 Controlling the Display...") ;;; ----[ 19.1 (info "(emacs)Scrolling") ;; scroll line by line (setq scroll-step 1) ;; better scrolling in Emacs (doing a `Pg Up' followed by a `Pg Dn' will ;; place the point at the same place) (when (try-require 'pager) (global-set-key [(prior)] 'pager-page-up) (global-set-key [(next)] 'pager-page-down) (global-set-key [(meta up)] 'pager-row-up) (global-set-key [(meta down)] 'pager-row-down)) ;;; ----[ 19.7 (info "(emacs)Font Lock") ;; make buffer size irrelevant for fontification (setq font-lock-maximum-size nil) (XEmacs ;; stop showing that annoying progress bar when fontifying (setq progress-feedback-use-echo-area nil) ;; enable Font Lock mode (font-lock-mode)) ;; highlight non-breaking spaces (GNUEmacs (require 'disp-table) (aset standard-display-table (make-char 'latin-iso8859-1 (- ?\240 128)) (vector (+ ?\267 (* 524288 (face-id 'nobreak-space)))))) ;; highlight FIXME, TODO, XXX and BUG as warning in some major modes ;; adding keywords: missing, invalid, failed (GNUEmacs (dolist (mode '(c-mode shell-script-mode text-mode java-mode cperl-mode html-mode-hook css-mode-hook emacs-lisp-mode nuweb-mode latex-mode)) (font-lock-add-keywords mode '(("\\<\\(XXX\\|FIXME\\|TODO\\|[eE][rR][rR][oO][rR]\\|BUG\\)" 0 font-lock-warning-face t) ("\\<\\([wW][aA][rR][nN][iI][nN][gG]\\|[mM][iI][sS][sS][iI][nN][gG]\\|[iI][nN][vV][aA][lL][iI][dD]\\|[fF][aA][iI][lL][eE][dD]\\)" 0 font-lock-warning-face t))))) ;; ;;; to test... ;; (add-hook 'after-change-major-mode-hook ;; (lambda () ;; (font-lock-add-keywords nil ;; '(("error" . font-lock-warning-face))))) ;; WAS: (font-lock-add-keywords mode ;; '(("\\(XXX\\|FIXME\\|TODO\\|BUG\\)" ;; 1 font-lock-warning-face prepend))))) ;; `x-symbol' ;;; ----[ 19.8 (info "(emacs)Highlight Interactively") by Matching ;; You can use `hi-lock-mode' to highlight words: ;; `M-x hi-lock-mode RET' ;; `C-x w h <match> RET hi-blue RET' ;; You can also write your settings to the buffer you're using with ;; `C-x w b', and read them back in again next time with `C-x w i'. ;; minor mode for interactive automatic highlighting (when (try-require 'hi-lock) (when (boundp 'global-hi-lock-mode) (global-hi-lock-mode 1)) ;; bind the hi-lock commands to more finger-friendly sequences (define-key hi-lock-map [(control z) (control h)] 'highlight-lines-matching-regexp) (define-key hi-lock-map [(control z) (i)] 'hi-lock-find-patterns) (define-key hi-lock-map [(control z) (h)] 'highlight-regexp) (define-key hi-lock-map [(control z) (p)] 'highlight-phrase) (define-key hi-lock-map [(control z) (r)] 'unhighlight-regexp) (define-key hi-lock-map [(control z) (b)] 'hi-lock-write-interactive-patterns) ;; highlight errors and warnings (defun highlight-errors-and-warnings () "Highlight lines containing errors or warnings." (interactive) ;; (if (equal "log" (file-name-extension (buffer-file-name))) (progn ;;;; this is redundant with `font-lock-add-keywords' (in 19.7) ;;; (highlight-lines-matching-regexp "[wW][aA][rR][nN][iI][nN][gG]" ;;; 'compilation-warning) ;;; (highlight-lines-matching-regexp "[eE][rR][rR][oO][rR]" ;;; 'compilation-error) )) ;; ) (add-hook 'find-file-hook 'highlight-errors-and-warnings)) ;;; ----[ 19.11 (info "(emacs)Useless Whitespace") ;; highlight trailing whitespaces in all modes (setq-default show-trailing-whitespace t) ;; ;; highlight tabs ;; (when (try-require 'show-wspace) ;; (add-hook 'font-lock-mode-hook 'highlight-tabs)) ;; delete all the trailing whitespaces and tabs across the current buffer (defun my-delete-trailing-whitespaces-and-untabify () "Delete all the trailing white spaces, and convert all tabs to multiple spaces across the current buffer." (interactive "*") (delete-trailing-whitespace) (untabify (point-min) (point-max))) (global-set-key [(control c) (t)] 'my-delete-trailing-whitespaces-and-untabify) ;;; ----[ 19.13 (info "(emacs)Optional Mode Line") Features ;; show the line number in each mode line (line-number-mode 1) ;; show the column number in each mode line (column-number-mode 1) ;; use inactive face for mode-line in non-selected windows (setq mode-line-in-non-selected-windows t) ;; code for including abbreviated file paths in mode line (GNUEmacs (when (try-require 'mode-line) (mode-line-toggle-display nil))) ;;; ----[ 19.14 How (info "(emacs)Text Display")ed ;; convert a buffer from DOS ^M end of lines to Unix end of lines (defun dos-to-unix () "Cut all visible ^M from the current buffer." (interactive) (save-excursion (goto-char (point-min)) (while (search-forward "\r" nil t) (replace-match "")))) (global-set-key [(control c) (d)] 'dos-to-unix) ;; convert a buffer from Unix end of lines to DOS ^M end of lines (defun unix-to-dos () (interactive) (save-excursion (goto-char (point-min)) (while (search-forward "\n" nil t) (replace-match "\r\n")))) ;; Bad interaction with CVSNT/diff/... (not yet understood) ;; ;; Remove or convert trailing ^M ;; (defun remove-trailing-ctrl-M () ;; "Propose to remove trailing ^M from a file." ;; (interactive) ;; (save-excursion ;; (goto-char (point-min)) ;; (if (and (not (string-match ".gz$" (buffer-file-name))) ;; (search-forward-regexp "\015$" nil t)) ;; ;: a ^M is found ;; (if (or (= (preceding-char) ?\^J) ;; (= (following-char) ?\^J) ) ;; (if (y-or-n-p (format "Remove trailing ^M from %s? " ;; (buffer-file-name))) ;; (progn (goto-char (point-min)) ;; (perform-replace "\015" "" nil nil nil) ;; (pop-mark) ;; (save-buffer)) ;; (message "No transformation.")))))) ;; (add-hook 'find-file-hooks 'remove-trailing-ctrl-M) ;;; ----[ 19.15 The (info "(emacs)Cursor Display") (GNUEmacs ;; using cursor color to indicate some modes (read-only, insert and ;; overwrite modes) (setq my-set-cursor-color-color "") (setq my-set-cursor-color-buffer "") (defun my-set-cursor-color-according-to-mode () "Change cursor color according to some minor modes." (let ((color (if buffer-read-only "purple1" (if overwrite-mode "red" "rgb:15/FF/00")))) ;; insert mode (unless (and (string= color my-set-cursor-color-color) (string= (buffer-name) my-set-cursor-color-buffer)) (set-cursor-color (setq my-set-cursor-color-color color)) (setq my-set-cursor-color-buffer (buffer-name))))) (add-hook 'post-command-hook 'my-set-cursor-color-according-to-mode)) (when (try-require 'column-marker) ;; ;; highlight column 80 in foo mode ;; (add-hook foo-mode-hook ;; (lambda () ;; (interactive) ;; (column-marker-1 80))) ;; use `C-c m' interactively to highlight with `column-marker-1-face' (global-set-key [(control c) (m)] 'column-marker-1)) ;; ;; conflicts with the above! ;; (when (try-require 'wide-column) ;; (setq wide-column-start-width 60) ;; (setq wide-column-default-cursor-colour "rgb:15/FF/00")) ;; ;; (add-hook 'text-mode-hook 'wide-column-mode) ;;; ----[ 19.17 (info "(emacs)Display Custom")ization ;; see what I'm typing *immediately* (setq echo-keystrokes 0.01) ;;; ----[ Temporary Displays ;; make the help, apropos and completion windows the right height for their ;; contents (GNUEmacs (temp-buffer-resize-mode t)) ;; enhanced display of temporary windows (such as help buffers) ;; (try-require 'show-temp-buffer) [bug with XEmacs 21.5] (message "19 Controlling the Display... Done") ;;}}} ;;{{{ --[ 20 (info "(emacs)Search")ing and Replacement ]-------------------- (message "20 Searching and Replacement...") ;;; ----[ 20.1 (info "(emacs)Incremental Search") ;; always exit searches at the beginning of the expression found (add-hook 'isearch-mode-end-hook 'custom-goto-match-beginning) (defun custom-goto-match-beginning () "Use with isearch hook to end search at first char of match." (when isearch-forward (goto-char isearch-other-end))) ;;; ----[ 20.4 (info "(emacs)Regexp Search") ;; You can build regexps with visual feedback by using `M-x re-builder' ;; or `regex-tool' (http://www.newartisans.com/downloads_files/regex-tool.el) ;; Optimize regexps with `regexp-opt.el' ;; list the input line, followed by the first nine substrings matches, ;; to debug regexp searches (in IELM) ;; example: ELISP> (save-excursion (set-buffer "BUFFER") ;; (re-search-forward "REGEXP" nil t) ;; (my-buffer-matched-strings)) (defun my-buffer-matched-strings () (interactive) (mapcar 'my-buffer-matched-string-nth '(0 1 2 3 4 5 6 7 8 9))) (defun my-buffer-matched-string-nth (n) "Return the Nth pattern-matched string from the current buffer." (if (and (match-beginning n) (match-end n)) (if (> (match-end n) (match-beginning n)) (buffer-substring (match-beginning n) (match-end n)) "") nil)) ;;; ----[ 20.8 (info "(emacs)Search Case") ;; searches and matches should ignore case (setq default-case-fold-search t) ;;; ----[ 20.9 (info "(emacs)Replace")ment Commands ;; You can force a matched regex text pattern to upper case by entering ;; `C-M-% your_regexp RET \,(upcase \num_of_match)' ;;; ----[ 20.10 (info "(emacs)Other Repeating Search") Commands (defun isearch-occur () "Invoke `occur' from within isearch." (interactive) (let ((case-fold-search isearch-case-fold-search)) (occur (if isearch-regexp isearch-string (regexp-quote isearch-string))))) (define-key isearch-mode-map [(control o)] 'isearch-occur) ;; `M-x flush-lines' deletes each line that contains a match for REGEXP (message "20 Searching and Replacement... Done") ;;}}} ;;{{{ --[ 21 Commands for (info "(emacs)Fixit") Typos ]--------------------- (message "21 Commands for Fixing Typos...") ;;; ----[ 21.1 (info "(emacs)Undo") (GNUEmacs ;; keep no more undo information once it exceeds this size (setq undo-limit (* 4 undo-limit)) ; 4 * 20 MB (default) ;; don't keep more than this much size of undo information (setq undo-strong-limit (* 4 undo-strong-limit))) ; 4 * 30 MB (default) ;;; ----[ 21.5 Checking and Correcting (info "(emacs)Spelling") ;; aspell -H list Article.html ;; aspell -H check Article.html ;; Then hold your finger down on the `a' (add) or `l' (add lower case) key. ;; use GNU Aspell instead of (port of) `ispell' (setq ispell-program-name (if running-ms-windows "C:/Program Files/Aspell/bin/aspell.exe" "/usr/bin/aspell")) (my-file-executable-p ispell-program-name) (when (and ispell-program-name (file-executable-p ispell-program-name)) ;;;;;;;;;;; (require 'ispell) ;; already loaded!? ;; extra switches to pass to the `ispell' program (setq ispell-extra-args '("--sug-mode=ultra")) ; tell `aspell' to speed up, though this reduces somewhat the ; quality of its suggestions. ; According to the `aspell' documentation, "ultra" is the fastest ; suggestion mode, which is still twice as slow as `ispell'. ; If your machine is fast enough, a better option might be to try ; "fast" mode, which is twice as slow as "ultra", but more ; accurate. ; The "normal" mode, which is the `aspell' default, is even more ; accurate, but is reportedly 10 times slower than "fast" mode. ;; `aspell' extensions should be used (setq ispell-really-aspell t) ;; redefine the list of installed dictionaries ;; customize to ("-B" "-d" "spanish") or ("-C" "-d" "dutch") if aliases ;; are needed for the file names (setq ispell-dictionary-alist '( (nil ; default (English.aff) "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1) ("american" ; Yankee English "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1) ("castellano" ; Spanish mode "[A-Za-záéíóúüñÁÉÍÓÚÜÑ]" "[^A-Za-záéíóúüñÁÉÍÓÚÜÑ]" "[-]" nil ("-B") "~tex" iso-8859-1) ("francais" ; Francais.aff (ou "fr" ?) "[A-Za-zÀÂÇ-ËÎÏÔÙÛÜàâç-ëîïôùûü]" "[^A-Za-zÀÂÇ-ËÎÏÔÙÛÜàâç-ëîïôùûü]" "[-']" t nil "~list" iso-8859-1) ("francais-tex" "[A-Za-zÀÂÇ-ËÎÏÔÙÛÜàâç-ëîïôùûü\\]" "[^A-Za-zÀÂÇ-ËÎÏÔÙÛÜàâç-ëîïôùûü\\]" "[-'^`\"]" t nil "~tex" iso-8859-1) ("nederlands" ; Nederlands.aff "[A-Za-zÀÂÇ-ËÎÏÔÙÛÜàâç-ëîïôùûü]" "[^A-Za-zÀÂÇ-ËÎÏÔÙÛÜàâç-ëîïôùûü]" "[']" t ("-C") nil iso-8859-1))) ;; save the personal dictionary without confirmation (setq ispell-silently-savep t) ;; solve the problem of words separated by `-' flagged as erroneous ;; by removing the `-' from the value of otherchars (if (fboundp 'ispell-get-decoded-string) (defun ispell-get-otherchars () (replace-regexp-in-string "-" "" (ispell-get-decoded-string 3)))) ;; LaTeX-sensitive spell checking (setq ispell-enable-tex-parser t) ;; on-the-fly spelling checking (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checking" t) ;; `flyspell-auto-correct-word' is bound to `C-.' ;; Press it one time to correct the word under the cursor. ;; If several spellings are possible, they appear in the minibuffer. ;; Just keep hitting `C-.' to replace the word with the successive ;; suggestions. ;; enable the likeness criteria (setq flyspell-sort-corrections nil) ;; don't consider that a word repeated twice is an error (FIXME) (setq flyspell-doublon-as-error-flag nil) ;; dash character (`-') is considered as a word delimiter (setq flyspell-consider-dash-as-word-delimiter-flag t) (defun my-turn-on-flyspell-french () "Unconditionally turn on flyspell-mode (in French) and call `flyspell-buffer'." (interactive) (flyspell-mode 1) ;; instead of just toggling the mode (ispell-change-dictionary "francais") (flyspell-buffer)) (defun my-turn-on-flyspell-english () "Unconditionally turn on flyspell-mode (in American English) and call `flyspell-buffer'." (interactive) (flyspell-mode 1) (ispell-change-dictionary "american") (flyspell-buffer)) ;; turn on `flyspell' when changing a buffer which is unmodified (when (or (file-readable-p "/usr/lib/aspell/francais.alias") (file-readable-p "C:/Program Files/Aspell/dict/francais.alias")) ;; check that the French dictionary can be opened ;; for reading (defvar my-flyspell-major-mode-list '(html-mode latex-mode message-mode muse-mode ;;; nuweb-mode (emmerdant: je sauve, compile, et recheck spell!) nxml-mode text-mode)) (add-hook 'first-change-hook (lambda () (when (and (memq major-mode my-flyspell-major-mode-list) (not flyspell-mode)) (my-turn-on-flyspell-french))))) ;; from Alex Schroeder (defun my-change-dictionary () "Change the dictionary." (interactive) (let ((dict (or ispell-local-dictionary ispell-dictionary))) (setq dict (if (string= dict "francais") "american" "francais")) (message "Switched to %S" dict) (sit-for 0.4) (ispell-change-dictionary dict) (when flyspell-mode (flyspell-delete-all-overlays) (flyspell-buffer)))) ;; key bindings (global-set-key [(f7)] 'ispell-word) (global-set-key [(shift f7)] 'my-change-dictionary) (global-set-key [(control f7)] 'ispell-change-dictionary) ;;; ;; don't print messages for every word (when checking the entire buffer) ;;; ;; as it causes an enormous slowdown ;;; (setq flyspell-issue-message-flag nil) ;; flyspell comments and strings in programming modes ;; (preventing it from finding mistakes in the code) (add-hook 'autoconf-mode-hook 'flyspell-prog-mode) (add-hook 'autotest-mode-hook 'flyspell-prog-mode) (add-hook 'c++-mode-hook 'flyspell-prog-mode) (add-hook 'c-mode-hook 'flyspell-prog-mode) (add-hook 'cperl-mode-hook 'flyspell-prog-mode) (add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode) (add-hook 'makefile-mode-hook 'flyspell-prog-mode) (add-hook 'nxml-mode-hook 'flyspell-prog-mode) (add-hook 'python-mode-hook 'flyspell-prog-mode) (add-hook 'sh-mode-hook 'flyspell-prog-mode) ;; (add-hook 'c-mode-common-hook 'flyspell-prog-mode t) ;; (add-hook 'java-mode-common-hook 'flyspell-prog-mode t) ;; spell-check your XHTML (eval-after-load "flyspell" '(progn (add-to-list 'flyspell-prog-text-faces 'nxml-text-face)))) ;; TODO Take a look at `diction' (style and grammar for English and German) ;; excellent! (defun word-definition-lookup () "Look up the word under cursor in a browser." (interactive) (browse-url (concat "http://www.answers.com/main/ntquery?s=" (thing-at-point 'word)))) (when (try-require 'dictionary-FIXME) (load "dictionary-init") ;; server contacted for searching the dictionary ;; (setq dictionary-server "localhost") ;; connect via a HTTP proxy (using the CONNECT command) (setq dictionary-use-http-proxy t) ;; name of the HTTP proxy to use (setq dictionary-proxy-server "hellman") ;; port of the proxy server (setq dictionary-proxy-port 8080) ;; ask for a new word to search (global-set-key [(control c) (s)] 'dictionary-search) ;; ask for a pattern and list all matching words (global-set-key [(control c) (m)] 'dictionary-match-words)) (when (try-require 'dictem-FIXME) (setq dictem-server "localhost") (dictem-initialize) (define-key mode-specific-map [?s] 'dictem-run-search) (define-key dictem-mode-map [tab] 'dictem-next-link) (define-key dictem-mode-map [(backtab)] 'dictem-previous-link) ;; For creating hyperlinks on database names ;; and found matches. ;; Click on them with mouse-2 (add-hook 'dictem-postprocess-match-hook 'dictem-postprocess-match) ;; For highlighting the separator between the definitions found. ;; This also creates hyperlink on database names. (add-hook 'dictem-postprocess-definition-hook 'dictem-postprocess-definition-separator) ;; For creating hyperlinks in dictem buffer ;; that contains definitions. (add-hook 'dictem-postprocess-definition-hook 'dictem-postprocess-definition-hyperlinks) ;; For creating hyperlinks in dictem buffer ;; that contains information about a database. (add-hook 'dictem-postprocess-show-info-hook 'dictem-postprocess-definition-hyperlinks)) (message "21 Commands for Fixing Typos... Done") ;;}}} ;;{{{ --[ 22 (info "(emacs)Keyboard Macros") ]------------------------------ (message "22 Keyboard Macros...") ;;; ----[ 22.1 (info "(emacs)Basic Keyboard Macro") Use ;; If you want to check the result each time before repeating, then ;; `C-x e e e...'. ;; If you want to repeat only N times, then `C-u N C-x e'. ;; If you want to repeat forever or until error, then `C-u 0 C-x e'. ;; <shift>-<F8> to start recording ;; <shift>-<F8> again to stop recording ;; <F8> to call it (defun my-toggle-kbd-macro-recording-on () "Start recording a keyboard macro and toggle functionality of key binding." (interactive) (global-set-key [(shift f8)] 'my-toggle-kbd-macro-recording-off) (start-kbd-macro nil)) (defun my-toggle-kbd-macro-recording-off () "Stop recording a keyboard macro and toggle functionality of key binding." (interactive) (global-set-key [(shift f8)] 'my-toggle-kbd-macro-recording-on) (end-kbd-macro)) ;; execute the most recent keyboard macro (global-set-key [(f8)] 'call-last-kbd-macro) ;; start/stop recording a keyboard macro (global-set-key [(shift f8)] 'my-toggle-kbd-macro-recording-on) ;; assign a name to the last keyboard macro defined (global-set-key [(control f8)] 'name-last-kbd-macro) (message "22 Keyboard Macros... Done") ;;}}} ;; ## M a j o r S t r u c t u r e s o f E m a c s ##################### ;;{{{ --[ 23 (info "(emacs)Files") Handling ]------------------------------- (message "23 Files Handling...") ;;; ----[ 23.2 (info "(emacs)Visiting") Files ;; change the default directory (if it exists) ;; (it is also the default directory when attaching files to mails) (setq my-default-directory "~") (if (file-directory-p my-default-directory) (cd my-default-directory) (cd (getenv "HOME"))) ;; open my Emacs init file (defun my-open-dot-emacs () "Opening `~/.emacs'." (interactive) (find-file "~/.emacs")) (global-set-key [(shift f3)] 'my-open-dot-emacs) ;; open my Gnus configuration file (defun my-open-dot-gnus () "Opening `~/.gnus'." (interactive) (find-file "~/.gnus")) (global-set-key [(control f3)] 'my-open-dot-gnus) ;; open my Timeclock file (defun my-open-timeclock () "Opening `~/.timeclock/default.log'." (interactive) (find-file "~/.timeclock/default.log")) (global-set-key [(control f4)] 'my-open-timeclock) ;;; ----[ 23.3 (info "(emacs)Saving") Files ;; make your changes permanent (global-set-key [(f2)] 'save-buffer) ;; (add-hook 'after-save-hook ;; 'executable-make-buffer-file-executable-if-script-p) ;; offer save of `*scratch*' buffer on exit (save-excursion (set-buffer "*scratch*") (setq buffer-file-name "~/*scratch*")) ;; `(setq buffer-offer-save t)' does not have its intended effect in my ;; `.emacs' file (i.e., `buffer-offer-save' still has its global default ;; value of nil in the `*scratch*' buffer). But if I immediately evaluate it ;; in the `*scratch*' buffer, it works. ;; That is because at startup, Emacs sets the major mode of `*scratch*' ;; according to `initial-major-mode', _after_ my `.emacs' is read. Changing ;; major modes kills all local variables that are not permanently local, ;; including `buffer-offer-save'. (setq initial-major-mode 'text-mode) ;; to avoid autoloads for lisp mode (cedet) ;; ensure a file ends in a newline when it is saved (setq require-final-newline t) ;; TODO I should do this only for text and Fundamental modes, because I ;; could edit binary files ;; directory used for temporary files (XEmacs (setq temporary-file-directory (or (getenv "TEMP") "/tmp/"))) ;; maintain last change time stamps (`Time-stamp: <>' occurring within the ;; first 8 lines) in files edited by Emacs (when (try-require 'time-stamp) ;; format of the string inserted by `M-x time-stamp' (setq time-stamp-format "%3a %:y-%02m-%02d %02H:%02M %u on %s") ; `Weekday YYYY-MM-DD HH:MM USER on SYSTEM' ;; update time stamps every time you save a buffer (add-hook 'write-file-hooks 'time-stamp)) ;; insert a time stamp string (defun my-insert-time-stamp () "Insert a time stamp." (interactive "*") (insert (format "%s %s - %s %s" comment-start (current-time-string) (user-login-name) comment-end))) ;; update the copyright notice in current buffer (GNUEmacs (when (try-require 'copyright) (add-hook 'write-file-hooks 'copyright-update))) ;;; ----[ 23.4 (info "(emacs)Reverting") a Buffer ;; replace current buffer text with the text of the visited file on disk (defun my-revert-buffer () "Unconditionally revert current buffer." (interactive) (flet ((yes-or-no-p (msg) t)) (revert-buffer))) ;; key binding (global-set-key [(control f12)] 'my-revert-buffer) ;;; ----[ 23.6 (info "(emacs)Auto Save"): Protection Against Disasters ;; how to get Emacs to auto-save to your local disk [`#file#'] ;; auto-save every 100 input events (setq auto-save-interval 100) ;; auto-save after 15 seconds idle time (setq auto-save-timeout 15) ;; put backup files (i.e., `foo~' or `foo.~i~') in one place (GNUEmacs ;; regexp => directory mappings ;; filenames matching a regexp are backed up in the corresponding directory (setq backup-directory-alist '((".*" . "~/.emacs_backups/")))) ;; '(("." . "~/.saves")) ;; Emacs will `make-directory' it if necessary (XEmacs (when (try-require 'backup-dir) (make-variable-buffer-local 'backup-inhibited) (setq bkup-backup-directory-info '((t "~/.saves" ok-create full-path prepend-name))))) ;; ;; The `auto-save.el' and `backup.el' packages collect files in one place ;; (try-require 'auto-save) ;; (try-require 'backup) ;; always use copying to create backup files (don't clobber symlinks) (setq backup-by-copying t) ;; make numeric backup versions (setq version-control t) ;; delete excess backup versions silently (setq delete-old-versions t) ;; Check out Kevin's `ebackup.el' ;; for saving in a specified common directory (not in local dir) ;; and handling saving of buffers with spaces in their name... ;; (otherwise, problems when composing *mail replies to ...* ) ;;; ----[ 23.8 (info "(emacs)Version Control") ;; PCL-CVS (when (try-require 'pcvs-XXX) ;; allow commit on whole directories (setq cvs-allow-dir-commit t) ;; when to reuse an existing cvs buffer (setq cvs-reuse-cvs-buffer 'always) ;; subdir ;; examine (global-set-key [(control x) (v) (e)] 'cvs-examine) ;; examine without asking for a directory (global-set-key [(control f9)] '(lambda () (interactive) (cvs-examine (file-name-directory (buffer-file-name)) nil))) ;; messages that should be ignored by the parser ;; TODO should only ADD the last one to the default value of cvs-parse-... (setq cvs-parse-ignored-messages '("Executing ssh-askpass to query the password.*$" ".*Remote host denied X11 forwarding.*$" ".*-m wrapper option is not supported remotely.*$")) ;; change the CVS Id marker to reflect that a source file was edited ;; (from Brady Montz) (defun my-mark-cvs-modified () "Called when a file has changed. Updates any RCS Id and Header keywords it finds to show that the file is modified." (let ((buffer-undo-list t)) ; don't let this change get into the undo list ; because of this, we must ensure that the edit is in-place, and doesn't ; move any text (when (and (buffer-modified-p) (boundp 'vc-mode) vc-mode) (save-excursion (goto-char (point-min)) (while (re-search-forward (concat "\\(\\$\\(?:Id\\|Header\\): " "[^\"'#;$]* \\)\\(Exp \\$\\)") nil t) (replace-match "\\1Mod $" t)))))) (defadvice basic-save-buffer (before my-basic-save-buffer first activate) (my-mark-cvs-modified)) (defun run (command &optional to-buffer) "A variation of shell-command. With no optional argument this runs the command creating a special buffer to put the output in. The buffer is named after the first word in the command. The optional argument to-buffer allows the target buffer to be specified. With the interactive-prefix the target buffer is the current buffer (as in shell-command)." (interactive (list (read-from-minibuffer "Shell command: " nil nil nil 'shell-command-history) current-prefix-arg)) (shell-command command (or to-buffer (get-buffer-create (car (split-string command " ")))))) (defun run-eval (command &optional func) "Evaluate the shell command optionally passing results to a function. Without the optional func this returns the result of running the command, as a string. With the function the results of the shell command are passed as a string to the function, the value of calling the function is returned. If you supply func then it must either be a function taking one string argument or a string which can be evaluated to a function taking one string argument. Interactively the prefix argument will cause a function to be prompted for." (interactive (list (read-from-minibuffer "Shell command: " nil nil nil 'shell-command-history) (if current-prefix-arg (read-from-minibuffer "Function: ")))) (with-temp-buffer ;; This turns off the open window behavior of shell-command (let ((pop-up-windows nil)) (shell-command command (current-buffer))) (let ((str (buffer-substring-no-properties (point-min) (- (point-max) 1)))) (cond ((functionp func) (funcall func str)) ((stringp func) (funcall (eval (read func)) str)) ('t str))))) (defun map-files (thunk filename-list) "Read in each file as a buffer and execute thunk on them. If any file does not already exist in the buffer list then that buffer is destroyed after thunk has been executed. If filename-list is a list then it's used directly, if it's a string we run string-to-words on it." (mapcar (lambda (filename) (if (not (get-file-buffer filename)) (let ((buf (find-file filename))) (with-current-buffer buf (funcall thunk) (kill-buffer buf))) (with-current-buffer (get-buffer filename) (funcall thunk)))) (if (listp filename-list) filename-list (split-string filename-list)))) ;; switch the entire module from one location to another, using the same ;; code base when being at different physical sites (defun my-cvs-hack () "Toggle the CVS between local and remote" (interactive) (run-eval "find . -name 'Root'" (lambda (list-of-files) (map-files (lambda () (if (re-search-forward ":localhost:" nil 't) (replace-match ":rawls:") (progn (re-search-forward ":rawls:" nil 't) (replace-match ":localhost:"))) (save-buffer)) list-of-files))))) ;; Subversion (GNUEmacs (when (try-require 'psvn) ;; `svn-status-property-edit-svn-ignore' (`P TAB') allows user to edit ;; list of files ignored by Subversion ;; hide unmodified files (setq svn-status-hide-unmodified t) ;; use longer phrases (setq svn-status-short-mod-flag-p nil) ;; delete temporary files (setq svn-status-ediff-delete-temporary-files t) ;; show the diff we are about to commit (define-key svn-log-edit-mode-map [(f6)] 'svn-log-edit-svn-diff) ;; examine (global-set-key [(control x) (v) (e)] 'svn-status) (defun my-svn-log-edit-mode-setup () (setq ispell-local-dictionary "american") (flyspell-mode)) (add-hook 'svn-log-edit-mode-hook 'my-svn-log-edit-mode-setup))) ;;; ----[ 23.10 (info "(emacs)Comparing Files") ;; default to unified diffs (setq diff-switches "-u") ;; compare text in current window with text in next window (global-set-key [(control c) (=)] 'compare-windows) ;;;;;;;;;;;;;;;; FIXME conflict with reftex ;;; ----[ 23.11 (info "(emacs)Diff Mode") ;; run `diff' in compilation-mode (autoload 'diff-mode "diff-mode" "Diff major mode" t) ;; extensions to `diff-mode.el' (try-require 'diff-mode-) ;; ediff, a comprehensive visual interface to diff & patch ;; setup for Ediff's menus and autoloads (try-require 'ediff-hook) ;; auto-refine only the regions of this size (in bytes) or less (setq ediff-auto-refine-limit (* 2 14000)) ;; begin in side by side split (setq ediff-split-window-function 'split-window-horizontally) ;;; ----[ 23.13 Accessing (info "(emacs)Compressed Files") ;; Using the Emacs Dired utility, you can compress or uncompress a file by ;; pressing `Z' ;; easy editing of arc/zip/zoo/lhz archives (GNUEmacs (require 'arc-mode) ;; TODO see `archive-zip-extract' (when running-ms-windows ;; Unfortunately, if you are trying to use gunzip to uncompress a file ;; under Dired, you will probably encounter a problem saying "Failed ;; to uncompress ..." or "spawning child process: exec format error". ;; The problem is due to that gunzip provided by Cygwin is not an ;; executable file. It is a symbolic link to gzip. (You can verify ;; this by "ls -l /usr/bin/gunzip". Since Gnu Emacs does not ;; understand Cygwin's symbolic link, it cannot execute gunzip. Here ;; is the solution. (require 'dired-aux) (defun dired-call-process (program discard &rest arguments) ;; 09Feb02, sailor overwrite this function because Gnu Emacs cannot ;; recognize gunzip is a symbolic link to gzip. Thus, if the program ;; is "gunzip", replace it with "gzip" and add an option "-d". ;; "Run PROGRAM with output to current buffer unless DISCARD is t. ;; Remaining arguments are strings passed as command arguments to ;; PROGRAM." ;; Look for a handler for default-directory in case it is a ;; remote file name. (let ((handler (find-file-name-handler (directory-file-name default-directory) 'dired-call-process))) (if handler (apply handler 'dired-call-process program discard arguments) (progn (if (string-equal program "gunzip") (progn (setq program "gzip") (add-to-list 'arguments "-d"))) (apply 'call-process program nil (not discard) nil arguments))))))) ;;; ----[ 23.14 (info "(emacs)File Archives") ;; simple editing of tar files as a Dired-like listing of its contents (try-require 'tar-mode) ;; reading/writing/loading compressed files (require 'jka-compr) ;;{{{ crypt++ ;; code for handling all sorts of compressed and encrypted files (try-require 'crypt++) ;; allows you to encrypt/decrypt files within Emacs. I use it regularly and ;; it works very reliably. When I use `C-x C-f' to access an encrypted file, ;; Emacs asks me for the passphrase and then decrypts the file before ;; displaying it. When I save the file, Emacs automatically encrypts it ;; again. ;;}}} ;;; ----[ 23.15 (info "(emacs)Remote Files") ;; transparent FTP support (when (try-require 'ange-ftp) ;; try to use passive mode in ftp, if the client program supports it (setq ange-ftp-try-passive-mode t)) ; needed for Ubuntu ;;{{{ (info "(tramp)Top") TRAMP - Transparent Remote Access, Multiple Protocols ;; (other protocols than just FTP) ;; Examples: C-x C-f /ssh:fni@server:/home/fni/.bashrc ;; C-x C-f /plink:fni@server:/home/fni/.bashrc (from Windows) ;; C-x C-f /sudo:root@localhost:/etc/group ;; Note -- `sshfs' can give me the same functionality as Tramp: it is like a ;; personal NFS (another mounted file system) over SSH. If you can SSH to a ;; server, you can probably do `sshfs'. ;; > I'm in shell mode, logged in on another machine over ssh, and I want to ;; > do some 'crontab -e' editing on that machine. But that will bring up a ;; > new editor, which is whatever you set in your EDITOR env variable, and ;; > both vi and emacs cannot be used in this dumb shell. How can I edit the ;; > crontab in my emacs session? ;; ;; Create the crontab on the remote machine, open it using tramp from your ;; machine, edit and save and then reinstall it. ;; That or simply enable x forwarding so running emacs on the remote ;; bring up emacs gtk/x on your main machine editing your cron file ;; on the remote. (when (try-require 'tramp) ;;{{{ 4.5 Selecting a (info "(tramp)Default Method") ;; default transfer method ;; (issues with Cygwin `ssh' which does not cooperate with Emacs processes ;; -> use `plink' from PuTTY) (setq tramp-default-method ; `scp' by default (if running-ms-windows "plink" "ssh")) ;;}}} ;;{{{ 4.6 Selecting a (info "(tramp)Default User") ;; default user (setq tramp-default-user "fni") ;;}}} ;;{{{ 4.8 Connecting to a remote host using (info "(tramp)Multi-hops") ;; new proxy system (instead of the old "multi-hop" filename syntax) ;; to edit files on a remote server by going via another server (add-to-list 'tramp-default-proxies-alist '("10.10.13.123" "\\`root\\'" "/ssh:%h:")) ;; Opening `/sudo:10.10.13.123:' would connect first `10.10.13.123' via ;; `ssh' under your account name, and perform `sudo -u root' on that ;; host afterwards. It is important to know that the given method is ;; applied on the host which has been reached so far. ;; The trick is to think from the end. ;;}}} ;;{{{ 4.14 (info-link "(tramp)Remote shell setup") hints ;; string used for end of line in rsh connections (setq tramp-rsh-end-of-line "\r") ; "\n" by default ;;}}} ;;{{{ 4.15 (info "(tramp)Auto-save and Backup") configuration ;; faster auto saves (setq tramp-auto-save-directory temporary-file-directory) ;;}}} ;;{{{ 10 How to Customize (info "(tramp)Traces and Profiles") ;; help debugging (setq tramp-verbose 6) ; 0 (setq tramp-debug-buffer t) ;;}}} ;; define own abbreviation (for use with bookmarks) (add-to-list 'directory-abbrev-alist (if (memq system-type '(cygwin windows-nt)) '("^/RUSSELL" . "//RUSSELL/Users") '("^/RUSSELL" . "/smb:fni@RUSSELL:/Users"))) ;; after adding: ;; (setq coding-system-for-read 'utf-8) ;; (setq coding-system-for-write 'utf-8) ;; to my `.emacs', tramp works correctly with UTF-8 files. ;;{{{ Open a file as root, easily [from Alex Schroeder] (defvar find-file-root-prefix "/sudo:root@localhost:" "*The filename prefix used to open a file with `find-file-root'. This should look something like \"/sudo:root@localhost:\" (new style TRAMP) or \"/[sudo:root@localhost]/\" (XEmacs or old style TRAMP).") (defvar find-file-root-history nil "History list for files found using `find-file-root'.") (defvar find-file-root-hook nil "Normal hook for functions to run after finding a \"root\" file.") (defun find-file-root () "*Open a file as the root user. Prepends `find-file-root-prefix' to the selected file name so that it maybe accessed via the corresponding tramp method." (interactive) (require 'tramp) (let* (;; We bind the variable `file-name-history' locally so we can ;; use a separate history list for "root" files. (file-name-history find-file-root-history) (name (or buffer-file-name default-directory)) (tramp (and (tramp-tramp-file-p name) (tramp-dissect-file-name name))) path dir file) ;; If called from a "root" file, we need to fix up the path. (when tramp (setq path (tramp-file-name-path tramp) dir (file-name-directory path))) (when (setq file (read-file-name "Find file (UID = 0): " dir path)) (find-file (concat find-file-root-prefix file)) ;; If this all succeeded save our new history list. (setq find-file-root-history file-name-history) ;; allow some user customization (run-hooks 'find-file-root-hook)))) (defface find-file-root-header-face '((t (:foreground "white" :background "red3"))) "*Face use to display header-lines for files opened as root.") (defun find-file-root-header-warning () "*Display a warning in header line of the current buffer. This function is suitable to add to `find-file-root-hook'." (let* ((warning "WARNING: EDITING FILE WITH ROOT PRIVILEGES!") (space (+ 6 (- (frame-width) (length warning)))) (bracket (make-string (/ space 2) ?-)) (warning (concat bracket warning bracket))) (setq header-line-format (propertize warning 'face 'find-file-root-header-face)))) (add-hook 'find-file-root-hook 'find-file-root-header-warning) (global-set-key [(control x) (control g)] 'find-file-root)) ;;}}} ;;}}} ;;; ----[ 23.18 (info "(emacs)File Conveniences") ;; show image files as images (not as semi-random bits) (GNUEmacs (auto-image-file-mode 1)) ;; visit a file (global-set-key [(f3)] 'find-file) ;; find file (or URL) at point (when (try-require 'ffap) ;; don't use default key bindings, as I want some of them to be defined ;; differently (C-x C-r, for example) ;; function called to fetch an URL (setq ffap-url-fetcher 'browse-url) ; could be `browse-url-emacs' or ; `w3m-browse-url' ;; visit a file (global-set-key [(f3)] 'find-file-at-point)) ;; setup a menu of recently opened files (when (try-require 'recentf) ;;; ;; maximum number of items of the recent list that will be saved ;;; (setq recentf-max-saved-items 30) ;; file to save the recent list into (setq recentf-save-file "~/.emacs.d/.recentf") ;; maximum number of items in the recentf menu (setq recentf-max-menu-items 30) ;; to protect from tramp not correctly supported (yet) under Win32 (setq recentf-auto-cleanup 'never) ;; save file names relative to my current home directory (setq recentf-filename-handlers '(abbreviate-file-name)) ;; toggle `recentf' mode (recentf-mode 1) ;; add key binding (global-set-key [(control x) (control r)] 'recentf-open-files)) ;; open anything (GNUEmacs (when (try-require 'anything-config) ; loads `anything.el' too ;; source of candidates for anything (setq anything-sources (list anything-c-source-locate anything-c-source-tracker-search anything-c-source-bookmarks ;; 1 anything-c-source-file-name-history ;; 2 anything-c-source-buffers ;; 3 anything-c-source-man-pages ;; 4 anything-c-source-info-pages ;; 5 )) ;;; (setq anything-sources ;;; (list ;;; anything-c-source-recentf ;;; anything-c-source-files-in-current-dir ;;; anything-c-source-complex-command-history ;;; anything-c-source-emacs-commands ;;; anything-c-source-emacs-functions ;;; anything-c-source-imenu ;;; anything-c-source-mac-spotlight ;;; anything-c-source-evaluation-result ;;; anything-c-source-google-suggest ;;; )) ;; do not show more candidates than this limit from inidividual sources (setq anything-candidate-number-limit 10) ;; make anything minibuffer better input latency (defadvice anything-check-minibuffer-input (around sit-for activate) (if (sit-for anything-idle-delay t) ad-do-it)) ;; select anything (global-set-key [(f3)] 'anything))) ;; TODO Have a look at gpicker! (message "23 Files Handling... Done") ;;}}} ;;{{{ --[ 24 Using Multiple (info "(emacs)Buffers") ]----------------------- (message "24 Using Multiple Buffers...") ;;; ----[ 24.2 (info "(emacs)List Buffers") ;; The C (current) column has a `.' for the buffer from which you came. ;; The R (read-only) column has a `%' if the buffer is read-only. ;; The M (modified) column has a `*' if it is modified. ;; rebind `C-x C-b' (global-set-key [(control x) (control b)] 'electric-buffer-list) ;; `buffer-menu' moves point in the window which lists your buffers ;; `electric-buffer-list' pops up a buffer describing the set of buffers ;; operate on buffers like Dired (when (try-require 'ibuffer) ;; completely replaces `list-buffer' (defalias 'ibuffer-list-buffers 'list-buffer) (global-set-key (kbd "C-x C-b") 'ibuffer)) ;; customizable buffer-selection with multiple menus (GNUEmacs (when window-system (require 'msb))) ;; buffer selection (GNUEmacs (try-require 'ibs)) ;; `cyclebuffer.el' ;; put the current buffer at the end of the list of all buffers (global-set-key [(shift f12)] 'bury-buffer) ;;; ----[ 24.4 (info "(emacs)Kill Buffer") ;; kill buffer without confirmation (if not modified) (defun my-kill-this-buffer () "Kill the current buffer without confirmation (if not modified)." (interactive) (kill-buffer nil)) ;; key binding (global-set-key [(f12)] 'my-kill-this-buffer) ;;; ----[ 24.7 (info "(emacs)Buffer Convenience") and Customization of Buffer Handling ;; unique buffer names dependent on file name (when (try-require 'uniquify) ;; style used for uniquifying buffer names with parts of directory name (setq uniquify-buffer-name-style 'forward)) (message "24 Using Multiple Buffers... Done") ;;}}} ;;{{{ --[ 25 Multiple (info "(emacs)Windows") ]----------------------------- (message "25 Multiple Windows...") ;; turn off this horrible tab thingy in XEmacs (XEmacs (when (boundp 'default-gutter-visible-p) (set-specifier default-gutter-visible-p nil))) ;; look at `ido' ;;; ----[ 25.3 Using (info "(emacs)Other Window") ;; cycle through all windows on current frame ;; (global-set-key [(control tab)] 'other-window) (global-set-key [(f6)] 'other-window) ;; ----[ 25.6 Deleting and (info "(emacs)Change Window") ;; delete all windows in the selected frame except the selected window (global-set-key [(f5)] 'delete-other-windows) ;; delete the selected window and kill the buffer that was showing in it ;;(global-set-key [(f12)] 'kill-buffer-and-window) ;; enlarge or shrink windows more easily (global-set-key [(control shift up)] 'enlarge-window) (global-set-key [(control shift down)] 'shrink-window) (global-set-key [(control shift left)] 'enlarge-window-horizontally) (global-set-key [(control shift right)] 'shrink-window-horizontally) ;; make all visible windows the same height (approximately) (global-set-key [(control f6)] 'balance-windows) ;; swap 2 windows (defun my-swap-windows () "If you have 2 windows, it swaps them." (interactive) (cond ((not (= (count-windows) 2)) (message "You need exactly 2 windows to do this.")) (t (let* ((w1 (first (window-list))) (w2 (second (window-list))) (b1 (window-buffer w1)) (b2 (window-buffer w2)) (s1 (window-start w1)) (s2 (window-start w2))) (set-window-buffer w1 b2) (set-window-buffer w2 b1) (set-window-start w1 s2) (set-window-start w2 s1))))) (global-set-key [(control c) (~)] 'my-swap-windows) (defun my-toggle-window-split () "Vertical split shows more of each line, horizontal split shows more lines. This code toggles between them. It only works for frames with exactly two windows." (interactive) (if (= (count-windows) 2) (let* ((this-win-buffer (window-buffer)) (next-win-buffer (window-buffer (next-window))) (this-win-edges (window-edges (selected-window))) (next-win-edges (window-edges (next-window))) (this-win-2nd (not (and (<= (car this-win-edges) (car next-win-edges)) (<= (cadr this-win-edges) (cadr next-win-edges))))) (splitter (if (= (car this-win-edges) (car (window-edges (next-window)))) 'split-window-horizontally 'split-window-vertically))) (delete-other-windows) (let ((first-win (selected-window))) (funcall splitter) (if this-win-2nd (other-window 1)) (set-window-buffer (selected-window) this-win-buffer) (set-window-buffer (next-window) next-win-buffer) (select-window first-win) (if this-win-2nd (other-window 1)))))) (global-set-key [(control c) (|)] 'my-toggle-window-split) ;; ----[ 25.7 (info "(emacs)Window Convenience") Features and Customization ;; `M-x scroll-all-mode' scrolls all visible windows together. ;; directional window-selection routines (when (try-require 'windmove) ;; set up keybindings for `windmove' (switch windows with S-<arrow-key>) (windmove-default-keybindings)) ;; Another possibility is window-number.el. It numbers windows and you can ;; switch them with C-x C-j <number>. With `window-number-meta-mode' you can ;; switch them more easily with M-<number>. ;; You can make a window dedicated, which does just what you want. You can ;; do it for all windows or windows for buffers whose names match some ;; pattern, and so on. ;; Check the Elisp manual (that's Emacs Lisp), and look for `dedicated' ;; windows. See, in particular, user options `special-display-buffer-names' ;; and `special-display-regexps'. ;; Do you know winner-mode ? ;; When you have many windows open, do M-x winner-mode, ;; then come back to a single window (C-x 1) and then run ;; M-x winner-undo ==> C-c left ;; come-back to the single window ==>C-c right (winner-redo) ;; winring (message "25 Multiple Windows... Done") ;;}}} ;;{{{ --[ 26 (info "(emacs)Frames") and Graphical Displays ]---------------- (message "26 Frames and X Windows...") ;;; ----[ 26.1 (info "(emacs)Mouse Commands") for Editing ;; copy/paste with Gnome desktop (GNUEmacs ;; make cut, copy and paste (keys and menu bar items) use the clipboard (menu-bar-enable-clipboard) ;; cutting and pasting uses the clipboard (setq x-select-enable-clipboard t)) ;;; ----[ 26.6 (info "(emacs)Frame Commands") (unless running-ms-windows (defun toggle-full-screen () "Toggle between full screen and partial screen display on X11; courtesy of http://www.emacswiki.org/cgi-bin/wiki/FullScreen" (interactive) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_FULLSCREEN" 0))) (global-set-key [(control c) (z)] 'toggle-full-screen)) (GNUEmacs (when running-ms-windows (defun w32-maximize-frame () "Maximize the current frame." (interactive) (w32-send-sys-command 61488) (global-set-key [(control c) (z)] 'w32-restore-frame)) (global-set-key [(control c) (z)] 'w32-maximize-frame) (defun w32-restore-frame () "Restore a minimized frame." (interactive) (w32-send-sys-command 61728) (global-set-key [(control c) (z)] 'w32-maximize-frame)))) ;;; ----[ 26.7 (info "(emacs)Creating Frames") ;; o resize the frame to the size you want ;; o enter `(frame-parameters)' in the `*scratch*' buffer ;; o evaluate the form: place the cursor after the closing paren, and ;; type `C-j', so that the output goes right into the `*scratch*' buffer ;; put Emacs exactly where you want it, every time it starts up, by ;; auto-detecting the screen dimensions and computing where it should be (when window-system ;; list of frame parameters for creating the initial frame (setq initial-frame-alist '((top . 0) (left . 0))) (setq initial-frame-alist (append (list '(internal-border-width . 2) '(line-spacing . 1) ;; frame transparency '(active-alpha . 0.875) ;; active frame '(inactive-alpha . 0.75)) ;; inactive frame initial-frame-alist)) ;; list of default values for frame creation (setq default-frame-alist (cond ((= (x-display-pixel-height) 1200) '((left . 0) (height . 74))) ((= (x-display-pixel-height) 1024) '((left . 0) (height . 63))) ((= (x-display-pixel-height) 800) (if running-ms-windows '((left . 0) (height . 55)) ;; under Ubuntu '((left . 0) (height . 47) (vertical-scroll-bars . right)))) ((= (x-display-pixel-height) 768) '((left . 0) (height . 46)))))) (XEmacs (set-frame-width (buffer-dedicated-frame) 80) (set-frame-height (buffer-dedicated-frame) 42) (set-frame-position (buffer-dedicated-frame) 0 0)) ;; title bar display of visible frames (setq frame-title-format "Emacs - %b") ;;; From sample .emacs ;;; local Emacs background: default ;;; remote Emacs background: palegreen1 ;;; root Emacs background: coral2 ; ;(cond ; ((and (string-match "XEmacs" emacs-version) ; (eq window-system 'x) ; (boundp 'emacs-major-version) ; (= emacs-major-version 19) ; (>= emacs-minor-version 12)) ; (let* ((root-p (eq 0 (user-uid))) ; (dpy (or (getenv "DISPLAY") "")) ; (remote-p (not ; (or (string-match "^\\(\\|unix\\|localhost\\):" dpy) ; (let ((s (system-name))) ; (if (string-match "\\.\\(netscape\\|mcom\\)\\.com" s) ; (setq s (substring s 0 (match-beginning 0)))) ; (string-match (concat "^" (regexp-quote s)) dpy))))) ; (bg (cond (root-p "coral2") ; (remote-p "palegreen1") ; (t nil)))) ; (cond (bg ; (let ((def (color-name (face-background 'default))) ; (faces (face-list))) ; (while faces ; (let ((obg (face-background (car faces)))) ; (if (and obg (equal def (color-name obg))) ; (set-face-background (car faces) bg))) ; (setq faces (cdr faces))))))))) ;;; ----[ 26.9 Making and Using a (info "(emacs)Speedbar") Frame ;; everything browser (into individual source files), or Dired on steroids (when (try-require 'speedbar-XXX) ;; number of spaces used for indentation (setq speedbar-indentation-width 2) ;; expand/collapse latex sections (speedbar-add-supported-extension '(".tex" ".bib" ".w")) ;; jump to speedbar frame (global-set-key [(f4)] 'speedbar-get-focus) ;; bind the arrow keys in the speedbar tree ;; [http://www.uweb.ucsb.edu/~dreamtheorist/emacs.html] (define-key speedbar-key-map [(right)] 'speedbar-expand-line) (define-key speedbar-key-map [(left)] 'speedbar-contract-line) ;; parameters to use when creating the speedbar frame in Emacs (setq speedbar-frame-parameters '((width . 30) (height . 45) (foreground-color . "blue") (background-color . "white")))) ;;; ----[ 26.16 (info "(emacs)Menu Bars") ;; turn menus off (unless window-system (menu-bar-mode 0)) ;;; ----[ 26.20 (info "(emacs)Mouse Avoidance") ;; make mouse pointer stay out of the way of editing (when window-system (when (try-require 'avoid) (mouse-avoidance-mode 'animate))) ;; mouse wheel support (GNUEmacs (mwheel-install)) (message "26 Frames and X Windows... Done") ;;}}} ;;{{{ --[ 27 (info "(emacs)International") Character Set Support ]---------- (message "27 International Character Set Support...") ;; To open (or save) a file in UTF-8, you can press `C-x RET c utf-8 RET' ;; (`universal-coding-system-argument') before the `C-x C-f' (or `C-x C-s') ;; To help you find all the chars you need to replace by escape sequences, ;; you can use `C-u C-s [^[:ascii:]]' ;; To check your locale settings, you can have a look to what Emacs produce ;; (in a mail buffer) under "Important settings" when you type ;; `M-x report-emacs-bug RET foo RET': ;; ;; Important settings: ;; value of $LC_ALL: nil ;; value of $LC_COLLATE: nil ;; value of $LC_CTYPE: nil ;; value of $LC_MESSAGES: nil ;; value of $LC_MONETARY: nil ;; value of $LC_NUMERIC: nil ;; value of $LC_TIME: nil ;; value of $LANG: en_US.UTF-8 ;; value of $XMODIFIERS: nil ;; locale-coding-system: utf-8-unix ;; default-enable-multibyte-characters: t ;;; ----[ 27.3 (info "(emacs)Language Environments") ;; (GNUEmacs ;; (set-language-environment 'utf-8)) ;; system locale to use for formatting time values (setq system-time-locale "en_US.utf8") ;;; ----[ 27.5 (info "(emacs)Select Input Method") ;; `M-x describe-coding-system RET RET' ;; ;; default input method for multilingual text ;; (setq default-input-method "latin-1-prefix") ;; To see all the non-ASCII characters you can type with the `C-x 8' prefix, ;; type `C-x 8 C-h'. ;;; ----[ 27.7 (info "(emacs)Coding Systems") ;; For any user who needs symbols that are not in the 7-bit ASCII set, our ;; recommendation is to move to Unicode UTF-8. That is the only encoding ;; that is the same across all platforms and operating systems that support ;; it. ;;; ----[ 27.8 (info "(emacs)Recognize Coding") Systems (add-to-list 'file-coding-system-alist '("\\.owl\\'" utf-8 . utf-8)) ;; and all the rest is utf-8: ;; '("" . utf-8) ;; In GNU Emacs, when you specify the coding explicitly in the file, ;; that overrides `file-coding-system-alist'. Not in XEmacs? ;; The variable `auto-coding-alist' is the strongest way to specify ;; the coding system for certain patterns of file names, or for files ;; containing certain patterns; this variable even overrides ;; `-*-coding:-*-' tags in the file itself. ;; default coding system (for new files), ;; also moved to the front of the priority list for automatic detection (GNUEmacs (if running-ms-windows (prefer-coding-system 'iso-latin-1) ; FIXME temp for PFlow (prefer-coding-system 'utf-8))) ;; or set environment variables like `LC_CTYPE', `LANG' or `LC_ALL' ;;; ----[ 27.9 (info "(emacs)Specify Coding") System of a File ;; ;; priority order for recognizing coding systems when reading files ;; (GNUEmacs ;; (set-coding-priority (list 'coding-category-utf-8))) (GNUEmacs ;; to copy and paste to and from Emacs through the clipboard (set-selection-coding-system 'utf-8) ;; (set-selection-coding-system 'compound-text-with-extensions) ) (message "27 International Character Set Support... Done") ;;}}} ;; ## A d v a n c e d F e a t u r e s ##################################### ;;{{{ --[ 28 (info "(emacs)Major Modes") ]---------------------------------- (message "28 Major Modes...") ;;; ----[ 28.1 How (info "(emacs)Choosing Modes") ;; Since `foo-mode' toggles Foo (minor) mode, it's better to use a function ;; on those hooks that unconditionally turns it on. Many minor modes have ;; `turn-on-foo-mode' and `turn-off-foo-mode' convenience functions for that ;; purpose, but you can fake it with an anonymous function: ;; ;; (add-hook 'text-mode-hook (lambda () (foo-mode 1))) ;; ;; or define your own convenience function and use that instead: ;; ;; (defun turn-on-foo-mode () ;; "Turn on Foo mode." ;; (foo-mode 1)) ;; (add-hook 'text-mode-hook 'turn-on-foo-mode) (autoload 'dtd-mode "tdtd" "Major mode for SGML and XML DTDs." t) (autoload 'sql-mode "sql" nil) (autoload 'css-mode "css-mode") (autoload 'nxml-mode "nxml-mode" "XML mode" t) (autoload 'ssh-config-mode "ssh-config-mode" t) ;; 1. list of filename patterns ;; vs. corresponding major mode functions (setq auto-mode-alist (append '( ("\\.css\\'" . css-mode) ("\\.\\(htm\\|html\\|xhtml\\)$" . nxhtml-mode) ("\\.sql$" . sql-mode) ;; ("\\.js$" . java-mode) ("\\.dcl$" . dtd-mode) ("\\.dec$" . dtd-mode) ("\\.dtd$" . dtd-mode) ("\\.ele$" . dtd-mode) ("\\.ent$" . dtd-mode) ("\\.mod$" . dtd-mode) ;; sorted by chapter ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode) ("\\.txt$" . indented-text-mode) ; or `text-mode' ("\\.log$" . text-mode) ("\\.tex$" . LaTeX-mode) ("\\.tpl$" . LaTeX-mode) ("\\.cgi$" . perl-mode) ("[mM]akefile" . makefile-mode) ("\\.bash$" . shell-script-mode) ("\\.expect$" . tcl-mode) (".ssh/config\\'" . ssh-config-mode) ("sshd?_config\\'" . ssh-config-mode) ) auto-mode-alist)) ;; See (info "(elisp) Syntax of Regexps") ;; \' matches end of string ;; $ matches end of line ;; Some Emacs modes are over 10K lines of code. (e.g. js2-mode, ;; nxml-mode, CEDET). Many packages make use of the `autoload' ;; feature, so that you only need to load a single file that define ;; autoloaded functions. ;; For example, nxml-mode's instruction tells you to do: ;; (when (load-library ;; "~/Media/Download/emacs/site-lisp/nxml-1.33-20080630/autostart.el") ;; ;; ;; always skip the nXhtml welcome message ;; (setq nxhtml-skip-welcome t)) (add-to-list 'auto-mode-alist (cons "\\.\\(xml\\|xsd\\|sch\\|rng\\|xslt\\|svg\\|rss\\|owl\\)\\'" 'nxml-mode)) (fset 'xml-mode 'nxml-mode) ;; instead of superseding the binding in `auto-mode-alist', you can ;; replace it (brute force) with `(setcdr (rassq 'old-mode ;; auto-mode-alist) 'new-mode)' ;; 2. list of buffer beginnings ;; vs. corresponding major mode functions (Emacs 22+) ;; see `magic-mode-alist' ;; 3. list of interpreters specified in the first line (starts with `#!') ;; vs. corresponding major mode functions (push '("expect" . tcl-mode) interpreter-mode-alist) ;; multiple major modes ;; o nXhtml includes `mumamo.el' ;; o MMM mode ;; load generic modes which support e.g. batch files (try-require 'generic-x) (message "28 Major Modes... Done") ;;}}} ;;{{{ --[ 29 (info "(emacs)Indentation") ]---------------------------------- (message "29 Indentation...") ;; indentation can't insert tabs (setq-default indent-tabs-mode nil) ;; `C-M-\' runs the command `indent-region' (message "29 Indentation... Done") ;;}}} ;;{{{ --[ 30 Commands for (info "(emacs)Text") Human Languages ]------------ (message "30 Commands for Human Languages...") ;;; ----[ 30.1 (info "(emacs)Words") ;; GNU Emacs default for killing back to the beginning of a word (XEmacs (global-set-key [(control backspace)] 'backward-kill-word)) ;; delete previous character, changing tabs into spaces (global-set-key [(shift backspace)] 'backward-delete-char-untabify) ;;; ----[ 30.2 (info "(emacs)Sentences") ;; a single space does end a sentence (setq-default sentence-end-double-space nil) ;;; ----[ 30.5 (info "(emacs)Filling") Text ;; try `longlines.el' (defun my-text-mode-setup () "Turn on filling modes in text mode." (turn-on-auto-fill) ;; adaptative filling (when (try-require 'filladapt) (setq-default filladapt-mode nil) ;; turn on filladapt mode everywhere but in ChangeLog files (cond ((equal mode-name "Change Log") t) (t (turn-on-filladapt-mode))))) ;; turn on my text setup (add-hook 'text-mode-hook 'my-text-mode-setup) ;; fabrication automatique de la typo française avec la ponctuation ;; ajout automatique de l'espace insécable là où cela va bien (defun my-insert-interrogation-mark () (interactive) (if (eq (char-before) ?\ ) ; normal space (progn (backward-delete-char 1) (insert " ?")) ; non-breaking space (insert "?"))) (defun my-insert-exclamation-mark () (interactive) (if (eq (char-before) ?\ ) ; normal space (progn (backward-delete-char 1) (insert " !")) ; non-breaking space (insert "!"))) (defun my-insert-colon () (interactive) (if (eq (char-before) ?\ ) ; normal space (progn (backward-delete-char 1) (insert " :")) ; non-breaking space (insert ":"))) (defun my-insert-semi-colon () (interactive) (if (eq (char-before) ?\ ) ; normal space (progn (backward-delete-char 1) (insert " ;")) ; non-breaking space (insert ";"))) (defun my-double-keys () "Touches spécifiques" (interactive) (local-set-key "?" 'my-insert-interrogation-mark) (local-set-key "!" 'my-insert-exclamation-mark) (local-set-key ":" 'my-insert-colon) (local-set-key ";" 'my-insert-semi-colon)) ;; typo auto pour les modes suivants (add-hook 'text-mode-hook 'my-double-keys) (add-hook 'message-mode-hook 'my-double-keys) ;; so that `M-q' does not cut spaces around «, », :, !, ... ;; (defun my-fill-nobreak-predicate () ;; (save-match-data ;; (or (looking-at "[ \t]*[])}»!?;:]") ;; (looking-at "[ \t]*\\.\\.\\.") ;; (save-excursion ;; (skip-chars-backward " \t") ;; (backward-char 1) ;; (looking-at "[([{«]"))))) ;; ;; (setq fill-nobreak-predicate 'my-fill-nobreak-predicate) (defun insert-one-quote-or-two () (interactive) (cond ((or (bolp) (not (looking-back "'"))) ;; insert just one ' (self-insert-command 1)) ((save-excursion (backward-char) ;; Skip symbol backwards. (and (not (zerop (skip-syntax-backward "w_"))) (not (looking-back "`")) (or (insert-and-inherit "`") t)))) (t ;; insert `' around following symbol (delete-backward-char 1) (unless (looking-back "`") (insert-and-inherit "`")) (save-excursion (skip-syntax-forward "w_") (unless (looking-at "'") (insert-and-inherit "'")))))) (global-set-key [39] 'insert-one-quote-or-two) ;; string for filling to insert at front of new line (setq fill-prefix " ") ;; automatic line-wrapping beyond that column (setq-default fill-column 76) ;; auto-refilling minor modes (GNUEmacs ;; restrict refilling only when you insert characters, so ;; paragraphs will not get reformatted if the cursor moves over it (try-require 'refill)) (XEmacs ;; `refill.el' does not work with XEmacs (try-require 'maniac)) ;;; ----[ 30.6 (info "(emacs)Case") Conversion Commands ;; enable the use of the commands `downcase-region' and `upcase-region' ;; without confirmation (put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil) ;;; ----[ 30.8 (info "(emacs)Outline Mode") ;; outline mode commands for Emacs (when (try-require 'outline) ;; bind the function `open-line' to `M-o' instead of `C-o' (by default) (global-set-key [(meta o)] 'open-line) ;; bind the outline minor mode functions to an easy to remember prefix key ;; (more accessible than the horrible prefix `C-c @') (setq outline-minor-mode-prefix [(control o)]) ;; makes other `outline-minor-mode' files feel like org files (when (try-require 'outline-magic) (add-hook 'outline-minor-mode-hook (lambda () (define-key outline-minor-mode-map (kbd "<backtab>") 'outline-cycle) (define-key outline-minor-mode-map [(meta left)] 'outline-promote) (define-key outline-minor-mode-map [(meta right)] 'outline-demote) (define-key outline-minor-mode-map [(meta up)] 'outline-move-subtree-up) (define-key outline-minor-mode-map [(meta down)] 'outline-move-subtree-down))))) ;;{{{ Folding Editing ;;; disappeared??? (when (try-require 'folding-XXX) (folding-mode-add-find-file-hook)) (GNUEmacs (when (try-require 'fold-dwim) (global-set-key [(control c) (f) (t)] 'fold-dwim-toggle) (global-set-key [(control c) (f) (h)] 'fold-dwim-hide-all) (global-set-key [(control c) (f) (s)] 'fold-dwim-show-all))) ;;}}} ;;; ----[ 30.9 (info "(emacs)TeX Mode") ;; (Emacs built-in latex-mode, not related to AUCTeX) ;; text-mode-hook (all text modes) ;; {tex-mode,latex-mode,plain-tex-mode}-hook (default Emacs [La]TeX mode) ;; {TeX-mode,LaTeX-mode,plain-TeX-mode}-hook (AUCTeX) ;; ;; Use a saner viewer. Try xpdf, for example. It won't reload automatically, ;; ;; but a quick tap on the R key will force it to reload the file. No need to ;; ;; close & reopen. ;; (setq tex-dvi-view-command "xpdf") ;; (setq tex-dvi-view-command "start \"acrobat\" *") ;; sumatra pdf, gsview ;; A decent view allows you to reread the file while staying on the same page. ;; Others reload the pdf automatically when the file has changed while ;; keeping the current position ;; Support for forward search with PDF files was added. That means you can ;; jump to a place in the output file corresponding to the position in the ;; source file. Currently this only works if you use the pdfsync LaTeX ;; package and xpdf as your PDF viewer. The accuracy is in the... ;;{{{ (info "(auctex)Top") ;; Note -- AUCTeX aliases tex-mode to TeX-mode ;; Note -- invoking `(la)tex-mode' also runs `text-mode-hook' ;;{{{ 2 - (info "(auctex)Installation") of AUCTeX ;; support for LaTeX documents (GNUEmacs (when (try-require 'latex) ;; (try-require 'tex-site) ;; should not be used anymore with current AUCTeX releases ;;}}} ;;{{{ 3 - (info "(auctex)Quick Start") ;; Press `C-c C-c File <Return> <Return>' to run `dvips' ;; (note that the command is `File' and not `Dvips' as one might expect) ;; Press `C-c C-c Print <Return> <Return>' to run `GSview' ;; (also somewhat misleading name) ;; If you want to print the document, do it from GSview. ;;}}} ;;{{{ 5 - (info "(auctex)Advanced Features") ;;{{{ 5.2 (info "(auctex)Completion") ;; if this is non-nil when AUC TeX is loaded, the TeX escape character `\' ;; will be bound to `TeX-electric-macro' (setq TeX-electric-escape t) ;;}}} ;;{{{ 5.4 (info "(auctex)Indenting") ;; number of spaces to add to the indentation for each `\begin' not matched ;; by a `\end' (setq LaTeX-indent-level 4) ;; number of spaces to add to the indentation for `\item''s in list ;; environments (setq LaTeX-item-indent 0) ; -4 ;; number of spaces to add to the indentation for each `{' not matched ;; by a `}' (setq TeX-brace-indent-level 0) ; 4 ;; auto-indentation (suggested by the AUCTeX manual -- instead of adding ;; a local key binding to `RET' in the `LaTeX-mode-hook') (setq TeX-newline-function 'newline-and-indent) ;;}}} ;;}}} ;;{{{ 7 - (info "(auctex)Running TeX and friends") Processors, Viewers and Other Programs ;;{{{ 7.1 Executing (info "(auctex)Commands") ;; use PDF mode by default (instead of DVI) (setq-default TeX-PDF-mode t) ;;}}} ;;{{{ 7.2 (info "(auctex)Viewing") the formatted output ;; list of style options and view options (setq TeX-view-style '(("^epsf$" "ghostview %f") ("^ncs$" "ghostview %f") ("^a5$" "yap %d") ("^landscape$" "yap %d") ("." "yap %d"))) ;; ("^pdf$" "." "xpdf -remote \"%s\" -raise %o %(outpage)") ;; ;; Ça permet de charger (ou recharger) le document dans un xpdf ;; éventuellement déjà lancé et de passer sa fenêtre au-dessus. De plus, ;; si pdfsync est utilisé, ça affiche la page correspondant à l'endroit ;; actuel du curseur dans le document. ;;}}} ;;{{{ 7.3 (info "(auctex)Debugging") Catching the errors ;; don't show output of TeX compilation in other window (setq TeX-show-compilation nil) ;;}}} ;;}}} ;;{{{ 8 - (info "(auctex)Multifile") Documents ;; AUC TeX will will assume the file is a master file itself (setq-default TeX-master t) ;;}}} ;;{{{ 9 - Automatic (info "(auctex)Parsing Files") ;; enable parse on load (if no style hook is found for the file) (setq TeX-parse-self t) ;; enable automatic save of parsed style information when saving ;; the buffer (setq TeX-auto-save t) ;;}}} ;;{{{ 11 - (info "(auctex)Automatic") Customization ;;{{{ 11.1 (info "(auctex)Automatic Global") Customization for the Site ;; directory containing automatically generated TeX information. Must end ;; with a slash (setq TeX-auto-global "~/.emacs.d/auctex-auto-generated-info/") ;;}}} ;;{{{ 11.3 (info "(auctex)Automatic Local") Customization for a Directory ;; directory containing automatically generated TeX information. Must end ;; with a slash (setq TeX-auto-local "~/.emacs.d/auctex-auto-generated-info/"))) ;;}}} ;;}}} ;;}}} ;; get more appropriate values for MikTeX ;; (default configuration of AUCTeX is not the best fit for Windows systems) (when running-ms-windows (try-require 'tex-mik)) ;; Take a look at Peter Gacs's macros for italic, ... (defun my-LaTeX-insert-underscore () "Inserts an underscore depending on the close context (TODO). If needed a backslash is inserted before." (interactive) (insert "\\_")) (defun my-LaTeX-mode-setup () "Customize my LaTeX-mode." (local-set-key "_" 'my-LaTeX-insert-underscore)) (add-hook 'LaTeX-mode-hook 'my-LaTeX-mode-setup) ;; manage cross references, bibliographies, indices, document navigation and ;; a few other things (when (try-require 'reftex) ;; very important package (with bibtex) ;; make a LaTeX reference (to a label) by pressing `C-c )' ;; insert a label by pressing `C-c (' (or `C-(' ;; insert a citation by pressing `C-c [' (or `C-[' ;; hit `C-c ='; the buffer will split into 2 and in the top half you ;; will see a TOC, hitting `l' there will show all the labels and cites. (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode ;; turn all plug-ins on (setq reftex-plug-into-AUCTeX t) ;;; (setq reftex-save-parse-info t) ;; use a separate selection buffer for each label type - so the menu ;; generally comes up faster (setq reftex-use-multiple-selection-buffers t) ;;; (setq reftex-texpath-environment-variables ;;; '("./inp:/PATH/TO/YOUR/TEX/DOCUMENTS//")) ;;; (setq reftex-bibpath-environment-variables ;;; '("/PATH/TO/YOUR/BIB/FILE/")) ) ;;{{{ (info "(preview-latex)Top") (add-hook 'LaTeX-mode-hook 'LaTeX-preview-setup) (autoload 'LaTeX-preview-setup "preview") ;; how to call gs for conversion from EPS (setq preview-gs-command (if running-ms-windows "C:/Program Files/gs/gs8.63/bin/gswin32c.exe" "/usr/bin/gs")) (my-file-executable-p preview-gs-command) ;; scale factor for included previews (setq preview-scale-function 1.2) ;;}}} ;;{{{ nuweb (GNUEmacs (when (try-require 'nuweb) ;; depends on `TeX-lisp-directory' ;; define what's needed to properly call nuweb (make-variable-buffer-local 'outline-prefix-char) (make-variable-buffer-local 'outline-regexp) (make-variable-buffer-local 'outline-level-function) ;; our version of nuweb knows about `@%' comments (setq nuweb-comment-leader "@%") ;; major mode (add-to-list 'auto-mode-alist '("\\.w$" . nuweb-mode)) ;; to get a menu with scraps/files/index entries (add-hook 'nuweb-mode-hook (lambda() (imenu-add-to-menubar "Nuweb"))) ;; recompute all the defs and uses point in the current file (add-hook 'nuweb-mode-hook 'nuweb-compute-d-u) ;; replace the existing `Web' command in order to use PDF mode by ;; default (instead of DVI) -- without writing explicitly the entire ;; `TeX-command-list' in the `.emacs' file (as `customize-variable' ;; would do): (setcdr (assoc "Web" TeX-command-list) '("nuweb %s && pdflatex \"\\nonstopmode\\input{%s}\"" TeX-run-LaTeX nil t :help "Extract files, create LaTeX document, and run `pdflatex' on it")))) ;;}}} ;; http://users.bigpond.net.au/sryoungs/XEmacs/init-files/latex-sy.html ;; = useful examples for XEmacs ;; ;; Having a toolbar only makes sense if we're in a windowing environment. ;; (XEmacs ;; (eval-and-compile ;; (when (device-on-window-system-p) ;; (try-require 'latex-toolbar)))) ;; extra support for outline minor mode (try-require 'out-xtra) ;;; ----[ (info "(emacs-goodies-el)boxquote") ;; quote text with a semi-box (when (try-require 'boxquote) ;; put spaces before my boxquotes (setq boxquote-top-corner " ,") (setq boxquote-side " | ") (setq boxquote-bottom-corner " `") (global-set-key [(control c) (b) (r)] 'boxquote-region) (global-set-key [(control c) (b) (t)] 'boxquote-title)) ;; --8<---------------cut here---------------start------------->8--- ;; In Gnus, you can mark some region with enclosing tags by pressing ;; `C-c M-m' (`message-mark-inserted-region') or by clicking on ;; `<menu-bar> <Message> <Insert Region Marked>'. ;; --8<---------------cut here---------------end--------------->8--- ;; interface to the festival speech synthesizer system (when (locate-library "festival-XXX") (autoload 'say-minor-mode "festival" "Menu for using Festival." t) (say-minor-mode t) (setq auto-mode-alist (append '(("\\.festivalrc$" . scheme-mode)) auto-mode-alist)) (setq festival-program-name "/usr/bin/festival")) ;; phonetic spelling (try-require 'phonetic) (message "30 Commands for Human Languages... Done") ;;}}} ;;{{{ --[ 31 Editing (info "(emacs)Programs") ]----------------------------- (message "31 Editing Programs...") ;;; ----[ 31.1 Major Modes for (info "(emacs)Program Modes") (autoload 'awk-mode "cc-mode" "Awk editing mode." t) ;; TODO or use a new AWK Mode for AWK files, rather than the older mode ;; contained in the file `awk-mode.el' ;; [from http://people.smu.edu/zwang/awk-mode.html] ;; (try-require 'graphviz-dot-mode) ;; Have a look at: ;; o http://cedet.sourceforge.net for C/C++ development, ;; o http://common-lisp.net/project/slime for Common Lisp development, ;; o http://jdee.sunsite.dk/ for Java programs. ;; Emacs tool for ELISP code analysis (to keep overview of the ;; function calls and dependecies between functions/variables): ;; byte-compile-generate-call-tree ;; Also http://whome.phys.au.dk/~harder/who-calls.el ;;; ----[ 31.3 (info "(emacs)Program Indent")ation ;; From (info "(ccmode)Indentation Commands"): ;; Changing the "hanginess" of a brace and then reindenting, will not ;; move the brace to a different line. For this, you're better off ;; getting an external program like GNU `indent', which will rearrange ;; brace location, amongst other things. ;; turn on auto-fill mode in Lisp modes (add-hook 'lisp-mode-hook 'turn-on-auto-fill) (add-hook 'emacs-lisp-mode-hook 'turn-on-auto-fill) ;; use one of several different indentation styles for C-like modes (setq c-default-style '((awk-mode . "stroustrup") (other . "stroustrup"))) (defun my-c-mode-setup () "Customize my c/c++-mode and awk-mode." ;; auto-indentation (local-set-key [(return)] 'newline-and-indent) ; (control m) (local-set-key [(linefeed)] 'newline)) ; (control j) (add-hook 'c-mode-hook 'my-c-mode-setup) (add-hook 'c++-mode-hook 'my-c-mode-setup) (add-hook 'awk-mode-hook 'my-c-mode-setup) (defun back-to-indentation-or-beginning () (interactive) (if (/= (point) (line-beginning-position)) (beginning-of-line) (back-to-indentation))) (defun align-with-spaces (beg end) "Align selected using only spaces for whitespace." (interactive "r") (let ((indent-tabs-mode nil)) (align beg end))) ;;; ----[ 31.4 Commands for Editing with (info "(emacs)Parentheses") ;; find matching parenthesis (% command in vim) (defun match-paren (arg) "Go to the matching parenthesis, if on parenthesis; otherwise, insert `%'." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) (global-set-key [(%)] 'match-paren) ;; highlight matching parenthesis (when (try-require 'paren) (GNUEmacs (show-paren-mode t) (setq show-paren-ring-bell-on-mismatch t)) (XEmacs (paren-set-mode 'paren))) ;; if the matching paren is offscreen, show the matching line in the echo ;; area + many other useful things (when window-system (when (try-require 'mic-paren) ;; activating (paren-activate))) ;; from hall@grumpy.nl.nuwc.navy.mil ;; goto-matching-paren ;;; ----[ 31.5 Manipulating (info "(emacs)Comments") (XEmacs (defun my-comment-region (beg end) "Comment a region of text." (interactive "r") (comment-region beg end) (global-set-key [(meta \;)] 'my-uncomment-region)) (defun my-uncomment-region (beg end) "Uncomment a region of text." (interactive "r") (comment-region beg end -1) (global-set-key [(meta \;)] 'my-comment-region)) (global-set-key [(meta \;)] 'my-comment-region)) ;;; ----[ 31.7 (info "(emacs)Hideshow") minor mode ;; You can have block-oriented folding in programming modes, for instance. ;; See also the library `foldout' and `hs-minor-mode', for instance, in the ;; Emacs manual. ;; `hs-minor-mode.el' collapses code for a lot of languages, not only lisp. ;; outline is line-oriented and does not distinguish end-of-block. ;; hideshow distinguishes end-of-block. ;; `outline-minor-mode.el' is used to collapse lisp code (i.e., to see in the ;; buffer just the definition of a function instead of the whole body) (add-hook 'emacs-lisp-mode-hook (lambda () (hs-minor-mode 0))) ;; (add-hook 'emacs-lisp-mode-hook ;; (lambda () (hs-minor-mode 1) ;; (hs-hide-all) ;; (set (make-variable-buffer-local 'my-hs-hide) t))) (defvar my-hs-hide t "Current state of hideshow for toggling all.") (defun my-toggle-hideshow-all () "Toggle hideshow all." (interactive) (set (make-variable-buffer-local 'my-hs-hide) (not my-hs-hide)) (if my-hs-hide (hs-hide-all) (hs-show-all))) (global-set-key [(control c) (@) (@)] 'my-toggle-hideshow-all) (global-set-key [(control c) (@) (h)] 'hs-hide-block) (global-set-key [(control c) (@) (s)] 'hs-show-block) (global-set-key [(control c) (@) (space)] 'hs-show-block) ;;; ----[ 31.8 (info "(emacs)Symbol Completion") ;; `M-/' runs the command `dabbrev-expand' by default ;; Expand previous word "dynamically". Expands to the most recent, preceding ;; word for which this is a prefix. (global-set-key [(control \`)] 'dabbrev-expand) ;; `C-M-/' runs the command `dabbrev-completion' ;; Completion on current word. Like `M-/' but finds all expansions in the ;; current buffer and presents suggestions for completion. ;; expand text trying various ways to find its expansion (when (try-require 'hippie-exp) ;; list of expansion functions tried (in order) by `hippie-expand' (setq hippie-expand-try-functions-list '(try-expand-dabbrev ; from current buffer try-expand-dabbrev-visible ; from visible parts of all windows try-expand-dabbrev-all-buffers ; from all other buffers try-expand-dabbrev-from-kill try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-complete-lisp-symbol-partially try-complete-lisp-symbol try-expand-whole-kill)) ;; expand-function (defun my-hippie-expand (arg) ;; called with a positive prefix `P', it jumps directly to the `P'-th ;; `try-function' (interactive "P") ;; `hippie-expand' does not have a customization-feature (like ;; `dabbrev-expand') to search case-sensitive for completions. So we ;; must set `case-fold-search' temporarily to nil! (let ((old-case-fold-search case-fold-search)) (setq case-fold-search nil) (hippie-expand arg) (setq case-fold-search old-case-fold-search))) (global-set-key [(control tab)] 'my-hippie-expand)) ;; (global-set-key (kbd "M-/") 'hippie-expand) ;; I recommend you split the key binding of those two command. ;; I binding TAB yas/expand, and binding M-/ hippie-expand. ;; So yas/expand don't conflict with hippie/expand. ;; predictive abbreviation expansion ("à la IntelliSense") (when (try-require 'pabbrev) ;; don't print messages while scavenging on idle timer (setq pabbrev-idle-timer-verbose nil) ;; tab completion with continual, as-you-type feedback (global-pabbrev-mode)) ;; > I'm trying to have code completion in Emacs, but i don't know what to ;; > do. In eclipse, when we writing a java code line, for example: ;; > System.out., we do C^SPACE to show a window with several methods ;; > associated (printl, print,etc). ;; > I would like to have something similar in Emacs. Can anybody help me? ;; Try M-TAB with cursor on the symbol; is that what you are looking for? ;;;----[ 31.9 (info "(emacs)Glasses") minor mode ;; face to be put on capitals of an identifier looked through glasses (setq glasses-face 'bold) ;; string to be displayed as a visual separator in unreadable identifiers (setq glasses-separator "") ;;;----[ Add-Ons ;; Collection of Emacs Development Environment Tools ;; whether to use the byte-code cache when loading (setq bcc-enabled nil) ;; ;; list of directories, where each directory is the root of some project ;; (setq semanticdb-project-roots '("/home/sva/emacs/site-lisp")) ;; turn on all "useful" features (setq semantic-load-turn-useful-things-on t) ;; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (when (try-require 'idle-require) (setq idle-require-idle-delay 10) (idle-require-mode)) (GNUEmacs ;; setup complete development environment ;; TODO (idle-require 'cedet) (eval-after-load "cedet" '((progn (message ">>> cedet 1") ;; Enabling various SEMANTIC minor modes. See semantic/INSTALL for more ;; ideas. ;; Select one of the following: ;; o This is the default. Enables the database and idle reparse ;; engines (semantic-load-enable-minimum-features) ;; o This enables some tools useful for coding, such as summary ;; mode imenu support, and the semantic navigator <<< (semantic-load-enable-code-helpers) ;; o This enables even more coding tools such as the nascent ;; intellisense mode decoration mode, and stickyfunc mode (plus ;; regular code helpers) (semantic-load-enable-guady-code-helpers) ;; o This turns on which-func support (plus all other code ;; helpers) (semantic-load-enable-excessive-code-helpers) ;; ;; This turns on modes that aid in writing grammar and developing ;; ;; semantic tool. It does not enable any other features such as code ;; ;; helpers above. ;; (semantic-load-enable-semantic-debugging-helpers) ;; getting rid of semantic.caches (setq semanticdb-default-save-directory "~/.emacs.d/semantic-cache") (my-make-directory-yes-or-no semanticdb-default-save-directory) ;; fix the max CPU problem on latest Emacs snapshots (setq semantic-idle-scheduler-idle-time 432000) (message ">>> cedet 2") ;; Emacs Code Browser (provides views of directories and files) ;; see http://platypope.org/yada/emacs-demo/ (when (try-require 'ecb-autoloads) ; load all available autoloads of ECB (message ">>> cedet 3") ;; ECB version (setq ecb-options-version "2.32") ;; don't show tip of the day at start time of ECB (setq ecb-tip-of-the-day nil) ;; toggle activation of ecb (global-set-key [(control c) (e)] 'ecb-minor-mode)) (message ">>> cedet 5"))) )) ;; If you've installed CEDET and ECB, eassist is worth trying out: ;; http://www.mail-archive.com/gnu-emacs-sources@gnu.org/msg00292.html ;; ;; It uses CEDET to provide a handy symbols browser for the current file, ;; that narrows down the list as you type substrings. Tastes differ, but I ;; for one really like this. ;; whether to use the byte-code cache when loading (setq bcc-enabled t) (message "31 Editing Programs... Done") ;;}}} ;;{{{ --[ 32 (info "(emacs)Building") Compiling and Testing Programs ]------ (message "32 Compiling and Testing Programs...") ;; >> It's possible to see, while we are programming, if we did a mistake. In ;; >> eclipse, when we do an error, for example, forget a ; , an underline ;; >> appears in the line indicating that something is wrong. It's possible to ;; >> have something like this in Emacs? ;; > ;; > There's a CWarn mode for C and C++, but I don't know about similar ;; > features for Java. Anyone? ;; flymake can compile in the background and colorize lines with errors/warnings ;; http://flymake.sourceforge.net/ ;; http://www.emacswiki.org/cgi-bin/wiki/JdeeFlymake (try-require 'flymake) ;;; ----[ 32.1 Running (info "(emacs)Compilation")s under Emacs ;; make (f9) : -in src make ;; clean (C-f9) : rm -vf src/emacs-23.* etc/DOC* && make clean ;; stop (C-f8) : -e kill-compilation ;; run (f8) : src/emacs ;; --- ;; configure : ./configure ;; install : echo root-pass | sudo -S make install ;; You don't need a Makefile to perform simple tasks, because Make knows a ;; lot of built in rules out of the box. For example, to compile a `.c' ;; source file `foo.c' into a program `foo', all you need is say ;; "make -k foo", and Make will do it even without a Makefile. ;; invoke a compiler with the same command as in the last invocation of ;; `compile' (global-set-key [(f9)] 'recompile) ;; scroll the `*compilation*' buffer window to follow output as it appears (setq compilation-scroll-output t) ;; number of lines in a compilation window (setq compilation-window-height (* 2 5)) ;; ;; I also don't like that the compilation window sticks around after a ;; ;; successful compile. After all, most of the time, all I care about ;; ;; is that the compile completed cleanly. Here's how I make the ;; ;; compilation window go away, only if there was no compilation ;; ;; errors: ;; (setq compilation-finish-function ;; (lambda (buf str) ;; (if (string-match "exited abnormally" str) ;; ;; there were errors ;; (message "Compilation errors, press C-x ` to visit") ;; ;; no errors, make compilation window go away in 0.5 sec ;; (run-at-time 0.5 nil 'delete-windows-on buf) ;; (message "NO COMPILATION ERRORS!")))) ;; (add-hook 'c-mode-hook ;; (lambda () ;; (set (make-local-variable 'compile-command) ;; (format "make %s" ;; (file-name-sans-extension ;; (file-name-nondirectory buffer-file-name)))))) ;; ;; Just set the CC=gcc and CFLAGs="-Wall -O3" environment variables, and ;; voila! (defvar make-clean-command "make clean all" "*Command used by the `make-clean' function.") (defun make-clean (&optional arg) "Run a make clean." (interactive "P") (require 'compile) ;; needed for compile-internal (if arg (setq make-clean-command (read-string "Command: " make-clean-command))) (save-some-buffers (not compilation-ask-about-save) nil) (compile-internal make-clean-command "No more errors")) (global-set-key [(shift f9)] 'make-clean) ;;; ----[ 32.2 (info "(emacs)Compilation Mode") ;; display the next compiler error message (global-set-key [(f10)] 'next-error) ;; display the previous compiler error message (global-set-key [(shift f10)] 'previous-error) ;; display the first compiler error message (global-set-key [(control f10)] 'first-error) ;; highlight and parse the whole compilation output as soon as it arrives (setq compile-auto-highlight t) ;; Some code that will make it so the background color of the lines ;; that gcc found errors on, should be in another color. (defvar all-overlays ()) (defun delete-this-overlay(overlay is-after begin end &optional len) (delete-overlay overlay)) (defun highlight-current-line () (interactive) (setq current-point (point)) (beginning-of-line) (setq beg (point)) (forward-line 1) (setq end (point)) ;; Create and place the overlay (setq error-line-overlay (make-overlay 1 1)) ;; Append to list of all overlays (setq all-overlays (cons error-line-overlay all-overlays)) (overlay-put error-line-overlay 'face '(background-color . "pink")) (overlay-put error-line-overlay 'modification-hooks (list 'delete-this-overlay)) (move-overlay error-line-overlay beg end) (goto-char current-point)) (defun delete-all-overlays () (while all-overlays (delete-overlay (car all-overlays)) (setq all-overlays (cdr all-overlays)))) (defun highlight-error-lines (compilation-buffer, process-result) (interactive) (delete-all-overlays) (condition-case nil (while t (next-error) (highlight-current-line)) (error nil))) (setq compilation-finish-function 'highlight-error-lines) ;;; ----[ 32.4 (info "(emacs)Grep Searching") under Emacs ;; ignore case distinctions in the default grep command ;;(if (my-file-executable-p "~/bin/wcgrep") (setq grep-command "grep -n -i -e ") ;; grep + emacs 22 + cygwin does not follow file links ;; try adding "-nH" to your grep options. ;; The commands lgrep and rgrep are somehow more user-friendly than the M-x ;; grep command. The word at point can be captured using the command ;; (thing-at-point 'word). So you may try: ;; ;; (defun my-grep () ;; "look for word at point in files ending by .cpp and .h ;; recursively starting from the work directory" ;; (interactive) ;; (rgrep (thing-at-point 'word) "*.cpp *.h" "~/work")) ;; ;; (global-set-key [(control shift f)] 'my-grep) ;;; ----[ 32.6 Running (info "(emacs)Debuggers") Under Emacs ;; > Enable debug-on-error via 'M-x toggle-debug-on-error', then start ;; > flyspell-mode again and examine the error. If that does not work, try ;; > edebug. Open the file where flyspell-mode is defined. Reeval the ;; > function with 'C-u C-M-x' and again, start flyspell-mode. Now you are ;; > in edebug-mode. Hit Space till you get the error. Press 'i' to enable ;; > debugging of the called function after point. ;; ;; The cursor has to be inside the flyspell-mode function for this to work. ;; (C-M-x evals the current function , with prefix it also installs the ;; debug routines.) ;; Alternatively this should enable edebug on all forms in the current buffer: ;; M-x edebug-all-defs ;; M-x eval-buffer ;;{{{ Debugging Mercury programs ;; 1. Put these lines in your .emacs file: ;; (setq mercury-dir (getenv "MERCURY_DIR")) ;; (load-file (concat mercury-dir "/lib/mercury/elisp/gud.el")) ;; (setq mdb-command-name "bash.exe mdb ./mas_server.exe -c ;; ../online/mas_server/mas_config_local.xml -d ../data")) ;; 2. To start the debugger, open a file in your build directory, ;; e.g. build/Makefile ;; 3. Run M-x and then type mdb ;; 4. At the prompt you should see the command from the .emacs file: ;; "bash.exe mdb ./mas_server.exe -c ;; ../online/mas_server/mas_config_local.xml -d ../data" ;; Change if necessary and hit the 'Return' key ;; 5. Find your bugs. ;; Known problems: ;; - tab completion doesn't work ;;}}} ;;{{{ Debugging Lisp programs ;; Emacs has the basic debugger/stack trace, but it also has edebug, which ;; is very powerful, for the more complex situation. ;; You can cause the debugger to be called at a certain point in your ;; program by writing the expression `(debug)' at that point. To do this, ;; visit the source file, insert the text `(debug)' at the proper place, ;; and type `C-M-x'. ;; `c' Exit the debugger and continue execution ;; `d' Continue execution, but enter the debugger the next time any Lisp ;; function is called. (define-key emacs-lisp-mode-map [(control x) (x)] 'edebug-eval-top-level-form) (define-key emacs-lisp-mode-map [(control x) (x)] 'edebug-defun) (autoload 'edebug-eval-top-level-form "edebug") (setq edebug-global-prefix "\C-xX") (add-hook 'cl-load-hook (lambda () (add-hook 'edebug-setup-hook (lambda () (load-library "cl-specs"))))) ;; toggle whether to enter Lisp debugger when an uncaught error is signaled ;; (global-set-key [(super c) (d)] 'toggle-debug-on-error) ;;}}} ;;; ----[ 32.7 (info "(emacs)Executing Lisp") Expressions (require 'lisp-mode) ;; nuke and reevaluate an elisp buffer (try-require 'nukneval) ;; show the function arglist or the variable docstring in the echo area (GNUEmacs (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode) (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)) (add-hook 'emacs-lisp-mode-hook 'my-elisp-extra-keys) (defun my-elisp-extra-keys () ;; auto-indentation (define-key emacs-lisp-mode-map "\C-m" 'newline-and-indent) (define-key emacs-lisp-mode-map "\C-cc" 'nuke-and-eval)) ;;; ----[ 32.9 (info "(emacs)Lisp Eval") Expressions ;; enable the use of the command `eval-expression' without confirmation (put 'eval-expression 'disabled nil) ;; enhanced eval-expression command (when (try-require 'eval-expr) (eval-expr-install)) ;;; ----[ 32.10 (info "(emacs)Lisp Interaction") Buffers ;; to evaluate a non-interactive command, simply use IELM! ;; interaction mode for Emacs Lisp (autoload 'ielm "ielm" "Start an inferior Emacs Lisp session" t) ;;; ----[ 32.11 Running an (info "(emacs)External Lisp") ;; Just as in C, C++, Java, Perl, Python, etc, Lisp code is kept in ;; files. All the normal editing operations are performed on files. In this ;; respect, hacking in Lisp is like hacking in any other language that you ;; are used to. What's different is that what you are hacking is a running ;; Lisp program. When you edit a function definition or add a new one, you ;; compile it into a running program. There is no compile, link, run, debug ;; cycle as you know it from C or Java. ;; Ponder that for a minute. ;; When you fix a bug in a C function, you have to recompile, relink, and ;; reload your program before you can test the fix. You don't do that in ;; Lisp. You make the fix and then go straight to testing it. This process ;; can be even faster than fixing a bug in a scripting language like Perl. ;; see http://svn.peadrop.com/emacs/lisp/lisp-config.el ;; superior lisp inferior mode extension (when (try-require 'slime-TODO) ;; indentation (slime-setup) (add-hook 'lisp-mode-hook (lambda () (slime-mode t))) (add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t))) ;; Gnu CLISP - Inferior Lisp Mode & ILISP (switches for ANSI & no banner) (defvar clisp-dir (if running-ms-windows "e:/vmware-home/bin/win32/clisp-2.31/full/" "/usr/bin")) (defvar clisp-exe (if running-ms-windows (concat clisp-dir "lisp.exe") (concat clisp-dir "/" "clisp"))) ;; optionally, specify the lisp program you are using. Default is "lisp". ;; include the full linking set with `-K full' (setq inferior-lisp-program (if running-ms-windows (concat clisp-exe " -B " clisp-dir " -M " clisp-dir "lispinit.mem" " -ansi -q") (concat clisp-exe " -B " clisp-dir " -ansi -q"))) ;; "clisp -K full" ;; connect automatically to my lisp when opening a lisp file (defun cliki:start-slime () (unless (slime-connected-p) (save-excursion (slime)))) (add-hook 'slime-mode-hook 'cliki:start-slime) ;; automatically show documentation for code near the point (add-hook 'slime-mode-hook (lambda () (slime-autodoc-mode t))) ;; ;; GNU CLISP - http://clisp.cons.org/ ;; (defun clisp-start () ;; (interactive) ;; (shell-command (concat "c:/bin/clisp-2.32/full/lisp.exe " ;; "-B c:/bin/clisp-2.32/full/ " ;; "-M c:/bin/clisp-2.32/full/lispinit.mem " ;; "-i c:/usr/home/.slime.lisp " ;; "-ansi -q&")))) ; Functions and key bindings for getting Emacs to interact with GCL. ; Thomas R. Ioerger, Dept of Computer Science, Texas A&M University ; see http://www.cs.tamu.edu/faculty/ioerger/emacs-gcl.html for more details (global-set-key "\C-t" (make-keymap)) (defun run-gcl () (interactive) (split-window) (other-window 1) (inferior-lisp "gcl")) (defun gcl-debug-quit () (interactive) (comint-send-string "*inferior-lisp*" ":q\C-M")) (defun gcl-quit () (interactive) (comint-send-string "*inferior-lisp*" "(bye)\C-M")) (defun gcl-eval-buffer () (interactive) (set-mark 0) (goto-char (point-max)) (lisp-eval-region 1 (point)) (exchange-point-and-mark)) (global-set-key "\C-tl" 'run-gcl) (global-set-key "\C-te" 'lisp-eval-defun) (global-set-key "\C-tw" 'switch-to-lisp) ; split screen! (global-set-key "\C-tq" 'gcl-debug-quit) (global-set-key "\C-tb" 'gcl-eval-buffer) (global-set-key "\C-tx" 'gcl-quit) ; commands (after prefix of control-t) ; l = start lisp ; e = eval current expression ; w = switch to lisp buffer ; q = quit from debugger back to top-level ; b = eval buffer ; x = kill lisp process ) (message "32 Compiling and Testing Programs... Done") ;;}}} ;;{{{ --[ 33 (info "(emacs)Maintaining") Programs ]------------------------- (message "33 Maintaining Programs...") ;;; ----[ 33.1 (info "(emacs)Change Log")s ;; don't make a new entry, when the last entry was made by you and on the ;; same date (setq add-log-always-start-new-record nil) ;; adds the file's version number to the change log entry (setq change-log-version-info-enabled t) ;;; ----[ 33.3 (info "(emacs)Tags") Tables ;; First of all, you must build a `TAGS' file (which keeps the symbols from ;; your project, by scanning all the source and header files with the ;; `etags' command). ;; list of file names of tags tables to search (setq tags-table-list '( "/home/sva/TAGS" ;;; "/usr/share/texmf-texlive/tex/latex/TAGS" )) ;; For example, you can have a "make TAGS" Makefile target to do this for ;; you: ;; ;; TAGS: ;; rm -f TAGS ;; find $$(pwd) \( -name \*.el \ ;; -o -name \*.[chCH] \ ;; \) -print | etags - ;; ;; You can create a tags file by using `M-x compile RET tags RET'. ;; Alternatively, (try-require 'sure-tags) ;; will make sure that tags file exists (and builds it if it doesn't), ;; allowing you to first rebuild the tags file or specify a new one when the ;; search fails. ;; After this, you can use a tags table with the command ;; `M-x visit-tags-table RET'. ;; You can search for *definitions* of tags that match your regexp, by using ;; `M-x find-tag' (bound to `M-.'). ;; To continue searching for next alternate definition, use `C-u M-.'. ;; To jump back, use `M-*'. (defun find-next-tag () (interactive) (find-tag nil t)) ;; select from multiple tags (when (try-require 'etags-select) ;; do a `find-tag-at-point', and display all exact matches (global-set-key [(meta \?)] 'etags-select-find-tag-at-point)) ;; find the definition of the Emacs Lisp function or variable near point (GNUEmacs (find-function-setup-keys)) ;; You can search for *occurrences* of tags that match you regexp on all ;; files in tags table, by using `M-x tags-search RET'. ;; To continue searching for next match, use `M-,'. ;; There is a cscope interface for emacs. I recommend it. tags are ;; extremely limited imo. cscope does a much better, if slower, job. ;;; ----[ 33.4 Merging Files with (info "(emacs)Emerge") ;; merge file diffs under Emacs control (try-require 'emerge) ;; `M-x smerge-mode RET' ;; That does not automatically select regions but provides convenient key ;; bindings to navigate between conflicts and to choose the A or B variant (message "33 Maintaining Programs... Done") ;;}}} ;;{{{ --[ 34 (info "(emacs)Abbrevs") ]-------------------------------------- (message "34 Abbrevs...") ;;; ----[ 34.3 Controlling (info "(emacs)Expanding Abbrevs") ;; I am aware of packages such as `ELSE', `tempo', `skeleton', some of which ;; do similar things. However, I believe this package does some things ;; better than these other packages. ;; It's particularly notable for having the easiest syntax of all, making it ;; possible to add new snippets without careful programming, and also very ;; nice navigation within the inserted text. ;; Check out the demo: http://www.bloomington.in.us/~brutt/msf-abbrev.html (GNUEmacs (when (try-require 'msf-abbrev) ;; ensure abbrev mode is always on (setq-default abbrev-mode t) ;; do not bug me about saving my abbreviations (setq save-abbrevs nil) ;;; ;; load up modes I use ;;; (require 'cc-mode) ;;; (require 'perl-mode) ;;; (require 'cperl-mode) ;;; (require 'sh-script) ;;; (require 'shell) ;;; (require 'tex-site) ;; I use AUCTeX ;;; (require 'latex) ;; needed to define LaTeX-mode-hook under AUCTeX ;;; (require 'tex) ;; needed to define TeX-mode-hook under AUCTeX ;; load up abbrevs for these modes (require 'msf-abbrev) (setq msf-abbrev-verbose t) ;; optional (global-set-key [(control c) (l)] 'msf-abbrev-goto-root) ;; FIXME conflict with `C-c a a' (global-set-key [(control c) (a)] 'msf-abbrev-define-new-abbrev-this-mode) (setq msf-abbrev-root "~/emacs/site-lisp/mode-abbrevs/") (when (file-directory-p msf-abbrev-root) (msf-abbrev-load)))) ;; There're some difference from msf-abbrev. For example, msf-abbrev doesn't ;; support mirror fields and transformations. It also doesn't support ;; multiple snippet with same name. (GNUEmacs (when (try-require 'yasnippet) ;; not yasnippet-bundle (yas/initialize) ;; FIXME (yas/load-directory "/home/sva/Media/Download/emacs/site-lisp/yasnippet-0.4.0/"))) ;;; ----[ 34.7 (info "(emacs)Dabbrev Customization") ;; preserve case when expanding the abbreviation (setq dabbrev-case-replace nil) (message "34 Abbrevs... Done") ;;}}} ;;{{{ --[ 35 Editing (info "(emacs)Picture") ]------------------------------ (message "35 Editing Pictures...") (message "35 Editing Pictures... Done") ;;}}} ;;{{{ --[ 36 (info "(emacs)Sending Mail") (with Gnus) ]--------------------- (message "36 Sending Mail...") ;; perform Caesar ciphers (when (try-require 'rot13) (defvar rot13-translate-table (let ((str (make-string 127 0)) (i 0)) (while (< i 127) (aset str i i) (setq i (1+ i))) (setq i 0) (while (< i 26) (aset str (+ i ?a) (+ (% (+ i 13) 26) ?a)) (aset str (+ i ?A) (+ (% (+ i 13) 26) ?A)) (setq i (1+ i))) str) "String table for rot 13 translation.") (defun rot13-string (string) "Return Rot13 encryption of STRING." (with-temp-buffer (insert string) (rot13-region (point-min) (point-max)) (buffer-string))) (defun rot13-region (start end) "Rot13 encrypt the region between START and END in current buffer." (interactive "r") (translate-region start end rot13-translate-table)) ;; full name of this user (setq user-full-name "Fabrice Niessen") ;; full mailing address of this user ;; (used in MAIL envelope FROM, and to select the default personality ID) (setq user-mail-address (concat (rot13-string "sav") "@" "missioncriticalit.com"))) (when (try-require 'gnus) ;; Gnus startup file name (setq gnus-init-file "~/.gnus") (global-set-key [(control f5)] (lambda () (interactive) (let ((buffer (get-buffer "*Group*"))) (if buffer (switch-to-buffer buffer) (call-interactively 'gnus) (gnus-demon-init))))) (setq mail-user-agent 'gnus-user-agent) (XEmacs (setq toolbar-mail-reader 'gnus))) ;;{{{ rs-info ;; to insert links such as `(info "(message)Insertion Variables")' (when (try-require 'rs-info) (autoload 'rs-info-insert-current-node "rs-info" "Insert reference to current Info node using STYPE in buffer." t nil) (autoload 'rs-info-boxquote "rs-info" "Yank text (from an info node), box it and use current info node as title." t nil) (autoload 'rs-info-reload "rs-info" "Reload current info node." t nil) (autoload 'rs-info-insert-node-for-variable "rs-info" "Insert a custom style info node for the top level form at point." t nil) (defalias 'boxquote-info 'rs-info-boxquote)) ;;}}} (message "36 Sending Mail... Done") ;;}}} ;;{{{ --[ 37 (info "(emacs)Rmail") Reading Mail (with Gnus) ]--------------- (message "37 Reading Mail with Gnus...") (when (try-require 'gnus) ;; reading mail with Gnus (setq read-mail-command 'gnus)) (message "37 Reading Mail with Gnus... Done") ;;}}} ;;{{{ --[ 38 (info "(emacs)Dired"), the Directory Editor ]------------------ (message "38 Dired, the Directory Editor...") ;; emulate insert-directory completely in Emacs Lisp (when (try-require 'ls-lisp) ;; disable the case sensitive sort of file names (setq ls-lisp-ignore-case t) ;; sort directories first in any ordering (setq ls-lisp-dirs-first t) ;; use ISO 8601 dates (on MS-Windows) (setq ls-lisp-format-time-list '("%Y-%m-%d %H:%M" "%Y-%m-%d %H:%M")) ;; use localized date/time format (setq ls-lisp-use-localized-time-format t)) ;; directory-browsing commands (when (try-require 'dired) ;; switches passed to `ls' for Dired ;; (setq dired-listing-switches "-h") ;; "-alt --time-style=long-iso") ;; try to guess a default target directory (setq dired-dwim-target t) ;; enable the use of the command `dired-find-alternate-file' ;; without confirmation (put 'dired-find-alternate-file 'disabled nil) ;; recursive deletes allowed, after asking for each directory at top level (setq dired-recursive-deletes 'top) ;; copy recursively without asking (setq dired-recursive-copies 'always) ;; extra Dired functionality (try-require 'dired-x) ; You can jump to the Dired buffer corresponding to the current ; buffer by pressing `C-x C-j' (`dired-jump'). ; If in Dired already, pop up a level and goto old directory's line. ; `dired-x' also has a feature to "guess" the right shell command. ;; extensions to Dired (when (try-require 'dired+) ;;; FIXME does not work (at least when pressing on `..' or `^') ;;; ;; accessing directories in Dired will reuse the buffer ;;; (toggle-dired-find-file-reuse-dir 1) ;; reuse the current Dired buffer to visit another directory ;; (limit Dired to 1 single buffer) (when (try-require 'dired-single) (define-key dired-mode-map [return] 'joc-dired-single-buffer) (define-key dired-mode-map [mouse-1] 'joc-dired-single-buffer-mouse) (define-key dired-mode-map "^" (function (lambda nil (interactive) (joc-dired-single-buffer ".."))))) ) ;;; ;; dired-sort-map.el ;;; ;; press s then s, x, t or n to sort by Size, eXtension, Time or Name ;;; (require 'dired-sort-map) ) (add-hook 'dired-load-hook (lambda () (load "dired-column-widths.el"))) (defun my-browse-dir () "Open the current directory in your OS's file manager." (interactive) (let ((dir-as-string (file-name-as-directory (expand-file-name "."))) (file-manager (cond (running-ms-windows "explorer") (t "/usr/lib/kde4/bin/dolphin")))) ;; `nautilus --no-desktop', `gnome-open' ;; or `xdg-open' (in `xdg-utils') (start-process "browse" nil file-manager dir-as-string))) (defun dired-open-externally () "Open the current directory in your OS's file manager." (interactive) (let ((fileobject (dired-get-file-for-visit))) (start-process "dired-external" nil "xdg-open" fileobject) (message "Opening file %s" fileobject))) (define-key dired-mode-map (kbd "e") 'dired-open-externally) ;;; ----[ 38.16 (info "(emacs)Dired and Find") ;; search for files with names matching a wild card pattern and Dired the ;; output (global-set-key [(control c) ?1] 'find-name-dired) ;; search for files with contents matching a wild card pattern and Dired the ;; output (global-set-key [(control c) ?2] 'find-grep-dired) ;; run grep via find, with user-specified arguments (global-set-key [(control c) ?3] 'grep-find) ;; ignore `.svn' and `CVS' directories (setq grep-find-command (concat "find . \\( -path '*/.svn' -o -path '*/CVS' \\) -prune -o -type f -print0" " | xargs -0 -e grep -i -n -e ")) ;; (setq igrep-find-prune-clause "-type d -wholename \"*.svn*\"") ;;; ----[ 38.17 Editing the (info "(emacs)Wdired") Buffer ;; Wdired mode is great for renaming (a lot of) files in a directory, as it ;; allows editing the Dired buffer like a text file, using all the power of ;; Emacs. That is, one can use keyboard macros, search and replace, ;; rectangle mode (great for adding prefixes to file names), flip mode bits ;; with the mouse, etc.! ;; in Dired, put a Dired buffer in a mode in which filenames are editable (when (try-require 'wdired) (autoload 'wdired-change-to-wdired-mode "wdired") (add-hook 'dired-load-hook (lambda () (define-key dired-mode-map [(shift e)] 'wdired-change-to-wdired-mode)))) ;;; ----[ Add-Ons ;; Dired stuff to open files a la Windows (from Howard Melman): ;; execute file using windows associations (GNUEmacs (when running-ms-windows (defun dired-is-dir() (file-directory-p (dired-get-filename))) (defun dired-execute-file (&optional arg) (interactive "P") (mapcar #'(lambda (file) (w32-shell-execute "open" (convert-standard-filename file))) (dired-get-marked-files nil arg))) (defun dired-mouse-execute-file (event) "In Dired, execute the file or goto directory name you click on." (interactive "e") (set-buffer (window-buffer (posn-window (event-end event)))) (goto-char (posn-point (event-end event))) (if (dired-is-dir) (dired-find-file) (dired-execute-file))) (global-set-key [?\C-x mouse-2] 'dired-mouse-execute-file) (defun hrm-dired-mode-hook () "Hook run when entering Dired mode." (define-key dired-mode-map [(shift x)] 'dired-execute-file) (define-key dired-mode-map [M-down-mouse-1] 'dired-mouse-execute-file)) (add-hook 'dired-mode-hook 'hrm-dired-mode-hook))) ;;{{{ dired-find-w3m ;; add a binding "w" -> `dired-find-w3m' to Dired (defun dired-find-w3m () (interactive) "In Dired, visit (with find-w3m) the file named on this line." (w3m-find-file (file-name-sans-versions (dired-get-filename) t))) (eval-after-load "dired" '(progn (define-key dired-mode-map "w" 'dired-find-w3m))) ;;}}} ;; On top of the traditional ways, there's also an add-on called Extview ;; which opens files using outside programs, such as XPDF, based on their ;; extension. It does this both from Dired and with `find-file'. One ;; advantage is that using the traditional ! switch with Dired locks up ;; Emacs until you close the other program. Extview does not and leaves ;; Emacs free for continued used. ;; >> how to associate external programs to known file types ;; >> in Dired. For example, associating ;; > ;; > Hi, i use `extview.el', it's work fine. ;; > It reads in a `.mailcap' file. ;; If you need to open a file in Emacs that has an extension that Extview ;; will open in another viewer, like HTML, you use `find-file-literally' to ;; open it in Emacs. (try-require 'extview) ;; emulate famous ms-dos file browser (norton commander) (GNUEmacs (autoload 'nc "nc" "Emulate MS-DOG file shell" t)) ;; See news "Opening html-File in Dired with w3m" for extra info ;; provide the same facility of `ls --color' inside Emacs (try-require 'dircolors) ;; view PDF/PostScript/DVI files in Emacs (when (try-require 'doc-view) ;; DPI resolution used to render the documents ;; `doc-view-enlarge' (`+') works fine (setq doc-view-resolution 96) ;; DPI your screen supports (setq doc-view-display-size 96)) ;; You can open the *text* of the current doc in a new buffer, by pressing ;; `C-c C-t' in doc-view-mode ;; Another option, without doc-view, is `! pdtotext ? - RET' ;; two-pane file manager for Emacs based on Dired and inspired by MC (try-require 'sunrise-commander) (message "38 Dired, the Directory Editor... Done") ;;}}} ;;{{{ --[ 39 The (info "(emacs)Calendar/Diary") ]--------------------------- (message "39 The Calendar and the Diary...") ;;; ----[ 39.1 (info "(emacs)Calendar Motion") ;; years must be written in full (setq abbreviated-calendar-year nil) (setq diary-abbreviated-year-flag nil) ;; interpret the date 1/2/1990 as February 1, 1990 (setq european-calendar-style t) ; before using any calendar or diary command ;; week in the calendar begins on Monday (setq calendar-week-start-day 1) ;; mark all visible dates that have diary entries (setq mark-diary-entries-in-calendar t) ;; (add-hook 'initial-calendar-window-hook 'mark-diary-entries) ;; marks the current date, by changing its face (add-hook 'today-visible-calendar-hook 'calendar-mark-today) ;; bind calendar to `C-c c' (global-set-key [(control c) (c)] 'calendar) ;;; ----[ 39.2 (info "(emacs)Scroll Calendar") ;; fix foolish calendar-mode scrolling (add-hook 'calendar-load-hook (lambda () (setq mark-holidays-in-calendar t) (define-key calendar-mode-map [(>)] 'scroll-calendar-left) (define-key calendar-mode-map [(<)] 'scroll-calendar-right) (define-key calendar-mode-map [(control x) (>)] 'scroll-calendar-left) (define-key calendar-mode-map [(control x) (<)] 'scroll-calendar-right))) ;;; ----[ 39.7 Times of (info "(emacs)Sunrise/Sunset") (setq calendar-latitude [50 87 north]) (setq calendar-longitude [4 71 east]) (setq calendar-location-name "Leuven, BE") ;; (setq calendar-latitude [43 41 north]) ;; (setq calendar-longitude [6 81 east]) ;; (setq calendar-location-name "Boulouris, FR") ;;; ----[ 39.10 The (info "(emacs)Diary") ;; The Emacs diary keeps track of appointments or other events on a daily ;; basis, in conjunction with the calendar. To use the diary feature, you ;; must first create a "diary file" containing a list of events and their ;; dates. (when (try-require 'diary-lib) ;; copy the diary entries into a special buffer (also display the diary ;; when I do `M-x diary') (add-hook 'diary-display-hook 'fancy-diary-display) ;; TODO sort each day's diary entries by their time of day? (add-hook 'diary-display-hook 'sort-diary-entries) (add-hook 'list-diary-entries-hook 'sort-diary-entries t) ;; allow `#includes' in `~/diary' (add-hook 'list-diary-entries-hook 'include-other-diary-files) ;; desk calendar style extensions to Emacs' Calendar/Diary (when (try-require 'cal-desk-calendar) (add-hook 'diary-display-hook 'fancy-schedule-display-desk-calendar t)) (if (file-exists-p "~/.diary") ;; generate the diary window for 4 days starting with the current date (diary 4)) ;; How do you arrange the entries of diary? Can they be automatically ;; arranged according to date and not just according to when they were ;; entered into the diary? ) ;;; ----[ 39.11 (info "(emacs)Appointments") ;; enable appointment notification, several minutes beforehand (add-hook 'diary-hook 'appt-make-list) ;;; ----[ 39.12 (info "(emacs)Importing Diary") Entries ;; for Gnus to be able to work with the Outlook meeting requests (try-require 'icalendar) ;;; ----[ 39.14 Summing (info "(emacs)Time Intervals") ;; http://emacswiki.org/cgi-bin/wiki/TimeClock ;; check Org's capabilities in this area: (info "(org)Clocking work time") ;; if you want to log your daily schedules for review, you need ;; `schedule.el' and `timeclock.el' to record your daily works ;; `worklog' also keeps track on my working hours, and it is very simple ;; tracker is started if there is an open project a reasonable guess can be ;; made as to when to mark it as closed. Each session can have multiple ;; comments associated with it, in which you can mark accomplishments or ;; whatever. It will generate informal daily summary reports and a report of ;; total hours for a particular billee. ;; keep track of how much you work (when (try-require 'timeclock) ;; start fresh counting (don't take into account previous days) (setq timeclock-relative nil) (setq timeclock-file "~/.timeclock/default.log") (when (file-exists-p timeclock-file) (global-set-key [(control x) (t) (i)] 'timeclock-in) (global-set-key [(control x) (t) (o)] 'timeclock-out) (global-set-key [(control x) (t) (c)] 'timeclock-change) ;;{{{ timeclock-x ;; whether to use the byte-code cache when loading (setq bcc-enabled nil) (if (try-require 'timeclock-x) (progn ;; bind interactive timeclock functions to a `C-x t' prefix (timeclock-setup-keys) ;; ask if the user wants to clock out before exiting Emacs (add-hook 'kill-emacs-query-functions 'timeclock-query-out) ;; ask the user if they wish to clock in (timeclock-query-in)) ;; clock in, recording the current time moment in the timelog (timeclock-in)) ;; whether to use the byte-code cache when loading (setq bcc-enabled t) ;;}}} )) ;;; ----[ 39.15 (info "(emacs)Advanced Calendar/Diary Usage") ;; show all the holidays that would appear in a complete Christian calendar (setq all-christian-calendar-holidays t) ;; remove some holidays (setq general-holidays nil) ; get rid of too U.S.-centric holidays (setq hebrew-holidays nil) ; get rid of religious holidays (setq islamic-holidays nil) ; get rid of religious holidays (setq oriental-holidays nil) ; get rid of Oriental holidays (setq bahai-holidays nil) ; get rid of Baha'i holidays ;; add Belgian holidays (setq local-holidays '( (holiday-fixed 01 01 "New Year's Day") (holiday-fixed 02 14 "Valentine's Day") (holiday-fixed 04 01 "April Fools' Day") (holiday-fixed 05 01 "Labor Day") (holiday-fixed 07 21 "Independence Day") (holiday-fixed 08 15 "Assumption") (holiday-fixed 10 31 "Halloween") (holiday-fixed 11 01 "Toussaint") (holiday-fixed 11 11 "Armistice 1918") (holiday-fixed 12 25 "Christmas") ;; holidays with variable dates (holiday-float 5 0 2 "Mother's Day") (holiday-float 6 0 3 "Father's Day"))) ;; (easter-monday) ;; mark dates of holidays in the calendar (setq mark-holidays-in-calendar t) ;;; ----[ Add-Ons ;; Getting Things Done ;;{{{ (info "(org)Top") Mode ;; After all the configuration has been done, you can easily manage your ;; daily work and tasks with `org-mode'. ;; Press `C-c a a' to jump you to this week's task page from anywhere. ;; Use `M-x planner-create-task-from-buffer' to link buffers to your daily ;; planner files. Soon you'll find that your daily work files are ;; conveniently linked together in daily tasks. Just use it to improve your ;; efficiency. ;; Comme `planner', `org-mode' peut s'intégrer/interfacer avec d'autres ;; modes comme `bbdb', `remember', `gnus', `vm', `calendar', `diary' et ;; `planner' ;; ;; Le gros avantage par rapport à `planner' ? Il fait partie depuis quelques ;; temps déjà de la distribution standard GNU Emacs (pas besoin donc de ;; l'installer à part). Son second point fort est la facilité d'utilisation. ;; C'est vraiment très simple à prendre en main et la documentation permet ;; de vite s'y retrouver en cas de pépin. ;; ;; Une des raisons de la complexité de Planner provient du fait que ;; `planner' est étroitement associé à `emacs-wiki', et que `emacs-wiki' a ;; basculé vers Muse. (when (try-require 'org) (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) (define-key global-map [(control c) (l)] 'org-store-link) (define-key global-map [(control c) (a)] 'org-agenda) ;;{{{ 2 (info "(org)Document Structure") ;; don't switch to OVERVIEW at startup (setq org-startup-folded nil) ;;}}} ;;{{{ 5 (info "(org)Hyperlinks") ;; TODO check if org-directory exists ;; directory with org files (used by the hooks for `remember.el') (setq org-directory "~/Personal/Notes/") ;; a mode for quickly jotting down things to remember (when (try-require 'remember) ;; default target for storing notes (setq org-default-notes-file "~/Personal/Notes/Remember.org") ;;; Pb with Org-mode 6.01d ;;; ;; setup `remember.el' for use with Org-mode ;;; (org-remember-insinuate) ;; key bindings (global-set-key [(control c) (r)] 'remember) (global-set-key [(control meta r)] 'org-remember) ;; templates for the creation of remember buffers (setq org-remember-templates '(("Buffer" ?b "* %a\n\n%i%?%!" org-default-notes-file "Buffer" nil) ("Org" ?o "* %a\n\n%i%?" org-default-notes-file "Org" nil) ("Infos" ?i "* %a\n\n%i%?%!" org-default-notes-file "Infos" nil)))) ; The %a in each template will be replaced by a link to the Gnus ; message. The %! means "immediatly store this note without ; further prompt", which is very handy for quick storing of ; emails. ;;}}} ;;{{{ 6 (info "(org)Timestamps") ;; insert a special time stamp each time a TODO entry is marked done (setq org-log-done t) ;;}}} ;;{{{ 7 Timeline and (info "(org)Agenda Views") ;; set which files to search for TODOs and scheduled items ;; (avoiding hidden files) (setq org-agenda-files (directory-files "~/Personal/Notes/" t "^[^\\.].*\\.org$")) ;; include entries from the Emacs diary into Org-mode's agenda (setq org-agenda-include-diary t) ;; generate the agenda buffer for this week (org-agenda-list) (delete-other-windows)) ;;}}} ;; open my work org file (defun my-open-org-work () "Opening `~/Personal/Notes/Work.org'." (interactive) (find-file "~/Personal/Notes/Work.org")) (global-set-key [(shift f2)] 'my-open-org-work) ;; open my home org file (defun my-open-org-home () "Opening `~/Personal/Notes/Home.org'." (interactive) (find-file "~/Personal/Notes/Home.org")) (global-set-key [(control f2)] 'my-open-org-home) ;;}}} ;;{{{ Muse ;; How to create web page by Emacs and Muse? ;; http://www.xshi.org/notes/WebPage.html ;; load generic module (GNUEmacs (when (try-require 'muse) ;; outline-style faces (try-require 'outline) ;; coloring/font-lock module (try-require 'muse-colors) ;; authoring mode (try-require 'muse-mode) ;; publishing styles (try-require 'muse-html) ; (X)HTML (try-require 'muse-latex) ; LaTeX/PDF (try-require 'muse-texinfo) ; Info (try-require 'muse-docbook) ; DocBook ;;; (try-require 'muse-blosxom) ; blosxom module (try-require 'muse-wiki) ; Wiki support (try-require 'muse-xml) ; XML support ;; publish files in projects (try-require 'muse-project) (add-hook 'muse-mode-hook 'my-muse-extra-keys) (defun my-muse-extra-keys () (define-key muse-mode-map [mouse-1] 'muse-follow-name-at-mouse) (define-key muse-mode-map [mouse-2] 'muse-follow-name-at-mouse-other-window)) ;; (add-hook 'emacs-wiki-mode-hook ;; (lambda () ;; (define-key emacs-wiki-mode-map (kbd "C-c C-h") 'emacs-wiki-preview-html) ;; (define-key emacs-wiki-mode-map (kbd "C-c C-c") 'emacs-wiki-preview-source) ;; (define-key emacs-wiki-mode-map (kbd "C-c C-v") 'emacs-wiki-change-project) ;; (define-key emacs-wiki-mode-map (kbd "C-c i") 'emacs-wiki-insert-contents) ;; (define-key emacs-wiki-mode-map (kbd "C-c C-n") 'emacs-wiki-unlink-toggle) ;; )) ;; (define-key muse-mode-map (kbd "C-c C-p") 'ywb-muse-publish-project) ;; (define-key muse-mode-map (kbd "C-c C-c") 'ywb-muse-preview-source) ;; (define-key muse-mode-map (kbd "C-c C-j") 'ywb-muse-preview-html) ;; (define-key muse-mode-map (kbd "C-c C-m") 'ywb-muse-preview-with-w3m) ;; listing of all directories that should be published with Muse ;; (customize style to use, directory, header and footer files, etc.) (setq muse-project-alist `( ("My-Muse-Public-Website" ("~/Public/Websites/Muse/source/" :default "index") (:base "xhtml" :path "~/Public/Websites/Muse/publish/" :header "~/Public/Websites/Muse/source/header.html" :footer "~/Public/Websites/Muse/source/footer.html")) ;;; ("Piaffer" ;;; (,@(muse-project-alist-dirs "~/piaffer") :default "index") ;;; ,@(muse-project-alist-styles ;;; "~/piaffer" ;;; "/ftp:jean@bokuro:piaffer" ;;; "hpia")) ("My-Muse-Private-Website" ("~/Personal/Websites/Muse/source/" :default "index") (:base "xhtml" :path "~/Personal/Websites/Muse/publish/" :header "~/Personal/Websites/Muse/source/header.html" :footer "~/Personal/Websites/Muse/source/footer.html")))) (defcustom muse-footer-date-format "%Y-%m-%d" ; " @ %H:%M" "Format of current date for `muse-html-footer'. This string must be a valid argument to `format-time-string'." :type 'string :group 'muse-publish) ;; FIXME rewrite properly! (defun my-muse-generate-nav-menu () (let* ((html-menu "") (cur-path-muse (muse-current-file)) (cur-path-html (replace-regexp-in-string "\\.muse" ".html" cur-path-muse))) (setq html-menu "<ul>\n") (while nav-menu (progn (if (not (listp (cdr (car nav-menu)))) (setq html-menu (concat html-menu "<li><a href=\"" (cdr (car nav-menu)) "\" title=\"" (caar nav-menu) "\"" (if (string-match (concat ".*" (cdr (car nav-menu)) "$") cur-path-html) " class=\"current\"" "") ">" (caar nav-menu) "</a></li>\n")) (progn (setq html-menu (concat html-menu "<li>" (caar nav-menu) "\n" "<ul>\n")) (setq nav-submenu (cdr (car nav-menu))) (while nav-submenu (setq html-menu (concat html-menu "<li><a href=\"" (cdr (car nav-submenu)) "\" title=\"" (caar nav-submenu) "\"" (if (string-match (concat ".*" (cdr (car nav-submenu)) "$") cur-path-html) " class=\"current\"" "") ">" (caar nav-submenu) "</a></li>\n")) (setq nav-submenu (cdr nav-submenu))) (setq html-menu (concat html-menu "</ul>\n</li>\n")))) (setq nav-menu (cdr nav-menu)))) (setq html-menu (concat html-menu "</ul>")) html-menu)) ;; default Emacs buffer encoding to use in published files (setq muse-html-encoding-default 'utf-8) ;; default HTML meta charset to use if no translation is found in ;; `muse-html-encoding-map' (setq muse-html-charset-default "utf-8") (defun tidy-do () "Run the HTML Tidy program on the current buffer." (interactive) (shell-command-on-region (point-min) (point-max) (concat "tidy" " -config ~/.tidyrc" " --error-file ./temp-tidy-errors") t) (delete-file "./temp-tidy-errors") (message "Buffer tidy'ed")) ;;; ;; TODO Check that tidy is in PATH ;;; ;; run in the buffer to be published ;;; (eval-after-load "tidy" ;;; '(progn (add-hook 'muse-after-publish-hook 'tidy-do))) ;; See `org-publish-escript.el' for htmlize of code ;; How to preview in a browser? ;; ;; Press `C-c C-v' (`browse-url-of-buffer'). You can also get a textual ;; preview by pressing `C-c TAB' (`sgml-tags-invisible'), which will hide ;; all the tags. Press `C-c TAB' again to show tags. ;;Auto Publish when muse saved ;;(eval-after-load "muse-mode" ;; (add-hook 'after-save-hook ;; (lambda () ;; (when (planner-derived-mode-p 'muse-mode) ;; (muse-project-publish nil))) ;;)) ;; nil t)) )) ;; You can create and publish a blog with `org-mode' ;; http://dto.freeshell.org/e/org-blog.el ;; See `muse-project-copy-files' with `rsync' ;; ;; automatically update web copy ;; (write-region ;; (point-min) (point-max) ;; "/scorpios@ftp.scorpioscotedazur.com:/public_html/emacs/mydotemacs.el") ;; or `sitecopy' ;; muse-mode on *.txt files, if a #title or sect. header is on top 4 lines (add-hook 'text-mode-hook (lambda () (unless (or (eq major-mode 'muse-mode) (not (stringp buffer-file-truename))) (when (equal (file-name-extension buffer-file-truename) "txt") (save-excursion (goto-line 5) (if (re-search-backward "\* [A-Z][a-z]+.*\\|#title " 1 t) (muse-mode))))))) ;;}}} (message "39 The Calendar and the Diary... Done") ;;}}} ;;{{{ --[ 40 (info "(emacs)Gnus") ]----------------------------------------- (message "40 Gnus...") ;;; ----[ Insidious (info "(bbdb)Top") ;; !! The file bbdb-com uses old-style backquotes !! (when (try-require 'bbdb) ;; coding system used for reading and writing `bbdb-file' (BBDB 2.35+) (setq bbdb-file-coding-system 'utf-8) ;; ensure `~/.bbdb' never becomes non utf-8 again (it is defined with ;; `defconst', so it is reset whenever `bbdb.el' is loaded) (add-hook 'bbdb-load-hook (lambda () (setq bbdb-file-coding-system 'utf-8))) ;;{{{ (info "(bbdb)Installation") ;; enable the various package-specific BBDB functions (bbdb-initialize 'gnus 'message) ;; add bindings for the default keys to Gnus and configure Gnus to ;; notify the BBDB when new messages are loaded (required if the BBDB is ;; to be able to display BBDB entries for messages displayed in Gnus) (add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus) ;; add a binding for `M-TAB' to Message mode ;; this will enable completion of addresses based on BBDB records (add-hook 'gnus-startup-hook 'bbdb-insinuate-message) ;; customizable completion in message headers ;; (to avoid conflict between `flyspell' and `BBDB') (try-require 'message-x) ;;}}} ;;{{{ (info "(bbdb)Interfaces") ;; mail aliases (local mailing lists) (add-hook 'message-setup-hook 'bbdb-define-all-aliases) ;; always use full name when sending mail ;; (even if User Name has an address of the form <user.name@somedomain>) (setq bbdb-dwim-net-address-allow-redundancy t) ;; no popup on auto-complete (setq bbdb-completion-display-record nil) ;; completion is done across the set of all full-names and user-ids (setq bbdb-completion-type nil) ;;}}} ;;{{{ (info "(bbdb)Reader-specific Features") ;; marking posters with records in the BBDB (setq bbdb/gnus-summary-mark-known-posters t) ;; mark authors in the Summary Buffer who have records in the BBDB (setq bbdb/gnus-summary-known-poster-mark "B") ;; display the poster's name from the BBDB if we have one (setq bbdb/gnus-summary-prefer-real-names t) ;; replace the information provided in the From header with data from ;; the BBDB if we have one (setq bbdb/gnus-summary-prefer-bbdb-data t) (setq bbdb/gnus-summary-show-bbdb-names t) ;;}}} ;;{{{ (info "(bbdb)Options")Options ;; You can add the author of a mail or posting to the BBDB ;; by hitting `:' ;; name of the file which contains your personal database (setq bbdb-file "~/.bbdb") ;; no default area code to use when prompting for a new phone number (setq bbdb-default-area-code nil) ;; default country to use if none is specified (setq bbdb-default-country "") ;; disable syntax-checking of telephone numbers (setq bbdb-north-american-phone-numbers-p nil) ;; restoration of the window configuration (setq bbdb-electric-p t) ;; don't display a continuously-updating BBDB window while in GNUS ;; (setq bbdb-use-pop-up nil) ;; desired number of lines in a GNUS pop-up BBDB window (setq bbdb-pop-up-target-lines 1) ;; default display layout (setq bbdb-display-layout 'multi-line) ;; default display layout pop-up BBDB buffers (setq bbdb-pop-up-display-layout 'one-line) ;; omit creation-date and timestamp from BBDB display (setq bbdb-display-layout-alist '((one-line (order . (phones notes)) (name-end . 24) (toggle . t) (omit . (net AKA mail-alias gnus-private creation-date timestamp))) (multi-line (indention . 14) (toggle . t) (omit . (AKA creation-date timestamp))) (pop-up-multi-line (indention . 14)))) ;; allow cycling of email addresses while completing them (setq bbdb-complete-name-allow-cycling t) ;; save the database without asking (any time it would ask) (setq bbdb-offer-save 'auto) ;; automatically add some text to the notes field of the BBDB record (add-hook 'bbdb-notice-hook 'bbdb-auto-notes-hook) ;; capture auto-notes (setq bbdb-auto-notes-alist ;; organization `(("Organization" (".*" Organization 0)) ;; mailer ("User-Agent" (".*" mailer 0 t)) ;; t = overwrite ("X-Mailer" (".*" mailer 0 t)) ("X-Newsreader" (".*" mailer 0 t)) ;; X-Face bitmaps of the people ("x-face" ,(list (concat "[ \t\n]*\\([^ \t\n]*\\)" "\\([ \t\n]+\\([^ \t\n]+\\)\\)?" "\\([ \t\n]+\\([^ \t\n]+\\)\\)?" "\\([ \t\n]+\\([^ \t\n]+\\)\\)?") 'face "\\1\\3\\5\\7")))) ;;}}} ;;{{{ (info "(bbdb)Utilities") ;; search the BBDB (global-set-key [(control f11)] 'bbdb) ;; search the BBDB by regexp (when (try-require 'bbdb-query) (global-set-key [(control f11)] 'bbdb-query)) ;; use BBDB to store PGP preferences (when (try-require 'bbdb-pgp) ;; what to do if the recipient is not in the BBDB (setq bbdb/pgp-default-action nil))) ;; BBDB SCHDPLUS Filter (when (try-require 'bbdb-ldif) ;; You can output the `*BBDB*' buffer in SCHDPLUS .CSV format ;; by invoking `M-x bbdb-output-schdplus' (load "bbdb-schdplus") (setq bos-filename "~/bbdb-schdplus.csv")) ;;}}} (message "40 Gnus... Done") ;;}}} ;;{{{ --[ 41 Running (info "(emacs)Shell") Commands from Emacs ]------------ (message "41 Running Shell Commands from Emacs...") ;; You're debugging bash code? I normally use `mode-compile.el' for ;; this. Basically, it runs bash with lots of debug output. ;; See `w32-settings.el' for more! ;; quote process arguments to ensure correct parsing on Windows (setq w32-quote-process-args t) ;; for single shell commands (setq shell-file-name "bash") ;; must be in the `PATH' ;; TODO check bash exists (in other words, check it is installed) ;; use `shell-file-name' as the default shell (when (try-require 'env) (setenv "SHELL" shell-file-name)) ;; name of shell used to parse TeX commands (GNUEmacs (setq TeX-shell shell-file-name)) (XEmacs ;; for the `preview-latex' package (setq TeX-shell "C:/Program Files/Emacs/emacs/bin/cmdproxy.exe")) ;; switch used to have the shell execute its command line argument ;; (`/c' does not work with XEmacs) (setq shell-command-switch "-c") ;; shell argument indicating that next argument is the command (setq TeX-shell-command-option shell-command-switch) ;; for the interactive (sub)shell (setq explicit-shell-file-name shell-file-name) ;; regexp to match prompts in the inferior shell (setq shell-prompt-pattern (concat "^" (system-name) " [^ ]+ \\[[0-9]+\\] ")) ;; general command interpreter in a window stuff (when (try-require 'comint) ;; `M-s' `comint-next-matching-input' ;; `M-r' `comint-previous-matching-input' ;; `M-n' `comint-next-input' ;; `M-p' `comint-previous-input' ;; `C-up' `last command' ;; don't add input matching the last on the input ring (setq-default comint-input-ignoredups t) ;; input to interpreter causes (only) the selected window to scroll (setq-default comint-scroll-to-bottom-on-input "this") ;; output to interpreter causes (only) the selected window to scroll (setq-default comint-scroll-to-bottom-on-output "this") ;; show the maximum output when the window is scrolled (setq-default comint-scroll-show-maximum-output t) ;; ignore short commands as well as duplicates (setq comint-min-history-size 5) (make-variable-buffer-local 'comint-min-history-size) (setq-default comint-input-filter (function (lambda (str) (and (not (string-match "\\`\\s *\\'" str)) (> (length str) comint-min-history-size))))) ;; functions to call after output is inserted into the buffer (setq-default comint-output-filter-functions ;; go to the end of buffer '(comint-postoutput-scroll-to-bottom)) ;; get rid of the ^M characters (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m) ;; prompt in the minibuffer for password and send without echoing ;; (for example, with `su' command) (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt) ;; use the `up' and `down' arrow keys to traverse through the previous ;; commands (defun my-shell-mode-setup () "Customize my shell-mode." (local-set-key '[(up)] 'comint-previous-input) (local-set-key '[(down)] 'comint-next-input)) (add-hook 'shell-mode-hook 'my-shell-mode-setup)) ;; translate ANSI escape sequences into faces (GNUEmacs (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)) ;; run a telnet session from within an Emacs buffer (when (try-require 'telnet) ;; program to run to open a telnet connection ;; simple public domain telnet client for Windows console ;; (from Igor Milavec) (setq telnet-program (if running-ms-windows (concat my-site-lisp-directory "../bin/telnet.exe") "/usr/bin/telnet")) ;; open a network login connection to a host (defun telnet (host) "Open a network login connection to host named HOST (a string). Communication with HOST is recorded in a buffer `*telnet-HOST*'. Normally input is edited in Emacs and sent a line at a time." (interactive "sOpen telnet connection to host: ") (let* ((comint-delimiter-argument-list '(?\ ?\t)) (name (concat "telnet-" (comint-arguments host 0 nil) )) (buffer (get-buffer (concat "*" name "*"))) process) (cond ((string-equal system-type "windows-nt") (setq telnet-new-line "\n"))) (if (and buffer (get-buffer-process buffer)) (pop-to-buffer (concat "*" name "*")) (pop-to-buffer (make-comint name telnet-program nil host)) (setq process (get-buffer-process (current-buffer))) (set-process-filter process 'telnet-initial-filter) (accept-process-output process) (telnet-mode) (setq comint-input-sender 'telnet-simple-send) (setq telnet-count telnet-initial-count))))) ;; (term "bash") ;; If you do `M-x term', `bash' is offered as the default as well. ;; ;; Need a good terminal emulation for applications that are interactive with ;; your terminal, in the same way `top' is working or `man' ... or `less' ;; ;; Try also to use `M-x ansi-term' that is much better than `term': with M-x ;; term, you can run only one shell; with ansi-term you can start more than ;; one (*ansi-term*<2>, *ansi-term*<3>). ;; In GNU Emacs 23, there's now support for serial port access. The new ;; command `serial-term' starts an interactive terminal on a serial port. ;; run an inferior shell, with I/O through buffer `*shell*' (if running-ms-windows (global-set-key [(control !)] 'shell) (global-set-key [(control !)] 'term)) (when (try-require 'multishell) (global-set-key [(control !)] 'multishell)) (GNUEmacs ;; add support for e-scripts in Emacs ;; See: (find-eev "eev-rctool" "new_block_emacs") ;; (find-eev-update-links) ;; I want to set up my own keymaps for eev-mode (setq eev-mode-map (make-sparse-keymap)) (define-key eev-mode-map "\M-E" 'ee-eval-last-sexp) ; C-x C-e (define-key eev-mode-map (kbd "M-e") 'eek-eval-sexp-eol) (define-key eev-mode-map "\M-e" 'ee-eval-sexp-eol) ; C-e C-x C-e (define-key eev-mode-map [(control shift f3)] 'eeb-default) ; f3 (define-key eev-mode-map [(control shift f8)] 'eepitch-this-line) ; f8 (define-key eev-mode-map [(control shift f9)] 'eechannel-this-line) ; f9 (define-key eev-mode-map [(control shift f12)] 'eesteps-do-step) ; f12 (define-key eev-mode-map "\M-h\M-f" 'find-efunction-links) ; in eev-insert.el (when (try-require 'eev-all) ; (find-eev "eev-all.el") (eev-mode 1))) (message "41 Running Shell Commands from Emacs... Done") ;;}}} ;;{{{ --[ 42 Using (info "(emacs)Emacs Server") ]--------------------------- (message "42 Using Emacs as a Server...") ;; use Emacs as a server ;; on GNU/Linux, you should use `server-start'/`emacsclient' ;; `Emacsclient' is now as well available under EmacsW32 (GNUEmacs ;; (setq server-host "Rabbit") ;; (setq server-use-tcp t) ;; start the Emacs server (server-start)) ;; > I'd like to be able to reconnect to the running Emacs process and have ;; > it display on my X server at home. Is this possible? ;; ;; In the X11 forwarded ssh shell: ;; ;; $ emacsclient -e "(make-frame-on-display \"$DISPLAY\")" ;; ; Fri Feb 1 13:06:41 2008 - sva Replace `$DISPLAY' by `:0.0' ;; From VM: ;; > ssh 10.0.2.2 -f emacsclient --eval '"(make-frame-on-display \":0.0\")"' ;; rebind `C-x C-c' to `delete-frame'? (message "42 Using Emacs as a Server... Done") ;;}}} ;;{{{ --[ 43 (info "(emacs)Printing") Hard Copies ]------------------------- (message "43 Printing Hard Copies...") ;; print Emacs buffer on line printer ;; for {lpr,print}-{buffer,region} (when (try-require 'lpr) ;; name of program for printing a file (setq lpr-command "enscript") ;; list of strings to pass as extra options for the printer program (setq lpr-switches (list "--font=Courier8" "--header-font=Courier10" (format "--header=%s" (buffer-name)))) ;; name of a printer to which data is sent for printing (setq printer-name (if running-ms-windows "//PRINT-SERVER/C510_APS" t))) ;; print text from the buffer as PostScript (when (try-require 'ps-print) (let ((gsprint-program "C:/Program Files/Ghostgum/gsview/gsprint.exe")) (my-file-executable-p gsprint-program) (if (and gsprint-program (file-executable-p gsprint-program)) (progn ;; name of a local printer for printing PostScript files ;; adjusted to run Ghostscript (setq ps-printer-name t) ;; name of program for printing a PostScript file ;; tell Emacs where ghostscript print utility is located (setq ps-lpr-command gsprint-program) ;; list of extra switches to pass to `ps-lpr-command' ;; tell Ghostscript to query which printer to use (setq ps-lpr-switches '("-query"))) (progn (setq ps-printer-name "//PRINT-SERVER/LexmarkC510") (setq ps-lpr-command "") (setq ps-lpr-switches '("raw")))) ;; size of paper to format for (setq ps-paper-type 'a4) ;; print in portrait mode (setq ps-landscape-mode nil) ;; number of columns (setq ps-number-of-columns 1))) ;; generate and print a PostScript image of the buffer (GNUEmacs (when running-ms-windows (w32-register-hot-key [snapshot]) ; override `Print Screen' globally used ; as a hotkey by Windows (global-set-key [(snapshot)] 'ps-print-buffer-with-faces))) (XEmacs (setq toolbar-print-function 'ps-print-buffer-with-faces)) (global-set-key [(meta p)] 'ps-print-buffer-with-faces) (message "43 Printing Hard Copies... Done") ;;}}} ;;{{{ --[ 47 (info "(emacs)Sorting") Text ]--------------------------------- (message "47 Sorting Text...") ;; key binding (global-set-key [(meta \#)] 'sort-lines) (message "47 Sorting Text... Done") ;;}}} ;;{{{ --[ 48 (info "(emacs)Narrowing") ]------------------------------------ (message "48 Narrowing...") ;; enable the use of the command `narrow-to-region' without confirmation (put 'narrow-to-region 'disabled nil) (message "48 Narrowing... Done") ;;}}} ;;{{{ --[ 49 (info "(emacs)Two-Column") Editing ]--------------------------- (message "49 Two-Column Editing...") (message "49 Two-Column Editing... Done") ;;}}} ;;{{{ --[ 50 (info "(emacs)Editing Binary Files") ]------------------------- (message "50 Editing Binary Files...") (message "50 Editing Binary Files... Done") ;;}}} ;;{{{ --[ 51 (info "(emacs)Saving Emacs Sessions") ]------------------------ (message "51 Saving Emacs Sessions...") (when (try-require 'saveplace) ;; automatically save place in each file (setq-default save-place t) ;; default value for all buffers ;; name of the file that records `save-place-alist' value (setq save-place-file (convert-standard-filename "~/.emacs.d/places.txt")) ;; do not make backups of master save-place file (setq save-place-version-control "never")) (message "51 Saving Emacs Sessions... Done") ;;}}} ;;{{{ --[ 52 (info "(emacs)Recursive Edit")ing Levels ]--------------------- (message "52 Recursive Editing Levels...") (message "52 Recursive Editing Levels... Done") ;;}}} ;;{{{ --[ 53 (info "(emacs)Emulation") ]------------------------------------ (message "53 Emulation...") (message "53 Emulation... Done") ;;}}} ;;{{{ --[ 54 (info "(emacs)Hyperlinking") and Navigation Features ]--------- (message "54 Hyperlinking and Navigation Features...") ;; I use an excellent package called `webjump' to store my bookmarks. It ;; also has provisions for generating search strings for the search sites as ;; well. ;;{{{ HTML Tidy (try-require 'tidy) ;; For other modes (like `html-helper-mode') simply change the variables ;; `html-mode-hook' and `html-mode-map' to whatever is appropriate e.g. (defun my-html-helper-mode-setup () "Customize my html-helper-mode." (tidy-build-menu html-helper-mode-map) (local-set-key [(control c) (control c)] 'tidy-buffer) (setq sgml-validate-command "tidy")) (add-hook 'html-helper-mode-hook 'my-html-helper-mode-setup) ;;}}} ;;{{{ pass a URL to a WWW browser ;; display the current buffer in the default Windows WWW browser (try-require 'browse-url) (autoload 'browse-url-at-mouse "browse-url") ;; default browser started when you click on some URL in the buffer (if window-system (if running-ms-windows (setq browse-url-browser-function 'browse-url-default-windows-browser) (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program (executable-find "firefox"))) (setq browse-url-browser-function 'w3m-browse-url)) ;; ;; shortcut to view the current file in browser ;; (define-key html-mode-map [(control c) (control v)] 'browse-url-of-buffer) ;; (setq browse-url-browser-function ;; '(("file:///usr/share/doc/hyperspec/" . w3m-browse-url) ;; ("emacswiki.org" . w3m-browse-url) ;; ("lispdoc.com" . w3m-browse-url) ;; ( "." . browse-url-firefox))) ;; that let me use w3m for emacswiki/common lisp documentation and ;; Firefox otherwise. ;;}}} ;;{{{ Emacs-w3m ;; Emacs/W3 is dead, long live Emacs-w3m ;; Emacs-w3m is a terrific text-based web and file browser ;; You can obtain a snapshot from ;; http://cvs.namazu.org/emacs-w3m.tar.gz?view=tar ;; `w3m-browse-url' asks Emacs-w3m to browse a URL. ;; When JavaScript is needed or the "design" is just too bad, use another ;; browser: you can open the page in your graphical browser (at your own ;; risk) by hitting `M' (`w3m-view-url-with-external-browser'). ;; For what "risk" means, please see: (info "(emacs-w3m)Gnus") ;; (for win32, use the Cygwin version of the executable) (setq w3m-command (executable-find "w3m")) ;; (my-file-executable-p w3m-command) ;; TODO should trap when w3m-command is nil (when (and w3m-command (file-executable-p w3m-command)) (when (try-require 'w3m) ;;{{{ 5.1 General Variables ;; send referers only when both the current page and the target page are ;; provided by the same server (setq w3m-add-referer 'lambda) ;; home page (setq w3m-home-page "http://www.emacswiki.org/") ;; number of steps in columns used when scrolling a window horizontally (setq w3m-horizontal-shift-columns 1) ; 2 ;; proxy settings (when (string= (upcase (system-name)) "PC3701") (eval-after-load "w3m" '(setq w3m-command-arguments (nconc w3m-command-arguments '("-o" "http_proxy=http://proxy:8080")))) (setq w3m-no-proxy-domains '("local.com" "sysdoc"))) ;;}}} ;;{{{ 5.2 Image Variables ;; always display images (setq w3m-default-display-inline-images t) ;; show favicon images if they are available (setq w3m-use-favicon t) ;;}}} ;;{{{ 5.4 Cookie Variables ;; ask user whether accept bad cookies or not (setq w3m-cookie-accept-bad-cookies 'ask) ;; list of trusted domains (setq w3m-cookie-accept-domains '("google.com" "google.be" "yahoo.com" ".yahoo.com" "groups.yahoo.com" "www.dyndns.org")) ;; enable cookies (to use sites such as Gmail) (setq w3m-use-cookies t) ;;}}} ;;{{{ 5.14 Other Variables (defun w3m-new-tab () (interactive) (w3m-copy-buffer nil nil nil t)) ;; fix inappropriate key bindings (define-key w3m-mode-map [(up)] 'previous-line) (define-key w3m-mode-map [(down)] 'next-line) (define-key w3m-mode-map [(left)] 'backward-char) (define-key w3m-mode-map [(right)] 'forward-char) (define-key w3m-mode-map [(shift left)] 'w3m-shift-right) (define-key w3m-mode-map [(shift right)] 'w3m-shift-left) (define-key w3m-mode-map [(tab)] 'w3m-next-anchor) (define-key w3m-mode-map [(shift tab)] 'w3m-previous-anchor) (define-key w3m-mode-map [(g)] 'w3m-goto-url) (define-key w3m-mode-map [(i)] 'w3m-toggle-inline-image) (define-key w3m-mode-map [(shift i)] 'w3m-toggle-inline-images) (define-key w3m-mode-map [(n)] 'w3m-next-anchor) (define-key w3m-mode-map [(control t)] 'w3m-new-tab) ;; Mozilla-like navigation (define-key w3m-mode-map [(meta right)] 'w3m-view-this-url) (define-key w3m-mode-map [(meta left)] 'w3m-view-previous-page) (define-key w3m-mode-map [(control return)] 'w3m-view-this-url-new-session) ;; add key bindings (global-set-key [(control c) (w) (w)] 'w3m) (global-set-key [(control c) (w) (s)] 'w3m-search) (defun my-w3m-goto-url () "Type in directly the URL I would like to visit (avoiding to hit `C-k')." (interactive) (let ((w3m-current-url "")) (call-interactively #'w3m-goto-url))) (define-key w3m-mode-map (kbd "g") #'my-w3m-goto-url))) ;;}}} (when (try-require 'w3m-search) (add-to-list 'w3m-search-engine-alist '("teoma" "http://www.teoma.com/search.asp?t=%s" nil))) ;; list of content types, regexps (matching a url or a file name), commands ;; to view contents, and filters to override the content type specified at ;; first (setq w3m-content-type-alist (append '(("text/html" "\\.xhtml\\'" nil nil)) w3m-content-type-alist)) ;; toggle a minor mode showing link numbers (when (try-require 'w3m-lnum) (defun my-w3m-go-to-linknum () "Turn on link numbers and ask for one to go to." (interactive) (let ((active w3m-link-numbering-mode)) (when (not active) (w3m-link-numbering-mode)) (unwind-protect (w3m-move-numbered-anchor (read-number "Anchor number: ")) (when (not active) (w3m-link-numbering-mode)) (w3m-view-this-url)))) (define-key w3m-mode-map [(f)] 'my-w3m-go-to-linknum)) ;;}}} ;;{{{ Web search (when (and (try-require 'browse-url) t) ;; (try-require 'url)) ;;{{{ from Glenn Morris (defvar my-google-maxlen 200 "Maximum string length of search term.") (defvar my-google-url "www.google.com" "Base URL for Google search.") (defvar my-google-groups-url "groups.google.com" "Base URL for groups Google search.") (defun my-google-search-region (prefix start end) "Create a search URL and send it to the web browser. With prefix argument, use groups URL." (interactive "P\nr") (if (> (- end start) my-google-maxlen) (message "Search string too long!") (let ((query (buffer-substring-no-properties start end))) (browse-url (concat "http://" (if prefix (concat my-google-groups-url "/groups") (concat my-google-url "/search")) "?q=" (url-hexify-string query)))))) (defvar my-url-maxlen 100 "Maximum length of string to send to browser as URL.") ;; `find-file-at-point' does this, essentially (defun my-url-at-point (start end) "Send the highlighted URL to the web browser." (interactive "r") (if (> (- end start) my-url-maxlen) (message "URL too long!") (browse-url (buffer-substring-no-properties start end)))) ;; (require 'url) ;; ;; (defvar google-search-maxlen 50 ;; "Maximum string length of search term. This prevents you from accidentally ;; sending a five megabyte query string to Netscape.") ;; ;; (defun google-it (search-string) ;; "Search for SEARCH-STRING on Google." ;; (interactive "sSearch for: ") ;; (browse-url (concat "http://www.google.com/search?client=xemacs&q=" ;; (url-hexify-string ;; (encode-coding-string search-string 'utf-8))))) ;; ;; (defun google-search-selection () ;; "Create a Google search URL and send it to your web browser." ;; (interactive) ;; (let (start end term url) ;; (if (or (not (fboundp 'region-exists-p)) (region-exists-p)) ;; (progn ;; (setq start (region-beginning) ;; end (region-end)) ;; (if (> (- start end) google-search-maxlen) ;; (setq term (buffer-substring start (+ start google-search-maxlen))) ;; (setq term (buffer-substring start end))) ;; (google-it term)) ;; (beep) ;; (message "Region not active")))) ;;}}} (defun my-google-search () "Prompt for a query in the minibuffer, launch the web browser and query Google." (interactive) (let ((query (read-from-minibuffer "Google Search: "))) (browse-url (concat "http://" my-google-url "/search?q=" (url-hexify-string query))))) (defun my-google-search-word-at-point () "Google the word at point." (interactive) (browse-url (concat "http://" my-google-url "/search?q=" (word-at-point)))) (defun my-google-search-file (file) "Use Google to search for a file named FILE." (interactive "sSearch for file: ") (w3m-browse-url (concat "http://" my-google-url "/search?q=" (w3m-url-encode-string (concat "+intitle:\"index+of\" " "-inurl:htm -inurl:html -inurl:php " file))))) (defvar my-google-prefix-map (make-sparse-keymap) "Keymap for my Google commands.") ;;; (global-set-key [(meta s)] 'my-google-search-region) (global-set-key [(control c) (g)] my-google-prefix-map) (define-key my-google-prefix-map "g" 'my-google-search) (define-key my-google-prefix-map (kbd "RET") 'my-google-search) (define-key my-google-prefix-map "w" 'my-google-search-word-at-point) (define-key my-google-prefix-map "r" 'my-google-search-region) (define-key my-google-prefix-map "u" 'my-url-at-point) (defun lookup-word-definition-in-w3m () "Look up the word's definition in a emacs-w3m.\n If a region is active (a phrase), lookup that phrase." (interactive) (let (myword myurl) (setq myword (if (and transient-mark-mode mark-active) (buffer-substring-no-properties (region-beginning) (region-end)) (thing-at-point 'symbol))) (setq myword (replace-regexp-in-string " " "%20" myword)) (setq myurl (concat "http://www.answers.com/main/ntquery?s=" myword)) (w3m-browse-url myurl))) (define-key my-google-prefix-map "a" 'lookup-word-definition-in-w3m) (defun lookup-wikipedia () "Look up the word's in Wikipedia.\n This command generates a url for Wikipedia.com and switches you to browser. If a region is active (a phrase), lookup that phrase." (interactive) (let (myword myurl) (setq myword (if (and transient-mark-mode mark-active) (buffer-substring-no-properties (region-beginning) (region-end)) (thing-at-point 'symbol))) (setq myword (replace-regexp-in-string " " "_" myword)) (setq myurl (concat "http://en.wikipedia.org/wiki/" myword)) (w3m-browse-url myurl)))) ;;}}} ;;{{{ Babel ;; TODO replace `require' by `try-require' (add file as optional parameter) (GNUEmacs ;; Uniform Resource Locator retrieval tool (require 'url (concat local-site-lisp-directory "url"))) ; FIXME (GNUEmacs ;; interface to web translation services such as Babelfish (require 'babel (concat local-site-lisp-directory "babel"))) ; FIXME ;;}}} ;;{{{ (info "(emacs-goodies-el)htmlize") ;; HTML-ize font-lock buffers (when (try-require 'htmlize) ;; output type of generated HTML (setq htmlize-output-type 'css) ;; override output type `inline-css' used for htmlizing a region (defun htmlize-region-for-paste (beg end) "Htmlize the region and return just the HTML as a string. This forces the `css' style and only returns the HTML body, but without the BODY tag. This should make it useful for inserting the text to another HTML buffer." (let* ((htmlize-output-type 'css) ; was `inline-css' (htmlbuf (htmlize-region beg end))) (unwind-protect (with-current-buffer htmlbuf (buffer-substring (plist-get htmlize-buffer-places 'content-start) (plist-get htmlize-buffer-places 'content-end))) (kill-buffer htmlbuf)))) ;; charset declared by the resulting HTML documents (setq htmlize-html-charset "utf-8") ;; non-ASCII characters (codes in the 128-255 range) are copied to HTML ;; without modification -- if your HTML is in Unicode (setq htmlize-convert-nonascii-to-entities nil) ;; key binding (global-set-key [(meta shift p)] 'htmlize-buffer)) (GNUEmacs ;; view current buffer as html in web browser (when (try-require 'htmlize-view) ;; add "Quick Print" entry to file menu (htmlize-view-add-to-files-menu))) ;; Now, you can print from the browser in (complete) Unicode, ;; using your system's capabilities ;;}}} (message "54 Hyperlinking and Navigation Features... Done") ;;}}} ;;{{{ --[ 55 Viewing Images as (info "(emacs)Thumbnails") ]----------------- (message "55 Viewing Images as Thumbnails...") (message "55 Viewing Images as Thumbnails... Done") ;;}}} ;;{{{ --[ 56 (info "(emacs)Dissociated Press") ]---------------------------- (message "56 Dissociated Press...") (message "56 Dissociated Press... Done") ;;}}} ;;{{{ --[ 57 Other (info "(emacs)Amusements") ]----------------------------- (message "57 Other Amusements...") (GNUEmacs ;; get rid of the Games in the Tools menu (define-key menu-bar-tools-menu [games] nil)) (message "57 Other Amusements... Done") ;;}}} ;;{{{ --[ (info "(pgg)Top") (Emacs interface to GnuPG) ]-------------------- ;; In Gnus 5.10 you don't need `mailcrypt' as it comes with a package called ;; "PGG" which does what mailcrypt does (and more because mailcrypt doesn't ;; do PGP/MIME). ;; Mailcrypt has some anonymous remailer stuff in it. PGG doesn't, ;; but you can do most of that kind of stuff from within Gnus, I believe. ;; ,----[ (info "(pgg)Overview") ] ;; | PGG is an interface library between Emacs and various tools for secure ;; | communication. Even though Mailcrypt has similar feature, it does not ;; | deal with detached PGP messages, normally used in PGP/MIME ;; | infrastructure. This was the main reason why I wrote the new library. ;; `---- ;;; Je chiffre avec easypg qui fait cela (entre autres choses). J'ai ;;; demandé à l'auteur que son outil propose encore plus de ;;; fonctionnalités pour être *le* vrai frontend GNU Emacs à GPG que ;;; je cherche depuis des années. ;;; ;;; Je me sers aussi de easypg en lieu et place de mailcrypt qui a ;;; l'air "mort" - i.e., plus maintenu. ;; 2008-03-03 -- No Gnus uses EasyPG instead of PGG when EasyPG is ;; installed. In Emacs CVS, EasyPG has been added recently. ;; ;; EasyPG is a GnuPG interface for Emacs. It has two aspects: convenient ;; tools which allow to use GnuPG from Emacs (EasyPG Assistant), and a fully ;; functional interface library to GnuPG (EasyPG Library.) It does not cache ;; passphrases, so gpg-agent (security/gnupg-devel) is recommended. (when (try-require 'pgg) ;; default PGP scheme (setq pgg-default-scheme 'gpg) ;; user ID of your default identity (setq pgg-default-user-id "Fabrice Niessen <fni@missioncriticalit.com>") ;; do not encrypt all outgoing messages with user's public key (setq pgg-encrypt-for-me nil) ;; how many seconds the passphrase is cached (setq pgg-passphrase-cache-expiry 600) ;; current scheme of PGP implementation (setq pgg-scheme 'gpg) ;; verify signed parts (setq mm-verify-option 'always) ;; decrypt encrypted parts (setq mm-decrypt-option 'always) ;; display buttons for signed and encrypted messages (setq gnus-buttonized-mime-types '("multipart/signed" "multipart/encrypted")) ;; package used for PGP/MIME (setq mml2015-use 'pgg)) ;; I'm not well acquainted with PGP/GnuPG too but you will be able ;; to fetch the key automatically if you set the `keyserver' entry ;; in the ~/.gnupg/gpg.conf file properly. ;; ;; Automagically sign all messages ;; ;(add-hook 'message-send-hook 'my-will-you-sign) ;; (defun my-will-you-sign () ;; (load-library "mc-toplev") ;; (interactive) ;; (if (y-or-n-p "Do you want to sign this message? ") ;; (mc-sign-message))) ;; ;; Hide pgp cruft if any. ;; (setq gnus-treat-strip-pgp t) ;; ;; After hiding pgp, verify the message; ;; ;; only happens if pgp signature is found. ;; (add-hook 'gnus-article-hide-pgp-hook ;; (lambda () ;; (save-excursion ;; (set-buffer gnus-original-article-buffer) ;; (mc-verify)))) ;; create a before-save-hook for auto encryption functions (defvar before-save-hook nil) (make-local-hook 'before-save-hook) (defadvice save-buffer (before crs-before-save-run-hooks) "Run before-save-hook before saving." (run-hooks 'before-save-hook)) (ad-activate 'save-buffer) ;; this is the auto-encryption function called at the bottom of important files (defun crs-auto-encrypt () (mc-decrypt) (auto-save-mode nil) (add-hook 'before-save-hook (lambda () (mc-encrypt-region 0 0 (save-excursion (goto-char (point-max)) (re-search-backward "[L]ocal Variables:" nil t) (beginning-of-line) (point)))) nil t)) (define-minor-mode sensitive-mode "For sensitive files like password lists. It disables backup creation and auto saving. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode." ;; the initial value nil ;; the indicator for the mode line " Sensitive" ;; the minor mode bindings nil (if (symbol-value sensitive-mode) (progn ;; disable backups (set (make-local-variable 'backup-inhibited) t) ;; disable auto-save (if auto-save-default (auto-save-mode -1))) ;; resort to default value of backup-inhibited (kill-local-variable 'backup-inhibited) ;; resort to default auto save setting (if auto-save-default (auto-save-mode 1)))) ;; Once the above snippet has been evaluated in Emacs, `M-x sensitive' will ;; disable backups and auto-save in the current buffer. All other buffers ;; will continue to have these features. ;; I usually set sensitive mode to turn on by default for files having the ;; gpg extension. The following code when put in your `.emacs' does exactly ;; that: (setq auto-mode-alist (append '(("\\.gpg$" . sensitive-mode)) auto-mode-alist)) ;; Check out ;; http://www.emacswiki.org/ -> Modes -> AutoEncryption ;; http://www.emacswiki.org/cgi-bin/emacs-en/AutoEncryption ;; for more information. I'm using crypt++, starting off with a file, ;; file.txt say, I encrypt it manually the first time ;; $ gpg --symmetric --armor file.txt ;; Enter passphrase: ;; repeat passphrase: ;; $ ;; ;; This creates a new file "file.txt.asc", which I open with emacs ;; (assuming crypt++ to be set up). This will ask for the passphrase, ;; then decrypt the file for me into the buffer. When saving the file, it ;; will be encrypted again. You can then remove the cleartext file. ;; ;; The use of "--armor" is disputable. While editing the file, there is ;; something like a autosave-file, the contents is clear in an emacs ;; buffer. This can be a problem on systems with more people logged in at ;; any time. So, I guess, this is not good for all possible scenarios. ;; ;; Hmm, you can try (info "(pgg)"). It uses GPG to provide functions for ;; encryption/decryption. ;; Note however, pgp is only in Emacs 22. ;;}}} ;; interface to `pwsafe' (GNUEmacs (when (try-require 'pwsafe) ;; primary database used for `pwsafe' (setq pwsafe-primary-database "~/.hide/.pwsafe.dat") ;; lock the password database after the given number of seconds (setq pwsafe-keep-passwd 120))) ;;{{{ --[ 58 (info "(emacs)Customization") ]-------------------------------- (message "58 Customization...") ;; inhibit the initial startup message in the `*scratch*' buffer (setq inhibit-startup-message t) (setq initial-scratch-message nil) (XEmacs (setq initial-scratch-message nil)) ;; limit on number of Lisp variable bindings & unwind-protects (setq max-specpdl-size (* 40 max-specpdl-size)) ; 40 * 1 M (default) ;; limit serving to catch infinite recursions for you before they ;; cause actual stack overflow in C, which would be fatal for Emacs (setq max-lisp-eval-depth (* 40 max-lisp-eval-depth)) ; 40 * 400 (default) ;; speed up things by preventing garbage collections (setq gc-cons-threshold (* 40 gc-cons-threshold)) ; 40 * 400 KB (default) ;; display messages at start and end of garbage collection (setq garbage-collection-messages t) ;;; ----[ 58.3 (info "(emacs)Variables") ;; file local variables specifications are obeyed, without query -- RISKY! (setq enable-local-variables t) ;; obey `eval' variables -- RISKY! (setq enable-local-eval t) ;; record safe values for some local variables (setq safe-local-variable-values '((TeX-master . t) (balloon-help-mode . -1) (flyspell-mode . t) (ispell-local-dictionary . american) (ispell-mode . t) (nuweb-auto-index-scrap) (nuweb-source-mode . "mercury") (nuweb-source-mode . "sql"))) ;;; ----[ 58.4 Customizing (info "(emacs)Key Bindings") ;; the keys `C-c LETTER' are reserved for user functions ;; print the key bindings in a tabular form ;; [from http://www-xray.ast.cam.ac.uk/~gmorris/dotemacs.html] (GNUEmacs (defun my-keytable (arg) "Print the key bindings in a tabular form." (interactive "sEnter a modifier string:") (with-output-to-temp-buffer "*Key table*" (let* ((i 0) (keys (list "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "<return>" "<down>" "<up>" "<right>" "<left>" "<home>" "<end>" "<f1>" "<f2>" "<f3>" "<f4>" "<f5>" "<f6>" "<f7>" "<f8>" "<f9>" "<f10>" "<f11>" "<f12>" "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "`" "~" "!" "@" "#" "$" "%" "^" "&" "*" "(" ")" "-" "_" "=" "+" "\\" "|" "{" "[" "]" "}" ";" "'" ":" "\"" "<" ">" "," "." "/" "?")) (n (length keys)) (modifiers (list "" "S-" "C-" "M-" "M-C-")) (k)) (or (string= arg "") (setq modifiers (list arg))) (setq k (length modifiers)) (princ (format " %-10.10s |" "Key")) (let ((j 0)) (while (< j k) (princ (format " %-28.28s |" (nth j modifiers))) (setq j (1+ j)))) (princ "\n") (princ (format "_%-10.10s_|" "__________")) (let ((j 0)) (while (< j k) (princ (format "_%-28.28s_|" "_______________________________")) (setq j (1+ j)))) (princ "\n") (while (< i n) (princ (format " %-10.10s |" (nth i keys))) (let ((j 0)) (while (< j k) (let* ((binding (key-binding (read-kbd-macro (concat (nth j modifiers) (nth i keys))))) (binding-string "_")) (when binding (if (eq binding 'self-insert-command) (setq binding-string (concat "'" (nth i keys) "'")) (setq binding-string (format "%s" binding)))) (setq binding-string (substring binding-string 0 (min (length binding-string) 28))) (princ (format " %-28.28s |" binding-string)) (setq j (1+ j))))) (princ "\n") (setq i (1+ i))) (princ (format "_%-10.10s_|" "__________")) (let ((j 0)) (while (< j k) (princ (format "_%-28.28s_|" "_______________________________")) (setq j (1+ j)))))) (delete-window) (hscroll-mode) (setq truncate-lines t))) ;; You can get a list of all the disabled functions by typing ;; `M-: (let(lst)(mapatoms(lambda(x)(if(get x 'disabled)(push x lst))))lst) RET' ;;; ----[ 58.5 The (info "(emacs)Syntax") Table ;; The syntax table contains information that tells Emacs how to operate on ;; text, words, sentences etc. It will make Emacs know enough about all the ;; symbols in a buffer. Syntax table is used for example for word motion ;; (`M-f'), spell-checking of words, expansion commands of abbrevs, etc. ;; fix completion syntax for `text-mode-syntax-table' (syntax table used for ;; editing text files) (defun my-change-word-constituent () (map nil (function (lambda (char) (modify-syntax-entry char "w" text-mode-syntax-table))) ;; include accented characters in completion syntax "áéíóúàèìòùâêîôûäëïöüñåç")) (my-change-word-constituent) ;; now '-' is not considered a word-delimiter ;; (add-hook 'emacs-lisp-mode-hook ;; (lambda () ;; (modify-syntax-entry ?- "w"))) (message "58 Customization... Done") ;;}}} ;;{{{ --[ App G Emacs and (info "(emacs)MS-DOS") ]-------------------------- (message "Appendix G Emacs and MS-DOS...") ;; numeric keypad (needed in XEmacs for Windows) (XEmacs ;; keys to the right of the regular keyboard (define-key key-translation-map [kp-divide] [?/]) (define-key key-translation-map [kp-multiply] [?*]) (define-key key-translation-map [kp-subtract] [?-]) (define-key key-translation-map [kp-add] [?+]) (define-key key-translation-map [kp-enter] [?\r]) (define-key key-translation-map [kp-decimal] [?.]) ;; keys with digits (define-key key-translation-map [kp-0] [?0]) (define-key key-translation-map [kp-1] [?1]) (define-key key-translation-map [kp-2] [?2]) (define-key key-translation-map [kp-3] [?3]) (define-key key-translation-map [kp-4] [?4]) (define-key key-translation-map [kp-5] [?5]) (define-key key-translation-map [kp-6] [?6]) (define-key key-translation-map [kp-7] [?7]) (define-key key-translation-map [kp-8] [?8]) (define-key key-translation-map [kp-9] [?9]) ;; additional keypad duplicates of keys ordinarily found elsewhere (define-key key-translation-map [kp-left] [left]) (define-key key-translation-map [kp-right] [right]) (define-key key-translation-map [kp-up] [up]) (define-key key-translation-map [kp-down] [down]) (define-key key-translation-map [kp-begin] [begin]) (define-key key-translation-map [kp-home] [home]) (define-key key-translation-map [kp-end] [end]) (define-key key-translation-map [kp-next] [next]) (define-key key-translation-map [kp-prior] [prior]) (define-key key-translation-map [kp-insert] [insert]) (define-key key-translation-map [kp-delete] [delete])) ;; divide key (needed in GNU Emacs for Windows) (GNUEmacs (global-set-key (kbd "<kp-divide>") (kbd "/"))) (message "Appendix G Emacs and MS-DOS... Done") ;;}}} ;;{{{ --[ Emacs Display ]--------------------------------------------------- ;;; ----[ Faces ;; You can get text properties of any char by typing `C-u C-x =' ;; Under Windows, you can get the current font string by typing ;; `(insert (format "\n%S" (w32-select-font)))' followed by `C-x C-e' ;; You can find the current font by typing ;; `M-x ielm RET (frame-parameters) RET' ;; see the line `font' ;; To check if some font is available in Emacs do following: ;; 1. Switch to the `*scratch*' buffer. ;; 2. Type `(prin1-to-string (x-list-fonts "font-you-want-to-check or ;; pattern"))'. ;; 3. Place the cursor after the last closing paren and hit ;; `C-j'. List of the names of available fonts matching given ;; pattern will appear in the current buffer (`*scratch*'). ;; 4. For listing of all available fonts, use ;; `(prin1-to-string (x-list-fonts "*"))'. ;; Format: "-a-b-c-d-e-f-g-h-i-j-k-l-" ;; where ;; ;; a = foundry ;; ;; b = font family <<< ;; ;; c = weight ;; Valid options: `bold', `demibold', `light', `medium', `normal'. ;; ;; d = slant ;; Valid options: `i' for italic and `r' for roman. ;; ;; e = set width ;; Ignored by NT-Emacs. ;; ;; f = pixels ;; Nominal font height in pixels. (Eg. 13 pixels roughly corresponds to ;; 10 points (a point is 1/72 of an inch) on a 96dpi monitor, so the ;; font spec above is selecting a 10 point bold Courier font) ;; ;; g = points in tenths of a point ;; 10 point is 100 ;; ;; h = horiz resolution in dpi ;; I think these numbers represent the "design resolution" of the font - ;; on X, fonts are typically designed for 75dpi or 100dpi screens (under ;; Windows,most monitors are assumed to be 96dpi I believe). NT-Emacs ;; ignores these values. ;; ;; i = vertical resolution in dpi ;; I think these numbers represent the "design resolution" of the font - ;; on X, fonts are typically designed for 75dpi or 100dpi screens (under ;; Windows,most monitors are assumed to be 96dpi I believe). NT-Emacs ;; ignores these values. ;; ;; j = spacing ;; Spacing as in mono-spaced or proportionally spaced. ;; Values are `c' (constant) or `m' (monospace) to mean fixed-width or ;; `p' for proportionally spaced. ;; ;; k = average width in tenths of a pixel ;; ;; l = character set ;; NT-Emacs understands: ansi, oem, symbol to refer to the standard ;; Windows character sets (the first two, at least, are locale ;; dependant). "iso8859" and "iso8859-1" are accepted as synonyms for ;; ansi. ;; Use `xfontsel' utility to try out different fonts. After choosing a font, ;; click the select button in `xfontsel' window. This will copy font name you ;; choose to copy & paste buffer. ;; Edit your `~/.Xresources' file to have a line with "Emacs.font". ;; Then do a `xrdb -merge ~/.Xresources' or restart your X11 to validate the ;; modification. ;; Now Emacs should start with that font. ;; avoid Emacs hanging for a while changing default font (modify-frame-parameters nil '((wait-for-wm . nil))) ;; the real color theme functions (when (try-require 'color-theme) ;; initialize the color theme package (if (fboundp 'color-theme-initialize) (color-theme-initialize)) ;; color themes will be installed for all frames (setq color-theme-is-global t) ;; set my default color theme (when (try-require 'color-theme-mine) (color-theme-mine))) ;; allow any scalable font (when running-ms-windows (setq scalable-fonts-allowed t)) (defun font-existsp (font) "Test if FONT is available." (if (null (list-fonts (font-spec :family font))) ;; 2008-02-26 function of the new font backend (Emacs 23), ;; instead of `x-list-fonts' nil t)) ;; set default font (GNUEmacs (unless running-ms-windows ;;; (if (font-existsp "Consolas") ; if Consolas is available (set-default-font "Consolas-8") ;;; (set-default-font "lucidasanstypewriter-11") ;;; ) ) (when running-ms-windows (if (font-existsp "Consolas") ; if Consolas is available (set-default-font "-outline-Consolas-normal-r-normal-normal-11-82-96-96-c-*-*-*") (set-default-font "-outline-Courier New-normal-r-normal-normal-12-90-96-96-c-*-iso8859-1")))) ;; Fonts that have a good utf-8 coverage are: ;; ;; Lucida Sans (Typewriter?) Unicode ;; DejaVu Sans Mono ;; Bitstream Vera Sans Mono ;; FreeMono ;; Monospace (Regular?) ;; Arial Unicode (MS?) ;; ;; None of them has all four variants, some have regular (medium) and bold ;; or light and regular, one regular and oblique. ;; To see if anti-aliasing is active, use `xmag' or any of the other ;; magnifier applications. The fonts should have gray edges. (defvar my-current-font-index 0) (defconst my-font-ring (if running-ms-windows '( "-*-Courier New-*-*-*-*-12-90-*-*-*-*-*-*" ) ;; else '( "-Misc-Fixed-Medium-R-SemiCondensed-*-13-*-*-*-*-*-*-*" ) )) (defun my-next-font () "Cycle between fonts." (interactive) (let ((len (length my-font-ring)) (next-index (+ my-current-font-index 1))) (if (= next-index len) (setq next-index 0)) (setq my-current-font-index next-index) (message (concat "Setting default font to `" (nth my-current-font-index my-font-ring) "'")) (set-default-font (nth my-current-font-index my-font-ring) t) (set-frame-font (nth my-current-font-index my-font-ring) t))) (global-set-key [(meta +)] 'my-next-font) (XEmacs (setq options-save-faces t)) ;; convenience functions for face customization (try-require 'face-list) (GNUEmacs ;; commands to zoom frame font size (when (try-require 'zoom-frm) ;; Get rid of `mouse-set-font': (define-key global-map [(S-down-mouse-1)] nil) (define-key global-map [(S-mouse-1)] 'zoom-frm-in) (define-key global-map [(C-S-mouse-1)] 'zoom-frm-out))) ;; Common fonts (defun ajg-set-font (f) "Set current and future frames to have font F" (interactive "sFont name (no quotes): ") (setq font-dotted-pair (cons 'font f)) (setq default-frame-alist (cons font-dotted-pair (assq-delete-all 'font default-frame-alist))) (set-default-font f)) (defun ajg-set-mono-font (size) "Set bitstream mono SIZE font for this and future frames" (interactive "sSize of bitstream mono font (no quotes): ") (ajg-set-font (concat "-bitstream-Bitstream Vera Sans Mono-normal-normal-normal-*-" size "-*-*-*-m-0-iso10646-1"))) (defun mono12-font () (interactive nil) (ajg-set-mono-font "12")) (defun mono14-font () (interactive nil) (ajg-set-mono-font "14")) (defun mono16-font () (interactive nil) (ajg-set-mono-font "16")) (defun mono18-font () (interactive nil) (ajg-set-mono-font "18")) (defun mono20-font () (interactive nil) (ajg-set-mono-font "20")) (defun mono25-font () (interactive nil) (ajg-set-mono-font "25")) (defun 4-up-font () (interactive nil) (mono12-font)) (defun 3-up-font () (interactive nil) (mono16-font)) (defun big-font () (interactive nil) (mono16-font)) (defun 2-up-font () (interactive nil) (mono25-font)) (defun huge-font () (interactive nil) (mono25-font)) (defun 1-up-font () (interactive nil) (mono52-font)) ; for a presentation ;; Automatically switch to dark background after sunset ;; and to light background after sunrise. ;; See www.jurta.org/emacs/dotemacs.en.html ;;}}} ;; ## R e c o v e r y f r o m P r o b l e m s ########################### ;;{{{ --[ 59 (info "(emacs)Quitting") and Aborting ]------------------------ (message "59 Quitting and Aborting...") (message "59 Quitting and Aborting... Done") ;;}}} ;;{{{ --[ Debugging ]------------------------------------------------------- ;; ;; get the backtrace when uncaught errors occur ;; (setq debug-on-error nil) ; was set to `t' at beginning of buffer ;; warn that some packages were missing (if missing-packages-list (progn (message "Packages not found: %S" (nreverse missing-packages-list)))) ;;}}} ;; I'm rather new to emacs, but I'm addicted already. I used to use ;; Eclipse a lot before, and there is one thing I'm missing though I'm ;; pretty sure that it must be available somewhere in Emacs. I was ;; wondering if it's possible to move (shift) a line of text up or down ;; like you would do in Eclipse pressing Alt-up (or down). (defun move-line (n) "Move the current line up or down by N lines." (interactive "p") (let ((col (current-column)) start end) (beginning-of-line) (setq start (point)) (end-of-line) (forward-char) (setq end (point)) (let ((line-text (delete-and-extract-region start end))) (forward-line n) (insert line-text) ;; restore point to original column in moved line (forward-line -1) (forward-char col)))) (defun move-line-up (n) "Move the current line up by N lines." (interactive "p") (move-line (if (null n) -1 (- n)))) (defun move-line-down (n) "Move the current line down by N lines." (interactive "p") (move-line (if (null n) 1 n))) (global-set-key (kbd "M-<up>") 'move-line-up) (global-set-key (kbd "M-<down>") 'move-line-down) ;; `C-x *' invokes the GNU Emacs Calculator (defun reverse-words (start end) (interactive "r") (let ((words (reverse (split-string (buffer-substring start end))))) (delete-region start end) (dolist (word words) (insert word " ")) (backward-char 1) (delete-char 1))) (message "Emacs startup time: %d seconds." (time-to-seconds (time-since emacs-load-start-time))) (sit-for 1.4) (message "}}}") ;; > move-to-window-line, M-r ;; > back-to-indentation, M-m ;; after-save-hook: (lambda () (byte-compile-file (buffer-file-name))) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(ecb-options-version "2.32")) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(default ((t (:size "8pt" :family "Consolas"))))) ;; This is for the sake of Emacs. ;; Local Variables: ;; coding: utf-8 ;; eval: (ispell-change-dictionary "american") ;; eval: (flyspell-mode 1) ;; End: ;;; .emacs ends here
Building GNU Emacs
If you're adventurous, you can build GNU Emacs yourself.
Get the Packages
On top of these default packages in Ubuntu:
sudo aptitude install gcc-4.2 sudo aptitude install libgcc1 sudo aptitude install cpp-4.2 sudo aptitude install binutils
you need to install the development tools:
sudo aptitude install build-essential
plus:
sudo aptitude install libgtk2.0-dev
Get Emacs
- Get the latest source (of Emacs with the XFT support):
cd /usr/local/src
cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs co -r emacs-unicode-2 emacs
- This will create a
emacsdirectory in the current directory. Go into it:
cd emacs
- For your information, display the options of the
configurescript:
./configure --help
- Prepare
makefor the build:
./configure --prefix=<PREFIXDIR> --enable-font-backend --with-xft
The `—prefix=PREFIXDIR' option specifies where the installation process should put the files. This defaults to `/usr/local'.
- Compile the initial elisp interpreter and bytecode necessary to dump a mini-Emacs that will compile the real Emacs:
make bootstrap
The bootstrap takes a looong time to build, so go grab some lunch...
- Do stuff:
make
- Put the pieces in their appropriate places on the system:
sudo make install
The installation takes some time.
- Run the latest Emacs you've just built on your machine:
<PREFIXDIR>/bin/emacs --enable-font-backend --font "Bitstream Vera Sans Mono-10"
Note — You can just launch emacs --enable-font-backend if you add the line
(set-default-font "Bitstream Vera Sans Mono-10") to your .emacs file.
After the first build, do make distclean before doing the CVS update.
Gnus
Here you should find my init file for Gnus soon!
Please contact me for corrections, additions and suggestions.
