;;::::::::::::::;; ;; Simple style ;; ;;::::::::::::::;; (menu-bar-mode 0) (scroll-bar-mode 0) (tool-bar-mode 0) (tooltip-mode 0) (transient-mark-mode 0) (column-number-mode 1) (global-font-lock-mode 1) (setq line-move-visual nil) (mouse-avoidance-mode 'exile) (setq truncate-partial-width-windows nil) ;;::::::::::;; ;; Packages ;; ;;::::::::::;; (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) (package-initialize) ;;; Custom (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. '(indent-tabs-mode nil) '(package-selected-packages (quote (browse-kill-ring cargo company counsel dash diminish flycheck flycheck-rust geiser haskell-mode htmlize inform7-mode ivy j-mode julia-mode julia-repl lua-mode magit modern-cpp-font-lock nasm-mode paredit picolisp-mode python-mode racer slime typing w3m web-mode yaml-mode)))) ;;::::::::::::::::;; ;; Package setups ;; ;;::::::::::::::::;; ;;; Ivy (ivy-mode 1) ;; instead of ido-mode (setq ivy-magic-tilde nil) (diminish 'ivy-mode) ;;; Swiper (global-set-key (kbd "C-S-s") 'swiper) ;;; Counsel ;; (counsel-mode 1) ;;; Company ;; (global-company-mode 1) (setq company-tooltip-align-annotations t) ;;; Magit (global-set-key (kbd "C-x g") 'magit-status) ;;:::::::::::::::::::::::;; ;; Programming languages ;; ;;:::::::::::::::::::::::;; ;;; C++ (modern-c++-font-lock-global-mode t) (diminish 'modern-c++-font-lock-mode "") (font-lock-add-keywords 'c++-mode '(("\\<\\(Q_OBJECT\\|signals\\|public slots\ \\|protected slots\\|private slots\\)\\>" . font-lock-keyword-face))) (dolist (mode '(c++-mode c-mode tcl-mode shell-script-mode python-mode haskell-mode)) (font-lock-add-keywords mode '(("\\(kutykurutty\\)" 1 font-lock-warning-face t)))) (setq auto-mode-alist (append (list '("\\.tcc$" . c++-mode) '("\\.thh$" . c++-mode) '("\\.in$" . c++-mode) '("\\.tin$" . c++-mode)) auto-mode-alist)) ;;; Factor (add-to-list 'load-path "~/share/factor/misc/fuel") (setq fuel-factor-root-dir "~/share/factor") (autoload 'factor-mode "factor-mode" "Major mode for editing Factor code" t) (autoload 'fuel-mode "fuel-mode" "Major mode for interacting with Factor" t) ;;; Forth (add-to-list 'auto-mode-alist '("\\.fb$" . forth-block-mode)) ;;; Haskell (set-variable 'haskell-program-name "ghci") (defun run-cabal () (interactive) (let ((haskell-program-name "cabal repl")) (run-haskell))) (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) (add-hook 'haskell-mode-hook 'turn-on-haskell-indent) (add-hook 'haskell-mode-hook 'interactive-haskell-mode) (add-hook 'haskell-mode-hook (lambda () (local-set-key "\C-cd" 'haskell-hoogle) (local-set-key "\C-c\C-d" 'haskell-hoogle))) ;;; Julia (setq julia-repl-executable-records '((default "/home/salvi/bin/julia"))) ;;; Maxima (add-to-list 'load-path "/usr/share/maxima/5.41.0/emacs") (autoload 'imaxima "imaxima" "Maxima mode with images" t) (autoload 'maxima "maxima" "Maxima mode" t) (autoload 'imath-mode "imath" "Math formula input" t) ;;; Octave (autoload 'octave-mode "octave-mod" "Octave mode" t) (setq inferior-octave-prompt ">> ") (add-to-list 'auto-mode-alist '("\\.m$" . octave-mode)) ;;; Rust (setq racer-rust-src-path "/home/salvi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src") (add-hook 'rust-mode-hook 'racer-mode) (add-hook 'racer-mode-hook 'eldoc-mode) (add-hook 'racer-mode-hook 'company-mode) (add-hook 'rust-mode-hook 'cargo-minor-mode) (add-hook 'rust-mode-hook 'flycheck-mode) (add-hook 'flycheck-mode-hook #'flycheck-rust-setup) (add-hook 'rust-mode-hook (lambda () (local-set-key (kbd "TAB") #'company-indent-or-complete-common))) ;;:::::::::::::::::::::::::::;; ;; Lisp / Scheme interaction ;; ;;:::::::::::::::::::::::::::;; ;;; Safe variables (setq safe-local-variable-values '((syntax . common-lisp))) ;;; Loading Slime (add-to-list 'auto-mode-alist '("\\.asd$" . lisp-mode)) (setq common-lisp-hyperspec-root "file:///home/salvi/programming/lisp/HyperSpec/" slime-startup-animation nil slime-complete-symbol-function 'slime-fuzzy-complete-symbol slime-fuzzy-completion-in-place t slime-net-coding-system 'utf-8-unix) (slime-setup '(slime-fancy)) ;;; Common Lisps (setq slime-lisp-implementations '((sbcl ("/usr/bin/sbcl" "--dynamic-space-size" "512")) (ccl ("/home/salvi/share/ccl/lx86cl64")) (ecl ("/home/salvi/project/ecls-ecl/test/bin/ecl")) ; "/usr/bin/ecl" (clisp ("/usr/bin/clisp")) (abcl ("/usr/bin/java" "-jar" "/home/salvi/share/abcl/abcl.jar")) (lispworks ("/usr/bin/lispworks-personal-6-0-1-x86-linux" "")))) (defun cl () (interactive) (let ((slime-default-lisp 'sbcl)) (slime))) ;;; Parenthesis & Co (show-paren-mode 1) (require 'paredit) (define-key paredit-mode-map (kbd "[") 'paredit-open-parenthesis) (define-key paredit-mode-map (kbd "]") 'paredit-close-parenthesis-and-newline) (define-key paredit-mode-map (kbd "M-[") 'paredit-wrap-sexp) (define-key paredit-mode-map (kbd "M-]") 'paredit-close-parenthesis) (define-key paredit-mode-map (kbd "(") 'paredit-open-bracket) (define-key paredit-mode-map (kbd ")") 'paredit-close-bracket-and-newline) (define-key paredit-mode-map (kbd "{") 'paredit-open-curly) (define-key paredit-mode-map (kbd "}") 'paredit-close-curly-and-newline) (dolist (hooks '(slime-mode-hook slime-repl-mode-hook emacs-lisp-mode-hook inferior-emacs-lisp-mode-hook lisp-interaction-mode-hook scheme-mode-hook inferior-scheme-mode-hook ielm-mode-hook)) (add-hook hooks '(lambda () (setq show-trailing-whitespace nil) (paredit-mode 1) (font-lock-add-keywords nil '(("\\(kutykurutty\\)" 1 font-lock-warning-face t)))))) ;;; Indentation and Font Lock (put 'with-accessors 'common-lisp-indent-function 2) (font-lock-add-keywords 'lisp-mode '(("\\(TODO\\)" 1 font-lock-warning-face t) ("(\\(def.*?\\)\\>[ '(]*\\(setf[ ]+\\sw+)\\|\\sw+\\)?" (1 font-lock-keyword-face) (2 (let ((name (match-string 2))) (when name (cond ((string-match "^\\*" name) font-lock-variable-name-face) ((string-match "^\\+" name) font-lock-constant-name-face) (t font-lock-function-name-face))))))) t) (define-key slime-mode-map (kbd "TAB") 'slime-indent-and-complete-symbol) ;;; Eval & Next (defun slime-eval-next-sexp-and-find-next () (interactive) (paredit-forward) (slime-eval-last-expression) (goto-char (1- (search-forward "(")))) (define-key slime-mode-map (kbd "M-RET") 'slime-eval-next-sexp-and-find-next) ;;; Scheme (add-hook 'geiser-mode-hook (lambda () (paredit-mode t))) (add-hook 'geiser-repl-mode-hook (lambda () (paredit-mode t))) (setq geiser-active-implementations '(chicken racket guile chibi chez mit)) (setq geiser-default-implementation 'chicken) ;;; Emacs Lisp Stuff (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) ;;::::::::::::::::::::::::::::;; ;; My input method extensions ;; ;;::::::::::::::::::::::::::::;; (add-to-list 'load-path "~/share/emacs") ;; (load "erbi") ;; (load "greek-babel-modification") ;; (load "latin-macron") (load "turkish") ;; (load "turkish-prefix") ;; (load "yoruba") ;;:::::::::::::::::::::::::::::::::::::;; ;; My other language learning snippets ;; ;;:::::::::::::::::::::::::::::::::::::;; (autoload 'pflr "pflr" "Chinese Pronounciation Exercise" t) (autoload 'swahili-dictionary "swahili" "Swahili Dictionary" t) (autoload 'flashdeck "flashdeck" "Emacs Flashdeck" t) (autoload 'htmlize-dictionary-buffer "htmlize-dictionary" "" t) ;;:::::;; ;; IRC ;; ;;:::::;; (require 'erc) (setq erc-header-line-format nil) (require 'erc-track) (setq erc-track-mode t) (require 'erc-join) (setq erc-autojoin-mode t) (erc-timestamp-mode t) (setq erc-timestamp-format "[%H:%M:%S]") (require 'erc-notify) (add-to-list 'erc-modules 'autoaway) (setq erc-hide-list '("JOIN" "PART" "QUIT")) (setq erc-auto-discard-away t) (setq erc-autoaway-idle-method 'irc) ; 'user / 'emacs / 'irc (setq erc-autoaway-idle-seconds (* 30 60)) (setq erc-autoaway-message "[auto-away]") (defvar irc-list '(("LiberaChat" "irc.libera.chat" "liberachat" 6667 "salvipeter" ("#emacs" "#lisp" "#julia" "##prolog" "#sml" "#nim" "#tcl")) ;; "##c++" "#rust" ;; "#concatenative" "#forth" ;; "#haskell" "#ocaml" ;; "#scheme" "#lispcafe" "#racket" "#sbcl" "#chicken" "#guile" "#picolisp" ("IRCNet" "irc.atw.hu" "atw" 6667 "szun" ("#shampoonokoibito")) ("BitlBee" "localhost" "bitlbee" 6667 "salvipeter" ())) "My IRC connections.") (defvar erc-authinfo (let ((buffer (find-file-noselect "~/.erc-authinfo"))) (prog1 (setq erc-authinfo (read buffer)) (kill-buffer buffer))) "The configuration file should contain a list of entries, eg. ((\"irc.server.org\" . \"password\") (bitlbee . \"password\")). Note that for the bitlbee server the first part is a symbol, not a string.") (defun erc-toggle-tracking () (interactive) (let ((name (buffer-name (current-buffer)))) (if (member name erc-track-exclude) (progn (setf erc-track-exclude (remove name erc-track-exclude)) (message "Tracking is turned on.")) (progn (push name erc-track-exclude) (message "Tracking is turned off"))))) (define-key erc-mode-map (kbd "C-c TAB") 'erc-toggle-tracking) (define-key erc-track-minor-mode-map (kbd "C-c `") 'erc-track-switch-buffer) (setq erc-prompt ">" erc-user-full-name "Peter Salvi" erc-email-userid "vukung@yahoo.com" erc-notify-list '("zsu" "zsu-msn" "ecco" "csalad" "csalad-gm") erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE" "324" "329" "332" "333" "353" "477")) (add-hook 'erc-join-hook 'bitlbee-identify) (defun bitlbee-identify () "If we're on the bitlbee server, send the identify command to the &bitlbee channel." (when (string= "&bitlbee" (buffer-name)) (erc-message "PRIVMSG" (format "root identify %s" (cdr (assoc 'bitlbee erc-authinfo)))))) (defun irc (server) "Connects to one of the servers I use. With a universal argument it does not join any channels automatically." (interactive (let* ((completion-ignore-case t) (string (completing-read "IRC Server: " irc-list nil t))) (list string))) (setq erc-autojoin-channels-alist (unless current-prefix-arg (mapcar (lambda (s) (cons (third s) (car (last s)))) irc-list))) (let ((data (rest (assoc server irc-list)))) (erc :server (first data) :port (third data) :nick (fourth data) :password (cdr (assoc (first data) erc-authinfo))))) ;;; Dynamic filling in ERC buffers (add-hook 'window-configuration-change-hook '(lambda () (save-excursion (walk-windows (lambda (w) (let ((buffer (window-buffer w))) (set-buffer buffer) (when (eq major-mode 'erc-mode) (make-variable-buffer-local 'erc-fill-column) (setq erc-fill-column (- (window-width w) 2))))))))) ;;::::::::::;; ;; Browsing ;; ;;::::::::::;; (require 'w3m) (require 'w3m-search) (setq w3m-home-page "http://www.google.com/") (setq browse-url-browser-function 'w3m-browse-url) (add-to-list 'w3m-search-engine-alist '("wikipedia" "http://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go" nil)) (add-to-list 'w3m-uri-replace-alist '("\\`wi:" w3m-search-uri-replace "wikipedia")) ;;::::::;; ;; Mail ;; ;;::::::;; (setq gnus-directory "~/.news/") (setq gnus-select-method '(nntp "nntp.aioe.org")) (setq user-mail-address "vukung@yahoo.com") (setq user-full-name "Peter Salvi") ;;:::::::::;; ;; Display ;; ;;:::::::::;; ;;; Colors (defun swap-colors () "Swaps the background and foreground colors" (interactive) (let* ((frame (selected-frame)) (bg (frame-parameter frame 'background-color))) (set-background-color (frame-parameter frame 'foreground-color)) (set-foreground-color bg))) ;;; Themes (defvar theme-list '(("Dark" "black" "wheat") ("Wheat" "wheat" "black") ("Blue" "azure2" "dark blue")) "My color themes.") (defun theme (name) "Selects a predefined theme" (interactive (let* ((completion-ignore-case t) (string (completing-read "Theme: " theme-list nil t))) (list string))) (let ((theme (assoc name theme-list))) (set-background-color (cadr theme)) (set-foreground-color (cadr (cdr theme))))) (defun create-fontset (name fontname attributes) (let* ((name (concat "fontset-" name)) (fontset (concat "-*-fixed-medium-r-normal--16-*-*-*-*-*-" name)) (font (concat fontname "-" attributes))) (create-fontset-from-fontset-spec fontset) (set-fontset-font name 'ascii font) (set-fontset-font name 'latin-iso8859-1 font) (set-fontset-font name 'latin-iso8859-2 font))) (defun set-fontset-fallbacks () (set-fontset-font nil 'mule-unicode-0100-24ff ; default fallback "DejaVu Sans Mono") (set-fontset-font nil (cons (decode-char 'ucs #x0900) (decode-char 'ucs #x097f)) ; Devanagari "Siddhanta-12") (set-fontset-font nil (cons (decode-char 'ucs #x0600) (decode-char 'ucs #x06ff)) ; Arabic "Scheherazade-18")) (when window-system (server-start) (create-fontset "terminus" "Terminus" "12:bold") (create-fontset "inconsolata" "Inconsolata" "12") (create-fontset "hack" "Hack" "10.5") (set-frame-font "fontset-hack") (set-fontset-fallbacks) (defvar fontset-list '("terminus" "inconsolata" "hack")) (defun fontset (name) "Selects a predefined fontset" (interactive (let* ((completion-ignore-case t) (string (completing-read "Fontset: " fontset-list nil t))) (list string))) (set-frame-font (concat "fontset-" name)) (set-fontset-fallbacks)) (defun frame-size-revert () "Restores the 100x45 frame size on the selected frame." (interactive) (set-frame-size (selected-frame) 100 45))) ;;::::::::::::::::::::::::;; ;; Miscellaneous snippets ;; ;;::::::::::::::::::::::::;; ;;; Fixed-length Number Insertion (defun insert-number-register (number register) "Inserts a number stored in REGISTER with at least NUMBER digits." (interactive "p\ncInsert number in register: ") (or (numberp (get-register register)) (error "Register does not contain a number")) (insert-register register) (if (and number (> number (- (mark) (point)))) (let ((iter (- number (- (mark) (point))))) (while (> iter 0) (princ 0 (current-buffer)) (backward-char) (setq iter (1- iter)))))) (defun goto-last-edit () "Moves point to the buffer's last edit." (interactive) (if (or (null buffer-undo-list) (eq buffer-undo-list t)) (message "This buffer has not been edited yet.") (let ((tail (cdr buffer-undo-list)) (last-pos nil)) (while (and tail (null last-pos)) (setq next (car tail)) (cond ;; POSITION ((integerp next) (setq last-pos next)) ;; nil ((atom next) nil) ;; (TEXT . POSITION) ((stringp (car next)) (setq last-pos (abs (cdr next)))) ;; (BEG . END) ((integerp (car next)) (setq last-pos (cdr next))) ;; (nil PROPERTY VALUE BEG . END) ((null (car next)) nil)) ;; (MARKER . DISTANCE) , (t HIGH . LOW) ? (setq tail (cdr tail))) (if last-pos (goto-char last-pos) (message "Cannot find last edit."))))) (defun scroll-n-lines-up (&optional n) "Scroll up N lines (1 by default)." (interactive "P") (scroll-up (prefix-numeric-value n))) (defun scroll-n-lines-down (&optional n) "Scroll down N lines (1 by default)." (interactive "P") (scroll-down (prefix-numeric-value n))) (defun forward-slide (&optional count) (interactive "p") (goto-char (point-min)) ; to be in the [start, end) interval (widen) (forward-page count) (narrow-to-page)) (defun backward-slide (&optional count) (interactive "p") (widen) (backward-page (1+ count)) (narrow-to-page)) (defun move-content-to-top () "Move a section of my homepage to the top." (interactive) (let ((start (search-backward "