;;; -*- emacs-lisp -*- ;; errors? use: emacs -nw --debug-init ;; CUSTOMIZATIONS (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. '(browse-url-browser-function (quote browse-url-w3)) '(case-fold-search t) '(current-language-environment "English") '(dired-listing-switches "-BGgh") '(ecb-options-version "2.32") '(ecb-source-path (quote (("~/darcs/" "")))) '(global-font-lock-mode t nil (font-lock)) '(gnus-nntp-server "news.i" t) '(grep-command "grep -nrI . -e ") '(haskell-program-name "ghci") '(mail-specify-envelope-from t) '(package-selected-packages (quote (nix-mode haskell-mode use-package rust-mode quack purescript-mode nodejs-repl geiser flycheck))) '(quack-default-program "mzscheme") '(quack-fontify-style (quote plt)) '(quack-programs (quote ("mzscheme" "bigloo" "csi" "csi -hygienic" "gosh" "gracket" "gsi" "gsi ~~/syntax-case.scm -" "guile" "kawa" "mit-scheme" "racket" "racket -il typed/racket" "rs" "scheme" "scheme48" "scsh" "sisc" "stklos" "sxi"))) '(quack-run-scheme-always-prompts-p t) '(quack-smart-open-paren-p nil) '(quack-switch-to-scheme-method (quote cmuscheme)) '(safe-local-variable-values (quote ((buffer-file-coding-system . iso-latin-1)))) '(send-mail-function (quote sendmail-send-it)) '(tags-revert-without-query t) '(use-file-dialog nil) '(user-mail-address "tom@zwizwa.be") '(w3m-use-cookies t) '(woman-cache-filename "~/.wmncach.el") '(woman-cache-level 3) '(woman-fill-column 75) '(woman-use-own-frame nil) '(x-dnd-types-alist (quote (("text/uri-list" . my-x-dnd-handle-uri-list) ("text/x-moz-url" . x-dnd-handle-moz-url) ("_NETSCAPE_URL" . x-dnd-handle-uri-list) ("FILE_NAME" . x-dnd-handle-file-name) ("UTF8_STRING" . x-dnd-insert-utf8-text) ("text/plain;charset=UTF-8" . x-dnd-insert-utf8-text) ("text/plain;charset=utf-8" . x-dnd-insert-utf8-text) ("text/unicode" . x-dnd-insert-utf16-text) ("text/plain" . dnd-insert-text) ("COMPOUND_TEXT" . x-dnd-insert-ctext) ("STRING" . dnd-insert-text) ("TEXT" . dnd-insert-text))))) (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. '(nxml-attribute-local-name-face ((t (:inherit font-lock-variable-name-face)))) '(nxml-cdata-section-CDATA-face ((t (:inherit zenburn-primary-4)))) '(nxml-cdata-section-content-face ((t (:inherit nxml-text-face)))) '(nxml-cdata-section-delimiter-face ((t (:inherit nxml-cdata-section-CDATA-face)))) '(nxml-char-ref-delimiter-face ((t (:inherit nxml-entity-ref-delimiter-face)))) '(nxml-char-ref-number-face ((t (:inherit nxml-entity-ref-name-face)))) '(nxml-comment-content-face ((t (:inherit font-lock-comment-face)))) '(nxml-comment-delimiter-face ((t (:inherit nxml-comment-content-face)))) '(nxml-delimited-data-face ((t (:inherit font-lock-string-face)))) '(nxml-delimiter-face ((t (:inherit default)))) '(nxml-entity-ref-delimiter-face ((t (:inherit nxml-entity-ref-name-face)))) '(nxml-entity-ref-name-face ((t (:inherit font-lock-doc-face)))) '(nxml-name-face ((t (:inherit font-lock-function-name-face)))) '(nxml-processing-instruction-content-face ((t (:inherit nxml-processing-instruction-target-face)))) '(nxml-processing-instruction-delimiter-face ((t (:inherit nxml-processing-instruction-target-face)))) '(nxml-processing-instruction-target-face ((t (:inherit zenburn-primary-2)))) '(nxml-ref-face ((t (:inherit font-lock-name-face)))) '(nxml-text-face ((t (:inherit default))) t) '(quack-pltish-comment-face ((((class color) (background dark)) (:inherit font-lock-comment-face)))) '(quack-pltish-defn-face ((t (:inherit font-lock-function-name-face)))) '(quack-pltish-keyword-face ((t (:inherit font-lock-keyword-face)))) '(quack-pltish-module-defn-face ((((class color) (background dark)) (:inherit font-lock-variable-name-face)))) '(quack-pltish-paren-face ((((class color) (background dark)) (:foreground "white")))) '(quack-pltish-selfeval-face ((((class color) (background dark)) (:inherit font-lock-string-face)))) '(woman-bold-face ((t (:foreground "white" :weight bold))))) (setq abbrev-file-name "~/.emacs.d/abbrev_defs") (setq save-abbrevs 'silent) (require 'cl) ;; Load these modules if present. (defun my-require (module) (message (format "(require '%s)" module)) (unwind-protect (condition-case nil (require module) (error (message (format "(require '%s) failed" module)) nil)))) (setenv "SSH_AUTH_SOCK" "/tmp/ssh-agent.tom") ;; Ad-hoc emacs tools. Note that while this library is public, it is ;; not meant to be used in other projects. Example only. (push "~/emacs/" load-path) ;; Some code is factored out as a proper library that can be dropped ;; into other projects. The development copy of this is integrated ;; into the exo toplevel. (push "~/exo/deps/emacs_tools" load-path) (push "~/exo/deps/asm_tools/emcas" load-path) ;; (add-hook 'after-save-hook 'push-change-after-save-hook) ;; (remove-hook 'after-save-hook 'push-change-after-save-hook) (add-hook 'after-save-hook 'my-exo-after-save-hook) ;; Install or refresh only once. (defvar my-package-refreshed nil) (defun my-package-install (package) (unless (package-installed-p package) (unless my-package-refreshed (package-refresh-contents) (setq my-package-refreshed t)) (package-install package))) ;; Do this before attempting to run code from installed packages. ;; FIXME: make this still start up properly even when not on the internet. (when (my-require 'package) (add-to-list 'package-archives '("elpa" . "http://elpa.gnu.org/packages/")) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/")) ;; (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/")) (package-initialize) (my-package-install 'use-package) (my-package-install 'use-package) (my-package-install 'geiser) (my-package-install 'quack) (my-package-install 'rust-mode) (my-package-install 'haskell-mode) ;; modes.el Erlang (my-package-install 'flycheck) (my-package-install 'purescript-mode) (my-package-install 'nodejs-repl) (my-package-install 'nix-mode) (my-package-install 'helm) (my-package-install 'htmlize) (my-package-install 'dts-mode) (my-package-install 'markdown-mode) ;;(my-package-install 'llvm-mode) ;; Note, packages such as cscope (with native dependencies) need to ;; be installed in Debian or Nixos. ) (defun my-load-library (lib) (message (format "(load-library \"%s\")" lib)) (unwind-protect (condition-case nil (load-library lib) (error (message (format "(load-library \"%s\") failed" lib)) nil)))) ;; emacs_tools (my-load-library "fs-context") (my-load-library "fs-context-flycheck") (my-load-library "push-change") (setq flycheck-command-wrapper-function 'fs-context-flycheck-command-wrapper) ;; FIXME: put this all into a flat file ;; (my-load-library "keys") ;; KEY BINDINGS ;; ------------ ;; http://www.gnu.org/software/emacs/manual/html_node/Key-Bindings.html#Key-Bindings ;; One of the confusing things is the string/vector thingy described ;; A key sequence which contains function key symbols (or anything but ;; ASCII characters) must be a vector rather than a string. ;; http://www.gnu.org/software/emacs/manual/html_node/Function-Keys.html#Function-Keys ;; You can use the modifier keys , , , , ;; and with function keys. To represent these modifiers, add the ;; strings ‘C-’, ‘M-’, ‘H-’, ‘s-’, ‘A-’ and ‘S-’ at the front of the ;; symbol name. ;; My window manager uses the windows key for WM commands, and leaves ;; all the other keys alone. This is much easier to work with emacs. ;; All goes through this function (defun my-key (key fun) (global-set-key key fun)) ;; MOUSE ;; From the `xterm-mouse-mode' help page: ;; When turned on, the normal xterm mouse functionality for such ;; clicks is still available by holding down the SHIFT key while ;; pressing the mouse button. ;; For xterm it seems best to have both worlds, even if that means to ;; have to use shift-middle to do paste from another X window. In ;; rxvt the xterm-mouse-mode doesn't work. ;; So... can't get normal x primary selection to work on long-lived ;; server sessions, so I give up. Configure such that drag and middle ;; are copy to kill and yank at click. Use simpleclip-paste for ;; paste. ;; Don't use these, use default keys instead: ;; control- simpleclip-copy ;; shift- simpleclip-cut ;; shift- simpleclip-paste ;;(global-set-key [C-insert] 'simpleclip-paste) ;;(global-set-key [C-delete] 'simpleclip-copy) ;; Use primary selection until it breaks again. It's too annoying to ;; work with cut and paste exceptions or inside xterm. ;; (global-set-key [mouse-2] 'mouse-yank-at-click) (my-key [mouse-2] 'mouse-yank-primary) (setq mouse-drag-copy-region t) (xterm-mouse-mode 1) (defun my-up-slightly () (interactive) (scroll-up 5)) (defun my-down-slightly () (interactive) (scroll-down 5)) (my-key [mouse-4] 'my-down-slightly) (my-key [mouse-5] 'my-up-slightly) (defun my-up-one () (interactive) (scroll-up 1)) (defun my-down-one () (interactive) (scroll-down 1)) (my-key [S-mouse-4] 'my-down-one) (my-key [S-mouse-5] 'my-up-one) (defun my-up-a-lot () (interactive) (scroll-up)) (defun my-down-a-lot () (interactive) (scroll-down)) (my-key [C-mouse-4] 'my-down-a-lot) (my-key [C-mouse-5] 'my-up-a-lot) ;; See also erl_tools/emacs/erl_tools.el ;; This needs Makefile support in the directory of the file (defun my-update-compile () (interactive) (let* ((path (buffer-file-name)) (dir (file-name-directory path)) (file (file-name-nondirectory path)) (new (concat file ".emacs_notify")) (cmd (concat "EMACS_NOTIFY=my-update-revert make -C " dir " " new))) (save-some-buffers t) (compile cmd))) (defun my-update-revert (file) (switch-to-buffer file) (revert-buffer t t)) ;; KEYBOARD ;; Don't use s- as it doesn't work in the terminal. ;; FIXME: escape for terminal missing meta key (my-key [f1] 'my-scratch) (my-key [f2] 'ibuffer) (my-key (kbd "ESC ") 'my-shell) (my-key [M-f2] 'my-shell) (my-key (kbd "ESC ") 'compile) (my-key [M-f5] 'compile) (my-key [f5] 'recompile) (my-key [f6] 'my-update-compile) (my-key [C-f1] 'my-t1) (my-key [C-f2] 'my-t2) (my-key [C-f3] 'my-t3) (my-key [C-f4] 'my-t4) (my-key [C-f5] 'my-t5) (my-key [C-f6] 'my-t6) (my-key [C-f7] 'my-t7) (my-key [C-f8] 'my-t8) (my-key [C-f9] 'my-t9) (my-key [C-f10] 'my-t10) (my-key [C-f11] 'my-t11) (my-key [C-f12] 'my-t12) ; xterm/dtach workaround (my-key (kbd "M-[ h") 'beginning-of-line) (my-key (kbd "M-[ f") 'end-of-line) (defun my-key-nothing () (interactive) (message "key not used")) (require 'eshell) ;; (add-to-list 'eshell-visual-commands "mutt") ;; not defined? (defun my-eshell (name) (let ((eshell-buffer-name (format "*%s*" name))) (eshell))) (defun my-term (name) (set-buffer (make-term name "/bin/bash")) (term-mode) (term-char-mode) (switch-to-buffer (format "*%s*" name)) (delete-other-windows)) (defun my-ansi-term (name) (let ((bufname (format "*%s*" name))) (if (get-buffer bufname) (switch-to-buffer bufname) (ansi-term "/bin/bash" name)))) ;; Default is local shell. Use prefix naming scheme "$" means user ;; buffer, "#" means root buffer. (defun my-shell () (interactive) (shell "/bin/bash")) ;; (defun my-shell () (my-shell-user "core")) ;; Open user and root terminals on remote hosts. This also opens a ;; tramp buffer with the slected directory. (defun my-shell-user (host) (interactive (list (read-string "host: " system-name))) (my-shell-dir (format "/scp:tom@%s:/home/tom" host) (format "$%s" host))) (defun my-shell-root (host) (interactive (list (read-string "host: " system-name))) (my-shell-dir (format "/scp:root@%s:/etc/net" host) (format "#%s" host))) (defun my-shell-dir (dir name) (let ((default-directory dir)) (shell name))) (defun my-t1 () (interactive) (my-eshell "1")) (defun my-t2 () (interactive) (my-eshell "2")) (defun my-t3 () (interactive) (my-eshell "3")) (defun my-t4 () (interactive) (my-eshell "4")) (defun my-t5 () (interactive) (my-eshell "5")) (defun my-t6 () (interactive) (my-eshell "6")) (defun my-t7 () (interactive) (my-eshell "7")) (defun my-t8 () (interactive) (my-eshell "8")) (defun my-t9 () (interactive) (my-ansi-term "9")) (defun my-t10 () (interactive) (my-ansi-term "10")) (defun my-t11 () (interactive) (my-ansi-term "11")) (defun my-t12 () (interactive) (my-ansi-term "12")) (defun my-kill-terminals () (interactive) (mapc (lambda (num) (let* ((name (format "*%d*" num))) (when (get-buffer name) (kill-buffer name)))) '(1 2 3 4 5 6 7 8 9 10 11 12))) (defun my-scratch () (interactive) (let ((scratch-buffer (or (get-buffer "*scratch*") (create-file-buffer "*scratch*")))) (switch-to-buffer scratch-buffer) (lisp-interaction-mode))) ;;(my-load-library "modes") (add-to-list 'auto-mode-alist '("\\.do$" . sh-mode)) (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) (add-to-list 'auto-mode-alist '("\\.f$" . forth-mode)) (add-to-list 'auto-mode-alist '("\\.mbox$" . vm-summary-mode)) ;; (add-to-list 'auto-mode-alist '("\\.xml$" . nxml-mode)) ; navigation keys, in case some of them are overridden ;(defun my-keys-local-navigation () ; (my-navigation-keys 'local-set-key)) (defun my-keys-local (bindings) (mapc (lambda (x) (local-set-key (car x) (cadr x))) bindings)) (defun my-keys-dabbrev () (interactive) (local-set-key [TAB] 'dabbrev-completion)) ;; RCIRC (defun my-irc-buffer (server) (let ((bufname (format "*%s*" server))) (let ((buf (get-buffer bufname))) (if buf (switch-to-buffer buf) (rcirc-connect server)))) (switch-to-buffer (get-buffer bufname))) (defun zwizwa () (interactive) (my-irc-buffer "zwizwa.i")) (setq rcirc-default-nick "doelie") (setq rcirc-default-user-name "tom") (setq rcirc-default-user-full-name "Tom Schouten") ;;; Minimal logging to `~/.rcirc-logs/channel' ;;; by courtesy of Trent Buck. (add-hook 'rcirc-print-hooks 'rcirc-write-log) (defcustom rcirc-log-directory "~/.rcirc-logs" "Where logs should be kept. If nil, logs aren't kept.") (defun rcirc-write-log (process sender response target text) (when rcirc-log-directory (with-temp-buffer ;; Sometimes TARGET is a buffer :-( (when (bufferp target) (setq target (with-current-buffer buffer rcirc-target))) ;; Sometimes buffer is not anything at all! (unless (or (null target) (string= target "")) ;; Print the line into the temp buffer. (insert (format-time-string "%Y-%m-%d %H:%M ")) (insert (format "%-16s " (rcirc-user-nick sender))) (unless (string= response "PRIVMSG") (insert "/" (downcase response) " ")) (insert text "\n") ;; Append the line to the appropriate logfile. (let ((coding-system-for-write 'no-conversion)) (write-region (point-min) (point-max) (concat rcirc-log-directory "/" (downcase target)) t 'quietly)))))) ;; LISP (defun my-keys-lisp-interaction () (my-keys-local '(("\C-x\C-j" pp-eval-last-sexp) ))) (add-hook 'lisp-interaction-mode-hook 'my-keys-lisp-interaction) (defun my-keys-scheme () (my-keys-local '(([tab] dabbrev-completion)))) ;; GUD (require 'gud) (defun my-gud-x-osd2 () (interactive) (gud-stop-subjob) (gud-basic-call "quit")) (defun my-gud-x-backtrace () (interactive) (gud-basic-call "echo \\n\\n") (gud-basic-call "bt")) (defun my-keys-gud () (interactive) (my-keys-local '(([s-left] gud-finish) ([s-down] gud-next) ([s-right] gud-step) ([s-up] gud-x-backtrace) ; ([s-prior] gud-up) ; ([s-next] gud-down) ; ([s-delete] gud-remove) ; ([s-insert] gud-break) ; ([s-end] gud-cont) ; ([s-up] gud-finish) ; ([s-down] gud-step) ; ([s-left] gud-tbreak) ; ([s-right] gud-next) ))) (add-hook 'gud-mode-hook 'my-keys-gud) ;; TERM ; (define-key term-mode-map "\M- " 'other-window) (require 'term) ;; (defun my-term (tag cmd) ;; (let* ((bufname (format "*%s*" tag)) ;; (had-old-buf (get-buffer bufname)) ;; (buf (or had-old-buf (create-file-buffer bufname)))) ;; (switch-to-buffer buf) ;; (term-mode) ;; ;;(term-exec buf tag "/bin/bash" nil nil) ;; (term-exec buf tag "sh" nil (list "-c" cmd)) ;; (term-char-mode) ;; )) (defun my-keys-term () (interactive) (my-keys-local '(([C-up] term-previous-input) ([C-down] term-next-input)))) ;; (eval-after-load "term" ;; '(define-key term-raw-map (kbd "C-c C-y") 'term-paste)) (add-hook 'term-mode-hook 'my-keys-term) (defun my-keys-shell () (interactive) ;; considering the significant amount of arbitrary output shell ;; programs spew, font locking makes no sense.. ;; (my-keys-local-navigation) (my-keys-local '(("\C-j" comint-send-input) ("\C-l" my-comint-clear-buffer) ([return] comint-send-input) ; newline) ("\M-k" comint-previous-matching-input-from-input) ;; kill-sentence ("\M-l" comint-next-matching-input-from-input) ;; downcase-word ))) (defun my-shell-mode-columns () "Reset the COLUMNS environment variable to the current width of the window." (interactive) (let ((proc (get-buffer-process (current-buffer))) (str (format "export COLUMNS=%s" (window-width)))) (funcall comint-input-sender proc str))) (defun my-shell-mode-hook () (interactive) ;; This is too dangerous, e.g. running python in shell buffer ;; (make-local-variable 'window-configuration-change-hook) ;; (add-hook 'window-configuration-change-hook 'my-shell-mode-columns) (my-shell-mode-columns)) (add-hook 'shell-mode-hook 'my-keys-shell) (add-hook 'shell-mode-hook 'my-shell-mode-hook) ;; (setq window-configuration-change-hook '(winner-change-fun)) ;; GDB ;; detach gdb from program and exit emacs ;; this is to support the 'attach-debugger' script (defun my-exit-gdb () (interactive) (gud-basic-call "detach") (gud-basic-call "quit") (kill-emacs)) ;; gdb hack: pervent stealing windows: ;; http://stackoverflow.com/a/24923325/412709 ;(defadvice gdb-inferior-filter ; (around gdb-inferior-filter-without-stealing) ; (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io) ; (comint-output-filter proc string))) ;(ad-activate 'gdb-inferior-filter) ;; C (defun my-c-mode-help () (interactive) (tags-search (word-at-point))) (defun my-c-mode-linux () (interactive) (c-set-style "linux") (set-variable 'indent-tabs-mode t) (set-variable 'show-trailing-whitespace t)) (defun my-c-mode-keil () (interactive) (c-set-style "cc-mode") (set-variable 'indent-tabs-mode nil) (set-variable 'show-trailing-whitespace nil) (set-variable 'tab-width 2)) ;; (my-require 'cflow-mode) (when (my-require 'xcscope) (setq cscope-do-not-update-database t) (cscope-set-initial-directory "~/exo/.cscope") (defun my-cscope-enter () (interactive) (let ((cscope-display-cscope-buffer nil)) (cscope-find-global-definition-no-prompting)))) ;; From https://www.kernel.org/doc/Documentation/CodingStyle (defun my-c-lineup-arglist-tabs-only (ignored) "Line up argument lists by tabs, not spaces" (let* ((anchor (c-langelem-pos c-syntactic-element)) (column (c-langelem-2nd-pos c-syntactic-element)) (offset (- (1+ column) anchor)) (steps (floor offset c-basic-offset))) (* (max steps 1) c-basic-offset))) (add-hook 'c-mode-common-hook (lambda () ;; Add kernel style (c-add-style "linux-tabs-only" '("linux" (c-offsets-alist (arglist-cont-nonempty c-lineup-gcc-asm-reg my-c-lineup-arglist-tabs-only)))))) (defun my-c-set-style-linux () (interactive) (setq indent-tabs-mode t) (c-set-style "linux-tabs-only")) (defun my-c-set-style-cc-mode () (interactive) (setq indent-tabs-mode t) (c-set-style "cc-mode")) ;; FIXME: use flycheck-gcc-args and the standard gcc checker ;; list of extra arguments, default null (defun my-c-mode-stuff () (interactive) (flycheck-select-checker 'my-c/c++-gcc) (flycheck-mode) (define-key c-mode-map "\C-c\C-h" 'my-c-mode-help) (c-set-style "cc-mode") (set-variable 'show-trailing-whitespace t) (auto-revert-mode) ;; very annoying to always confirm changes made by GIT.. ) (defun my-tab4 () (interactive) (setq tab-width 4)) (add-hook 'c-mode-hook 'my-c-mode-stuff) ;; (add-hook 'c-mode-hook ;; (lambda () ;; (let ((filename (buffer-file-name))) ;; ;; Enable kernel mode for the appropriate files ;; (when (and filename ;; (string-match (expand-file-name "~/src/linux-trees") ;; filename)) ;; ;; (my-c-set-style-linux) ;; (my-c-set-style-cc-mode) ;; )))) ;; Any ;; This is too smart. ; (add-hook 'before-save-hook 'delete-trailing-whitespace) ; (remove-hook 'before-save-hook 'delete-trailing-whitespace) ;; Lua (defun my-lua-mode-stuff () (interactive) (set-variable 'show-trailing-whitespace t) ;; FIXME: doesn't do anything? ) (add-hook 'lua-mode-hook 'my-lua-mode-stuff) ;; DIRED (require 'dired) (defun my-dired () (interactive) (local-set-key [s-up] 'dired-up-directory)) (add-hook 'dired-mode-hook 'my-dired) ;; SCHEME ;; (defun my-left-curly-bracket () (interactive) (insert "[")) ;; (defun my-right-curly-bracket () (interactive) (insert "]")) ;; (defun my-paren-forward () (interactive) ;; (search-forward ")")) ;; (defun my-paren-backward () (interactive) ;; (backward-char) ;; (search-backward ")") ;; (forward-char) ;; ) ;; (defun my-lisp-keys () (interactive) ;; (local-set-key "[" 'insert-parentheses) ;; ;; (local-set-key "]" 'move-past-close-and-reindent) ;; (local-set-key "]" 'my-paren-forward) ;; (local-set-key "\M-]" 'my-paren-backward) ;; (local-set-key "{" 'my-left-curly-bracket) ;; (local-set-key "}" 'my-right-curly-bracket) ;; ) (defun my-scheme-hook () (interactive) ;; (local-set-key [\e tab] 'hippie-expand) (local-set-key "\C-m" 'newline-and-indent) ;; (my-lisp-keys) ) (defun my-clear-comint-buffer () (interactive) (delete-region (point-min) (point-max))) (add-hook 'scheme-mode-hook 'my-scheme-hook) ;(defun plt-mzscheme () (interactive) ; (browse-url "/plt/doc/index.html")) (defun my-select-s-expression () (interactive) (mouse-set-point) (backward-list) (set-mark (point)) (forward-list)) (setq quack-fontify-treesemi-p t) ;; GNUS ;; (setq gnus-select-method '(nntp "news.kotnet.org")) ;; (setq gnus-select-method '(nntp "news.belnet.be")) ;; (nnfolder "archive" (nnfolder-directory "~/mail/archive/" ;; http://www.emacswiki.org/emacs/MessageMode (setq user-full-name "Tom Schouten") (setq user-mail-address "tom@zwizwa.be") (setq compose-mail-user-agent-warnings nil) (setq mail-host-address "zwizwa.be") (setq gnus-local-domain "zwizwa.be") (setq gnus-secondary-select-methods '((nnmbox ""))) (setq gnus-secondary-select-methods nil) (setq gnus-select-method nil) (setq gnus-nntp-server nil) (setq mail-sources '((file :path "/var/mail/tom"))) ;; (setq load-path (cons (expand-file-name "~/gnus-5.10.6/lisp") load-path)) (setq gnus-visible-headers (concat "^From:\\|^Subject:\\|^Newsgroups:" "\\|^X-Newsreader:\\|^X-Mailer:\\|^User-Agent:" "\\|^Message-ID:\\|^Organization:" "\\|^To:\\|^Cc:\\|^Date:" "\\|^X-Accept-Language:\\|^X-GPG-Key:\\|^X-GPG-Fingerprint:" )) (setq gnus-posting-styles '((".*" ("From" "Tom Schouten ") ("X-Accept-Language" "nl, en") (signature-file "~/.signature")) )) ;; (setq mail-sources '((pop :server "your.pop3server2.com" :user "user" :password "password"))) (setq mail-source '((maildir))) (setq gnus-select-method '(nnnil)) ;; ?? no primary (setq gnus-secondary-select-methods '((nnmaildir "" (directory "~/mail")) (nntp "news.i"))) ;; (setq gnus-default-subscribed-newsgroups '("comp.compilers")) (setq gnus-message-archive-method '(nnfolder "archive" (nnfolder-inhibit-expiry t) (nnfolder-active-file "~/mail/active") (nnfolder-directory "~/mail/"))) (setq gnus-message-archive-group "archive") (setq mm-text-html-renderer 'w3m) ;; VM ;; (defun my-vm-mode-hook () ;; (interactive) ;; (local-set-key "j" 'vm-previous-message) ;; (local-set-key ";" 'vm-next-message) ;; ) ;; (add-hook 'vm-mode-hook 'my-vm-mode-hook) ;; (setq vm-preview-lines nil) ;; (setq vm-movemail-program "movemail") ;; (setq vm-spool-files ;; (list (expand-file-name ;; (or (getenv "MAILDIR") "~/mail/INBOX.mdir")))) ;; (setq vm-mutable-frames) ;; leave frames alone ;; (setq vm-primary-inbox "~/mail/INBOX.mbox") ;; TRAMP (setq tramp-default-method "scp") ;; w3m ; (require 'w3m) (setq browse-url-browser-function 'w3m-browse-url) (autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t) ;; (global-set-key "\C-xm" 'browse-url-at-point) ;; TEXT (defun my-text-mode-hook () (interactive) ;; (auto-fill-mode 1) (local-set-key "\C-ce" 'my-log-entry) (electric-indent-mode 0) ;; too annoying when pasting into terminal ) (add-hook 'text-mode-hook 'my-text-mode-hook) (defun my-log-entry (name) (interactive "sEntry: ") (insert "Entry: " name "\n" "Date: ") (my-insert-command "date")) (defun my-insert-command (command) (interactive "sshell command: ") (insert-string (shell-command-to-string command))) ;; IBUFFER ;(defun my-ibuffer () (interactive) ; (local-set-key [j] 'ibuffer-backward-line) ; (local-set-key [\;] 'ibuffer-backward-line)) ; ; (add-hook 'ibuffer-hook 'my-ibuffer) ;; JAVA ;; Eclipse has tab=4 by default? ;; (defun tab-4 () (interactive) (setq tab-with 4)) ;; Setting it like this modifies linux source also to tab=4, but that ;; doesn't seem to pose a problem. (defun my-eclipse-tabs-hook () (interactive) (setq tab-width 4)) (add-hook 'java-mode-hook 'my-eclipse-tabs-hook) ; (add-hook 'c-mode-hook 'my-eclipse-tabs-hook) ; (add-hook 'c++-mode-hook 'my-eclipse-tabs-hook) ; (remove-hook 'c-mode-hook 'my-eclipse-tabs-hook) ; (remove-hook 'c++-mode-hook 'my-eclipse-tabs-hook) ;; asm mode ;; FIXME: buffer local from hook? (setq asm-comment-char (string-to-char ";")) (defun my-remove-dos-eol () "Do not show ^M in files containing mixed UNIX and DOS line endings." (interactive) (setq buffer-display-table (make-display-table)) (aset buffer-display-table ?\^M [])) ;; EXO. Note that all distel and flycheck code is part of exo.el ;; Before compilation, load vhdl. It sets a mode hook that's broken. (my-require 'vhdl-mode) (setq compilation-mode-hook '()) (setq compilation-scroll-output t) ;; (setq compilation-error-regexp-alist '(gcc-include)) ;; Compilation (defvar my-compilation-ok nil) (defun my-compilation-finish (buf info) (message info) (when ;; ignore others (grep also calls the ;; compilation-finish-function list) (equal "*compilation*" (buffer-name buf)) (if (string-match "finished" info) (progn (delete-window (get-buffer-window buf)) (and my-compilation-ok (funcall my-compilation-ok))) (with-current-buffer buf (next-error))))) (defun my-compilation-finish-enable (b) (if b (setq compilation-finish-functions '(my-compilation-finish)) (setq compilation-finish-functions '()))) ;; This is actually quite annoying. ;;(my-compilation-finish-enable t) (my-compilation-finish-enable nil) ;; GLSL (autoload 'glsl-mode "glsl-mode" nil t) (add-to-list 'auto-mode-alist '("\\.glsl\\'" . glsl-mode)) ;(add-to-list 'auto-mode-alist '("\\.vert\\'" . glsl-mode)) ;(add-to-list 'auto-mode-alist '("\\.frag\\'" . glsl-mode)) ;; LINUM ;; It's more convenient to use M-x linum-mode ;; (global-linum-mode t) ;; WEB ;; web-mode ;; (add-to-list 'package-archives ;; '("melpa-stable" . "https://stable.melpa.org/packages/") t) ;; (my-require 'web-mode) ;; (setq web-mode-content-types ;; '(("css" . "\\.css\\'\\|\\.css\\.erb\\'") ;; ("jsx" . "\\.jsx\\'") ;; ("javascript" . "\\.js\\'\\|\\.js\\.erb\\'") ;; ("json" . "\\.\\(json\\|jsonld\\)\\'") ;; ("html" . ".")) ;; (add-to-list 'auto-mode-alist '("\\.jsx$" . web-mode)) ;; (defadvice web-mode-highlight-part (around tweak-jsx activate) ;; (if (equal web-mode-content-type "jsx") ;; (let ((web-mode-enable-part-face nil)) ;; ad-do-it) ;; ad-do-it)) ;; MISC MODE CONFIG (put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil) (transient-mark-mode 1) (auto-compression-mode 1) ;(shell-command-completion-mode) (set 'kill-read-only-ok 1) (set 'truncate-partial-width-windows nil) (winner-mode 1) (setq backup-by-copying-when-linked t) ; make sure links are preserved (setq-default indent-tabs-mode nil) (setq mail-self-blind t) (setq show-trailing-whitespace t) (setq backup-by-copying-when-linked t) (prefer-coding-system 'utf-8) (setq tags-case-fold-search nil) ;; tags operations should be case-sensitive (setenv "PAGER" "/bin/cat") (setenv "EDITOR" "/usr/bin/emacsclient") (put 'erase-buffer 'disabled nil) ;; Auto-save (setq tramp-auto-save-directory "~/emacs/backup/") ;; Log file navigation ;; Tools (defun my-open-at (file line endx) (find-file file) (goto-line endx) (set-mark (point)) (goto-line line) (recenter-top-bottom 0) ;;(search-forward-regexp "^Entry:") ;;(search-forward-regexp "^Entry:") ) (defun my-buffer-copy-line (buffer line) (save-excursion (set-buffer buffer) (goto-line line) (let ((beg (line-beginning-position)) (end (line-end-position))) (buffer-substring-no-properties beg end)))) (defvar my-ramblings-current 1) (defvar my-ramblings-last-clause "WHERE file REGEXP 'pool' ORDER BY date DESC") (defun my-ramblings-query (clause) (interactive (list (read-string "sql clause: " my-ramblings-last-clause))) (setq my-ramblings-last-clause clause) (save-excursion (let* ((buf (make-comint "ramblings-index" "sqlite3" nil "-batch" "/home/tom/admin/index/db.sqlite3")) (proc (get-buffer-process buf)) (query (concat "select file,line,endx,date,entry from entries " clause ";\n"))) (set-buffer buf) ;; (comint-simple-send proc ".prompt '' ''\n") ;; apt-get install sqlite3-pcre (comint-simple-send proc ".load /usr/lib/sqlite3/pcre.so\n") (erase-buffer) (comint-simple-send proc query) ;;(message query) ))) (defun my-ramblings-pick (n) (let* ((row-string (my-buffer-copy-line (get-buffer "*ramblings-index*") n)) (row (split-string row-string "|")) (file (car row)) (line (+ 1 (string-to-number (cadr row)))) (endx (+ 1 (string-to-number (caddr row))))) (my-open-at file line endx) row-string)) (defun my-ramblings-rel (n) (let ((buf (get-buffer "*ramblings-index*"))) (if buf (let ((nb-lines (save-excursion (set-buffer buf) (count-lines 1 (buffer-end +1))))) (setq my-ramblings-current (max 1 (min nb-lines (+ n my-ramblings-current)))) (let ((row-string (my-ramblings-pick my-ramblings-current))) (message (concat (number-to-string my-ramblings-current) "/" (number-to-string nb-lines) ;; " " row-string )) )) ;; Start query if there is none. (my-ramblings-query my-ramblings-last-clause)))) (defun my-ramblings-next () (interactive) (my-ramblings-rel 1)) (defun my-ramblings-prev () (interactive) (my-ramblings-rel -1)) (defun my-ramblings-keys () (interactive) (my-set-keys 'global-set-key '(([M-left] my-ramblings-prev) ([M-right] my-ramblings-next)))) ;;(my-ramblings-query "where file regexp 'pool' order by date") ;;(my-ramblings-query "where file regexp 'humanetics' order by date") ;;(my-ramblings-pick 99) ;;(my-open-at "/home/tom/papers/math.txt" 100) ;; GEISER ;; no longer in elpa? download manually and use M-x package-install-file ;; http://download-mirror.savannah.gnu.org/releases/geiser/packages/geiser-0.8.1.tar ;; manual: C-h i m Geiser RET (when (my-require 'geiser) (setq geiser-active-implementations '(racket)) (setq geiser-racket-binary "/usr/local/bin/racket") (setq geiser-repl-use-other-window nil) ;; only one window on M-x run-geiser ) ;; Clipboard interaction through 'xsel' tool. (my-load-library "simpleclip") (when (my-require 'simpleclip) (simpleclip-mode 1)) (my-require 'llvm-mode) (my-require 'org) (my-require 'tramp) (when (my-require 'nxml-mode) (defalias 'xml-mode 'nxml-mode)) (when (my-require 'inf-haskell) ;; Do not change directory to ~/.cabal on load (setq inferior-haskell-find-project-root nil) ;; https://github.com/haskell/haskell-mode/issues/248 ;; (add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent) (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)) (my-require 'rust-mode) (my-require 'tex-site) (my-require 'csharp-mode) ;; Removing this resolved the error "Package assoc is obsolete!" that ;; triggered when loading distel. ;;(when (my-require 'visual-basic-mode) ;; (add-to-list 'auto-mode-alist '("\\.vb\\'" . visual-basic-mode))) (add-to-list 'load-path "/home/tom/emacs/emacs-fsharp-mode") (my-require 'fsharp-mode) ;; mu4e ;; Use Courier folder layout ;; tom@core:~$ mu index --maildir=~tom_zwizwa_be/Maildir (when (my-require 'mu4e) (setq mu4e-maildir "/home/tom_zwizwa_be/Maildir" mu4e-sent-folder "/.Sent" mu4e-drafts-folder "/.Drafts" mu4e-trash-folder "/.Trash")) ;; javascript (my-require 'purescript-mode) (my-require 'nodejs-repl) ;; markdown (my-require 'markdown-mode) ;; (my-load-library "dev") ;; Start ;; See modes.el for my-compilation-ok / my-compilation-finish) ;; Experiment in ironing out local/remote tradeoffs. Main reason for ;; this is to be able to easily switch terminals without constantly ;; having to commit and merge. ;; - run emacs locally (tp) to avoid remote lag ;; - edit files over nfs (zoe, e.g. localally linked exo -> zoe/git/exo) ;; - compile remotely using "x" ;; - run locally ;; FIXME: I dont seem to use this, but the idea is there: switch ;; development focus, which is a global emacs state. ;; (defun my-exo () (interactive) (my-start-dev "cd ~/exo ; smart-remote make" 'my-exo-start)) (defun my-dev-clear () (interactive) (setq my-compilation-ok nil)) ;; Rai (defun my-racket (module) (run-geiser 'racket) (switch-to-geiser-module module)) (defun my-rai () (interactive) (my-racket '(file "/home/tom/rai/test/doodle.rkt"))) ;; Custom per-project setup. Not all of these are present on all hosts. (defun my-load-if-exists (files) (mapcar (lambda (file) (when (file-exists-p file) (load-file file))) files)) (defun my-tty (node baud) (let ((buf (get-buffer node))) (if buf (switch-to-buffer buf) (serial-term node baud)))) (defun my-tty-phytec () (interactive) (my-tty "/tty/phytec" 115200)) (defun my-tty-colibri () (interactive) (my-tty "/tty/colibri" 115200)) (defun my-tty-colibriM4 () (interactive) (my-tty "/tty/colibriM4" 115200)) (my-load-if-exists '( ;; A lot of functionality depends on exo. All the Erlang and ;; flycheck stuff is in there. "~/exo/emacs/exo.el" "~/exo/deps/asm_tools/emcas/nlspec.el" "~/humanetics/notes/humanetics.el" "~/rai/emacs/rai.el" "~/staapl/emacs/staapl.el" "~/src/gw_src/host/gw.el" )) (defun my-siso () (interactive) (let ((haskell-program-name "/home/tom/darcs/meta/siso/ghci.sh")) (run-haskell))) ;; (my-load-library "terminal") ;; HOST/TERMINAL specific config (defun my-frame-minimalistic () (tool-bar-mode -1) (menu-bar-mode -1) (set-frame-parameter nil 'background-color "black") (when (eq window-system 'x) (message "my-frame-minimalistic: configure new X frame") (frame-notice-user-settings) (scroll-bar-mode -1) ;; x-get-selection: Timed out waiting for reply from selection owner (setq x-selection-timeout 100) ;; (setenv "MANWIDTH" (pp-to-string (- (/ (screen-width) 2) 3))) )) (my-frame-minimalistic) (add-hook 'after-make-frame-functions '(lambda (frame) (select-frame frame) (my-frame-minimalistic))) ;; Then to tie local clipboard to remote emacs session, use ;; "ssh -tX emacsclient -t" (setq display-time-day-and-date t display-time-24hr-format t) (display-time) ;; customize dnd (defun my-check-youtube (uri) (string= "https://www.youtube.com/watch" (substring s 0 29))) (defun my-open-youtube (uri) ;; kodi: plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=$VIDEOID (message s)) (defun my-x-dnd-handle-uri-list (w a s) (if (my-check-youtube s) (progn (my-open-youtube s) 'private) (x-dnd-handle-uri-list w a s))) ;; Misc settings ;; Set default frame font. (push '(font . "-xos4-terminus-bold-r-normal--16-160-72-72-c-80-iso8859-1") default-frame-alist) (defadvice load-theme (before theme-dont-propagate activate) (mapc #'disable-theme custom-enabled-themes)) ;; ;; (my-load-library "sh") ;; Running command shells (defun my-run-shell (buf) (interactive "B") (shell (my-wrap-asterisks buf))) (defun my-default-shell () (interactive) (if (and (get-buffer-process (current-buffer)) (equal "*shell*" (buffer-name (current-buffer)))) (my-call-interactively 'rename-buffer-asterisk) (shell) (font-lock-mode -1))) (defun my-wrap-asterisks (name) (concat "*" name "*")) (defun my-rename-buffer-asterisk (buf) (interactive "MRename to **: ") (rename-buffer (my-wrap-asterisks buf))) (defun my-comint-current-input () (buffer-substring-no-properties (process-mark (get-buffer-process (current-buffer))) (point-max))) (defun my-comint-clear-buffer () (interactive) (save-excursion (let ((inhibit-read-only t)) (comint-goto-process-mark) (forward-line 0) (kill-region (point-min) (point))))) (set-default-coding-systems 'utf-8) ;; Last, as this needs hooks set up before triggering mode activation ;; through loading files. (when (my-require 'desktop) (setq desktop-restore-frames nil) (desktop-save-mode 1) (desktop-release-lock "~/.emacs.d/") (desktop-read "~/.emacs.d/") ) ;; server (server-start) (message "emacs.el OK")