Richard Riley's web site (inprogress)
Dotprogramming
Table of Contents
Emacs programming customisations
Auto completion in emacs
Phew. Loads of possibilities. All stepping on the feet of each other. I settled on company-mode. You can search the completion list and then limit the list to those completion candidates.
;;;;; ;************************************************ ; rgr-completion.el ; ; completion stuff ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ (require 'rgr-anything) (add-to-list 'load-path "~/.emacs.d/lisp/company-mode") (require 'company) (setq company-begin-commands '(self-insert-command) company-ispell-available t ) (defun complete-or-indent () (interactive) (if (company-manual-begin) (company-complete-common) (indent-according-to-mode))) (defun indent-or-complete () (interactive) (if (looking-at "\\_>") (company-complete-common) (indent-according-to-mode))) (global-set-key "\t" 'indent-or-complete) ;; Use ispell dictionary for completion in text-mode! (add-hook 'text-mode-hook (lambda () (set (make-local-variable 'company-backends) '(company-dabbrev company-ispell)))) (global-company-mode 1) (provide 'rgr-completion)
General Programming with Emacs
My top level programming el file.
;;;;;;;;;;; ;************************************************ ; rgr-programming.el ; ; Top level programming file ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ (require 'etags-table) (provide 'etags-stack) (autoload 'paste2-buffer-create "paste2" nil t) (global-set-key "\M-." 'etags-select-find-tag-at-point) (global-set-key "\M-?" 'etags-select-find-tag) ;; (setq semantic-load-turn-useful-things-on t) ;; (add-to-list 'load-path "~/.emacs.d/lisp/cedet/common") ;; (require 'cedet) (setq speedbar-default-position (quote right) etags-table-search-up-depth 3 etags-table-alist (list '("/home/shamrock/.emacs.d/.*\\.el$" "/home/shamrock/.emacs.d/TAGS") '("/home/shamrock/programming/c/.*\\.c$" "/home/shamrock/programming/c/TAGS") '("/home/shamrock/programming/c/.*\\.c$" "/home/shamrock/programming/TAGS") '(".*\\.php$" "/home/shamrock/webs/shamrockirishbar/TAGS")) large-file-warning-threshold nil speedbar-track-mouse-flag t speedbar-use-images t Man-switches "-a" Man-notify-method (quote aggressive)) (setq indent-tabs-mode nil) (defadvice Man-build-page-list (after reverse-page-list activate) (setq Man-page-list (nreverse Man-page-list))) (require 'compile+) (require 'grep+) (autoload 'apt-utils-search "apt-utils") (eval-after-load "sql" `(progn (load "~/.emacs.d/.sql-auth.el"))) (require 'rgr-c) (require 'rgr-php) (require 'sql-transform) (setq flymake-extension-auto-show t) (require 'flymake-extension) (defun my-flymake-show-help () (when (get-char-property (point) 'flymake-overlay) (let ((help (get-char-property (point) 'help-echo))) (if help (message "%s" help))))) (add-hook 'post-command-hook 'my-flymake-show-help) ;; (load-library "flymake-cursor.el") (add-hook 'sql-mode-hook (function (lambda () (local-set-key "\C-cu" 'sql-to-update)))) (require 'rgr-python) (require 'rgr-haskell) (require 'rgr-java) (load "~/.emacs.d/lisp/nxhtml/autostart.el") (provide 'rgr-programming)
C/C++ Programming with Emacs
Note the compile command making selections of make files or using scons.
;;;;; ;************************************************ ; rgr-c.el ; ; C/C++ related utilities ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ (defun my-c-mode-common-hook() ;; (set (make-local-variable 'company-backends) '(company-semantic)) ;; (company-mode 1) ;;allow compile window to vanish if no errors. (add-hook 'compilation-finish-functions (lambda (buf str) (if (string-match "exited abnormally" str) (next-error) ;;no errors, make the compilation window go away in a few seconds (run-at-time "2 sec" nil 'delete-windows-on (get-buffer-create "*compilation*")) (message "No Compilation Errors!") ) )) (add-hook 'c-mode-common-hook (lambda () (which-function-mode t))) (defun do-compile() (interactive) (compile (make-command)) ) (defun make-command() (if (or (file-exists-p "makefile") (file-exists-p "Makefile")) "make" ) (if (file-exists-p "SConstruct") "scons" (let ((file (file-name-nondirectory buffer-file-name))) (if (equal (file-name-extension buffer-file-name) "cc") (progn (format "%s %s %s -o %s" (or (getenv "CC") "g++") (or (getenv "CPPFLAGS")"-Wall -g") "*.cc" (file-name-sans-extension file) )) (format "%s -o %s %s %s %s %s" (or (getenv "CC") "gcc") (file-name-sans-extension file) (or (getenv "GTKFLAGS") "`pkg-config --cflags --libs gtk+-2.0`") (or (getenv "CPPFLAGS")"-DDEBUG=9") (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g") file) )))) (defun do-lint() (interactive) (set (make-local-variable 'compile-command) (let ((file (file-name-nondirectory buffer-file-name))) (format "%s %s %s" "splint" "+single-include -strict -compdef -nullpass -preproc +matchanyintegral -internalglobs -I/usr/include/gtk-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/cairo/ -I/usr/include/pangomm-1.4/pangomm/" file ))) (message compile-command) (compile compile-command) ) (defun do-cdecl () (interactive) (shell-command (concat "cdecl explain \"" (buffer-substring (region-beginning) (region-end)) "\"")) ) (setq compilation-window-height 16) (setq compilation-scroll-output t) (setq compilation-finish-functions (lambda (buf str) (if (string-match "exited abnormally" str) ;;there were errors (message "compilation errors, F11 to goto next error.") ;;no errors, make the compilation window go away in 0.5 seconds ;; (run-at-time 5.0 nil 'delete-windows-on buf) (message "NO COMPILATION ERRORS!")))) (setq gdb-show-main t) (setq gdb-many-windows t) (define-key c-mode-base-map [(shift f2)] 'gdb-restore-windows) (define-key c-mode-base-map [(meta f10)] (lambda()(interactive)(do-compile))) (define-key c-mode-base-map [(shift f10)] (lambda()(interactive)(do-lint))) (define-key c-mode-base-map [(control f10)] (lambda()(interactive)(do-cdecl))) (define-key c-mode-base-map [f12] 'gdb) (add-hook 'c-mode-hook '(lambda () (local-set-key (kbd "RET") 'newline-and-indent))) (define-key c-mode-base-map (kbd "C-c C-f") 'php-search-documentation) (define-key c-mode-base-map (kbd "C-c C-m") 'php-browse-manual) ; (setq c-eldoc-includes "`pkg-config gtk+-2.0 --cflags` -I./ -I../ ") ; (load "c-eldoc") (c-set-style "linux") ; (c-turn-on-eldoc-mode) (require 'xcscope) (eval-after-load `xcscope `(progn ;; cscope databases (setq cscope-database-regexps '( ( "/home/shamrock/programming/c/linux" (t) ("/usr/src/linux/include") ) )) (setq cscope-do-not-update-database t) (setq cscope-display-cscope-buffer nil) (setq cscope-edit-single-match nil))) ) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) (provide 'rgr-c)
Java Programming with Emacs Using JDEE
JDEE is hard to setup. I had to install elib from the Debian repositories which bizarrely insists on bringing in emacs21 of all things. Why not install elib manually? Well the "ant" build to configure JDEE does not find the elib even after correctly modifying the build.properties files according (elib.dir=/home/shamrock/.emacs.d/lisp/jde/elib).
Furthermore running a sample hello world app didn't work because of some bizarre dependency issue which exists in 2.3.6 JDEE. I had to manually compile jde-run.el to get rid of it.
;;;;; ;************************************************ ; rgr-java.el ; ; Java ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ (add-to-list 'load-path "~/.emacs.d/lisp/jde/lisp") (setq jde-jdk (quote ("1.6")) jde-compiler (quote ("javac" "")) jde-jdk-registry (quote (("1.6" . "~/programming/java/java-6-sun"))) jde-sourcepath (quote ("~/programming/java/bike" "~/programming/java/bike/mypack" "$JAVA_HOME/src" "." "./src" "")) jde-compile-option-debug (quote ("all" (t nil nil))) ) (require 'jde-autoload) (provide 'rgr-java)
Python Programming With Emacs
General Integration including rope, company-mode and pylint
;;;;; ;************************************************ ; rgr-python.el ; ; python integration ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ ;; Notes : python in emacs is a mess. the official python.el seems ;; flakey to say the least and there is little if any concensus on ;; what to use. I tried to revert to using the officical python.el ;; but (a) could not load iPython without moving it to an autoload ;; and (b) the interpreter didn't work. (autoload 'python-mode "python-mode" "Python Mode." t) (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) (add-to-list 'interpreter-mode-alist '("python" . python-mode)) ;; (require 'python) (setq load-path (append (list nil "~/.emacs.d/lisp/pymacs/" "~/.emacs.d/lisp/pysmell/" "~/.emacs.d/lisp/pylint/elisp/" "~/.emacs.d/lisp/python-mode/" ) load-path)) (require 'pymacs) (when (load "flymake" t) (defun flymake-pycheckers-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "pycheckers" (list local-file))))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pycheckers-init)) (require 'ipython) (setq python-python-command "ipython") (setq py-python-command-args '( "-colors" "Linux")) ;; (pymacs-load "ropemacs" "rope-") (setq ropemacs-confirm-saving nil ropemacs-guess-project t ropemacs-enable-autoimport t ) (add-hook 'python-mode-hook (lambda () (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter (local-set-key [f2] 'flymake-goto-prev-error) (local-set-key [f3] 'flymake-goto-next-error) )) (require 'anything-ipython) (add-hook 'python-mode-hook #'(lambda () (define-key py-mode-map (kbd "M-<tab>") 'anything-ipython-complete))) (add-hook 'ipython-shell-hook #'(lambda () (define-key py-mode-map (kbd "M-<tab>") 'anything-ipython-complete))) (provide 'rgr-python)
The epylint python script
#!/usr/bin/env python import re import sys from subprocess import * p = Popen("pylint -f parseable -r n --disable-msg-cat=C,R %s" % sys.argv[1], shell = True, stdout = PIPE).stdout for line in p.readlines(): match = re.search("\\[([WE])(, (.+?))?\\]", line) if match: kind = match.group(1) func = match.group(3) if kind == "W": msg = "Warning" else: msg = "Error" if func: line = re.sub("\\[([WE])(, (.+?))?\\]", "%s (%s):" % (msg, func), line) else: line = re.sub("\\[([WE])?\\]", "%s:" % msg, line) print line, p.close()
The pycheckers batch
#!/bin/bash #epylint "$1" 2>/dev/null #pyflakes "$1" pep8.py --ignore=E221,E701,E202 --repeat "$1" true
flymake-cursor.el code to have errors shown in mini buffer
;; -*- emacs-lisp -*- ;; License: Gnu Public License ;; ;; Additional functionality that makes flymake error messages appear ;; in the minibuffer when point is on a line containing a flymake ;; error. This saves having to mouse over the error, which is a ;; keyboard user's annoyance ;;flymake-ler(file line type text &optional full-file) (defun show-fly-err-at-point () "If the cursor is sitting on a flymake error, display the message in the minibuffer" (interactive) (let ((line-no (line-number-at-pos))) (dolist (elem flymake-err-info) (if (eq (car elem) line-no) (let ((err (car (second elem)))) (message "%s" (fly-pyflake-determine-message err))))))) (defun fly-pyflake-determine-message (err) "pyflake is flakey if it has compile problems, this adjusts the message to display, so there is one ;)" (cond ((not (or (eq major-mode 'Python) (eq major-mode 'python-mode) t))) ((null (flymake-ler-file err)) ;; normal message do your thing (flymake-ler-text err)) (t ;; could not compile err (format "compile error, problem on line %s" (flymake-ler-line err))))) (defadvice flymake-goto-next-error (after display-message activate compile) "Display the error in the mini-buffer rather than having to mouse over it" (show-fly-err-at-point)) (defadvice flymake-goto-prev-error (after display-message activate compile) "Display the error in the mini-buffer rather than having to mouse over it" (show-fly-err-at-point)) (defadvice flymake-mode (before post-command-stuff activate compile) "Add functionality to the post command hook so that if the cursor is sitting on a flymake error the error information is displayed in the minibuffer (rather than having to mouse over it)" (set (make-local-variable 'post-command-hook) (cons 'show-fly-err-at-point post-command-hook)))
PHP Programming With Emacs
;;;;; ;************************************************ ; rgr-php.el ; ; PHP Programming ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ (defvar php-search-url "http://www.php.net/") (defvar php-manual-url "http://www.php.net/manual/en/") (defun php-search-documentation () "Search PHP documentation for the word at the point." (interactive) (w3m-browse-url (concat php-search-url (current-word t)))) (defun php-browse-manual () "Bring up manual for PHP." (interactive) (w3m-browse-url php-manual-url)) (eval-after-load "sgml-mode" (lambda()(debug))) (eval-after-load "html-mode" (lambda()(debug))) (setq load-path (append (list nil "~/.emacs.d/lisp/php-mode/" ) load-path)) ;; (require 'php-mode) ;; (require 'html-php) ;;(add-to-list 'auto-mode-alist '("\\.php\\'" . html-php-mode)) ;;(eval-after-load "php-mode" (lambda()(add-to-list 'auto-mode-alist '("\\.php\\'" . html-php-mode)))) (provide 'rgr-php)
Haskell Programming With Emacs
;;;;; ;************************************************ ; rgr-haskell.el ; ; Haskell emacs stuff ; Richard Riley. ; http://richardriley.net/default/projects/emacs/ ;************************************************ (load "~/.emacs.d/lisp/haskell-mode/haskell-site-file") (eval-after-load "haskell-mode" '(progn (require 'browse-apropos-url) (add-to-list 'apropos-url-alist '("^hayoo:? +\\(.*\\)" . "http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=\\1")) (define-key haskell-mode-map (kbd "C-h f") (lambda()(interactive)(rgr/browse-apropos-url "hayoo" "Hayoo Search (%s): "))) (setq haskell-program-name "ghci") (require 'hs-lint) (define-key haskell-mode-map [(shift f10)] (lambda()(interactive)(hs-lint))) (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) (add-hook 'haskell-mode-hook 'turn-on-haskell-indent))) (add-hook 'haskell-mode-hook (lambda () (setq haskell-font-lock-symbols t))) ;; Company mode completion (add-hook 'haskell-mode-hook (lambda () (set (make-local-variable 'company-backends) '(company-dabbrev company-dabbrev-code))(company-mode 1))) (add-hook 'inferior-haskell-mode-hook (lambda () (set (make-local-variable 'company-backends) '(company-dabbrev company-dabbrev-code))(company-mode 1))) (provide 'rgr-haskell)
Auctex for LaTeX programming within Emacs
NEW. Wow - preview-latex is pretty cool. In place image substitution to show how certain latex elements render.
(load "auctex.el" nil t t) (setq TeX-auto-save t) (setq TeX-save-query nil) (setq TeX-parse-self t) (setq-default TeX-master nil) ;; (add-hook 'LaTeX-mode-hook (lambda () ;; (reftex-mode 1) ;; (TeX-fold-mode 1))) (autoload 'cdlatex-mode "cdlatex" "CDLaTeX Mode" t) (autoload 'turn-on-cdlatex "cdlatex" "CDLaTeX Mode" nil) (add-hook 'LaTeX-mode-hook 'turn-on-cdlatex) ; with AUCTeX LaTeX mode (provide 'rgr-latex)
Date: 2009-12-08 17:33:42 CET
HTML generated by org-mode 6.33trans in emacs 23
