2013-01-03 23:55:57 +01:00
|
|
|
#+TITLE: Emacs init
|
|
|
|
#+STYLE: <link href="http://ryuslash.ninth.su/test2.css" rel="stylesheet">
|
|
|
|
#+OPTIONS: author:nil
|
2013-01-15 12:11:41 +01:00
|
|
|
#+STARTUP: showall
|
2013-01-25 00:32:30 +01:00
|
|
|
#+LINK: yoshi-theme http://ryuslash.org/projects/yoshi-theme.html
|
2013-01-03 23:55:57 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
* Emacs init
|
2013-01-03 23:55:57 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Before doing anything else I should make sure that both the
|
|
|
|
directories ~/usr/local/emacs/share/emacs/site-lisp~ and
|
|
|
|
~/usr/share/emacs/site-list~ are included in =load-path=, along with
|
|
|
|
their subdirectories, but only if they haven't already been added
|
|
|
|
and exist. Place them at the end of =load-path= so they don't mess up
|
|
|
|
package precedence.
|
2013-01-04 01:34:02 +01:00
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
2013-01-25 00:32:30 +01:00
|
|
|
(eval-and-compile
|
|
|
|
(defun oni:path-init (dir)
|
|
|
|
"Add DIR to `load-path' and all its subdirectories, unless
|
|
|
|
DIR is already in `load-path'."
|
|
|
|
(unless (or (member dir load-path) (not (file-exists-p dir)))
|
|
|
|
(let ((default-directory dir))
|
|
|
|
(add-to-list 'load-path dir t)
|
|
|
|
(normal-top-level-add-subdirs-to-load-path))))
|
|
|
|
(oni:path-init "/usr/share/emacs/site-lisp")
|
|
|
|
(oni:path-init "/usr/local/emacs/share/emacs/site-lisp"))
|
2013-01-03 23:55:57 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Add my project [[yoshi-theme]] to =custom-theme-load-path= and load it.
|
2013-01-03 23:55:57 +01:00
|
|
|
|
2013-01-04 01:34:02 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
2013-01-25 00:32:30 +01:00
|
|
|
(add-to-list 'custom-theme-load-path "~/projects/emacs/yoshi-theme/")
|
|
|
|
(load-theme 'yoshi t)
|
2013-01-03 23:55:57 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Remove the ~menu-bar~, ~tool-bar~ and ~scroll-bar~ from the UI since I
|
|
|
|
don't use them at all.
|
2013-01-04 02:08:31 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(menu-bar-mode -1)
|
|
|
|
(scroll-bar-mode -1)
|
|
|
|
(tool-bar-mode -1)
|
|
|
|
#+END_SRC
|
2013-01-04 02:08:31 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Add any other interesting paths to =load-path= and, if it exists,
|
|
|
|
load the ~loaddefs.el~ file from these directories.
|
2013-01-04 02:08:31 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(mapc #'(lambda (dir)
|
|
|
|
(add-to-list 'load-path dir)
|
|
|
|
(let ((loaddefs (concat dir "/loaddefs.el")))
|
|
|
|
(when (file-exists-p loaddefs)
|
|
|
|
(load loaddefs))))
|
|
|
|
'("~/projects/emacs/mode-icons" "~/.emacs.d/site-lisp"
|
|
|
|
"~/projects/emacs/pony-mode/src" "~/projects/emacs/php-mode"))
|
|
|
|
#+END_SRC
|
2013-01-15 12:11:41 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Don't ask ~yes~ or ~no~, ask ~y~ or ~n~, I've never had an accidental ~y~ so
|
|
|
|
far.
|
2013-01-15 12:11:41 +01:00
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
2013-01-25 00:32:30 +01:00
|
|
|
(defalias 'yes-or-no-p 'y-or-n-p)
|
2013-01-15 12:11:41 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Use =ibuffer= instead of the default =list-buffers= because it has many
|
|
|
|
more features.
|
2013-01-03 23:55:57 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defalias 'list-buffers 'ibuffer)
|
|
|
|
#+END_SRC
|
2013-01-03 23:55:57 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
Do the same with =hippie-expand= and =dabbrev-expand=.
|
2013-01-03 23:55:57 +01:00
|
|
|
|
2013-01-25 00:32:30 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defalias 'dabbrev-expand 'hippie-expand)
|
|
|
|
#+END_SRC
|
2013-01-28 00:18:29 +01:00
|
|
|
|
|
|
|
Don't show it when ~eldoc~ is running, I almost assume that it is
|
|
|
|
whenever I'm working in a mode that supports it anyway. This should
|
|
|
|
only execute once ~eldoc~ has been loaded.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(eval-after-load "eldoc" '(diminish 'eldoc-mode))
|
|
|
|
#+END_SRC
|
2013-01-28 00:43:57 +01:00
|
|
|
|
2013-02-02 00:56:15 +01:00
|
|
|
Use the standard EMMS configuration and add some MPD settings.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defun oni:emms-init ()
|
|
|
|
"Initialization function for EMMS."
|
|
|
|
(require 'emms-setup)
|
|
|
|
(require 'emms-player-mpd)
|
|
|
|
|
|
|
|
(emms-standard)
|
|
|
|
|
|
|
|
(add-to-list 'emms-info-functions 'emms-info-mpd)
|
|
|
|
(add-to-list 'emms-player-list 'emms-player-mpd)
|
|
|
|
|
|
|
|
(setq emms-player-mpd-server-name "localhost")
|
|
|
|
(setq emms-player-mpd-server-port "6600")
|
|
|
|
(setq emms-player-mpd-music-directory "/mnt/music/mp3"))
|
|
|
|
|
|
|
|
(eval-after-load "emms-source-file" '(oni:emms-init))
|
|
|
|
(setq emms-source-file-default-directory "/mnt/music/")
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Add some keybindings for EMMS.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defun oni:emms-toggle-playing ()
|
|
|
|
"Toggle between playing/paused states."
|
|
|
|
(interactive)
|
|
|
|
(if (eq emms-player-playing-p nil)
|
|
|
|
(emms-start)
|
|
|
|
(emms-pause)))
|
|
|
|
|
|
|
|
(defun oni:start-emms ()
|
|
|
|
"Check to see if the function `emms' exists, if not call
|
|
|
|
`emms-player-mpd-connect' and assume that will have loaded it."
|
|
|
|
(interactive)
|
|
|
|
(unless (fboundp 'emms)
|
|
|
|
(emms-player-mpd-connect))
|
|
|
|
(emms))
|
|
|
|
|
|
|
|
(global-set-key (kbd "<XF86AudioNext>") 'emms-next)
|
|
|
|
(global-set-key (kbd "<XF86AudioPlay>") 'oni:emms-toggle-playing)
|
|
|
|
(global-set-key (kbd "<XF86AudioPrev>") 'emms-previous)
|
|
|
|
(global-set-key (kbd "<XF86AudioStop>") 'emms-stop)
|
|
|
|
(global-set-key (kbd "<XF86Tools>") 'oni:start-emms)
|
|
|
|
#+END_SRC
|
|
|
|
|
2013-02-02 01:08:59 +01:00
|
|
|
Load ~flymake-cursor~ after loading ~flymake~, add Python and Go to
|
|
|
|
"allowed" files and add go error output to error patterns.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defun oni:flymake-init ()
|
|
|
|
"Initialization function for flymake."
|
|
|
|
(require 'flymake-cursor)
|
|
|
|
|
|
|
|
(add-to-list ; Make sure pyflakes is loaded
|
|
|
|
'flymake-allowed-file-name-masks ; for python files.
|
|
|
|
'("\\.py\\'" ext:flymake-pyflakes-init))
|
|
|
|
|
|
|
|
(add-to-list ; Error line repexp for go
|
|
|
|
'flymake-err-line-patterns ; compilation.
|
|
|
|
'("^\\([a-zA-Z0-9_]+\\.go\\):\\([0-9]+\\):\\(.*\\)$"
|
|
|
|
1 2 nil 3))
|
|
|
|
|
|
|
|
(add-to-list ; Go uses makefiles, makes
|
|
|
|
'flymake-allowed-file-name-masks ; flymaking 'easy'.
|
|
|
|
'("\\.go$" flymake-simple-make-init)))
|
|
|
|
|
|
|
|
(eval-after-load "flymake" '(oni:flymake-init))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Disable the GUI for flymake errors, add a bunch of pep8, flymake
|
|
|
|
and pyflakes messages to warning and info patterns, set the log
|
|
|
|
file to somewhere in my home directory and set logging level to 0.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(setq flymake-gui-warnings-enabled nil)
|
|
|
|
(setq flymake-info-line-regexp
|
|
|
|
(eval-when-compile
|
|
|
|
(regexp-opt
|
|
|
|
'("Invalid name"
|
|
|
|
"String statement has no effect"
|
|
|
|
"Missing docstring"
|
|
|
|
"Empty docstring"
|
|
|
|
"multiple imports on one line"
|
|
|
|
"expected 2 blank lines, found 1"
|
|
|
|
"expected 2 blank lines, found 0"
|
|
|
|
"TODO:"
|
|
|
|
"whitespace after '{'"
|
|
|
|
"whitespace before '}'"
|
|
|
|
"whitespace before ':'"
|
|
|
|
"whitespace after '('"
|
|
|
|
"whitespace before ')'"
|
|
|
|
"whitespace after '['"
|
|
|
|
"whitespace before ']'"
|
|
|
|
"the backslash is redundant between brackets"
|
|
|
|
"continuation line over-indented for visual indent"
|
|
|
|
"continuation line under-indented for visual indent"
|
|
|
|
"Too many statements"
|
|
|
|
"comparison to None should be"
|
|
|
|
"missing whitespace around operator"
|
|
|
|
"missing whitespace after ','"
|
|
|
|
"line too long"
|
|
|
|
"at least two spaces before inline comment"
|
|
|
|
"trailing whitespace"
|
|
|
|
"imported but unused"
|
|
|
|
"Unused import"
|
|
|
|
"too many blank lines"))))
|
|
|
|
(setq flymake-log-file-name (expand-file-name "~/.emacs.d/flymake.log"))
|
|
|
|
(setq flymake-log-level 0)
|
|
|
|
(setq flymake-warn-line-regexp
|
|
|
|
(eval-when-compile
|
|
|
|
(regexp-opt '("warning"
|
|
|
|
"Warning"
|
|
|
|
"redefinition of unused"
|
|
|
|
"Redefining built-in"
|
|
|
|
"Redefining name"
|
|
|
|
"Unused argument"
|
|
|
|
"Unused variable"
|
|
|
|
"Dangerous default value {} as argument"
|
|
|
|
"no newline at end of file"
|
|
|
|
"Access to a protected member"))))
|
|
|
|
#+END_SRC
|
|
|
|
|
2013-02-06 11:48:18 +01:00
|
|
|
After loading ~flycheck~ Remove the default python checkers and
|
|
|
|
replace them with my own, which tries both ~flake8~ and ~pylint~.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(eval-after-load "flycheck"
|
|
|
|
'(progn
|
|
|
|
(flycheck-declare-checker python-pycheck
|
|
|
|
"Uses pycheck.sh to check for errors/warnings."
|
|
|
|
:command '("pycheck.sh" source-inplace)
|
|
|
|
:error-patterns
|
|
|
|
'(("^\\(?1:.*\\):\\(?2:[0-9]+\\): Warning (W.*): \\(?4:.*\\)$" warning)
|
|
|
|
("^\\(?1:.*\\):\\(?2:[0-9]+\\): Error (E.*): \\(?4:.*\\)$" error)
|
|
|
|
("^\\(?1:.*\\):\\(?2:[0-9]+\\): \\[F\\] \\(?4:.*\\)$" error)
|
|
|
|
("^\\(?1:.*?\\):\\(?2:[0-9]+\\):\\(?:\\(?3:[0-9]+\\):\\)? \\(?4:E[0-9]+.*\\)$" error)
|
|
|
|
("^\\(?1:.*?\\):\\(?2:[0-9]+\\):\\(?:\\(?3:[0-9]+\\):\\)? \\(?4:W[0-9]+.*\\)$" warning)
|
|
|
|
("^\\(?1:.*\\):\\(?2:[0-9]+\\): \\(?4:.*\\)$" error))
|
|
|
|
:modes 'python-mode)
|
|
|
|
|
|
|
|
(mapc (lambda (c) (delete c flycheck-checkers))
|
|
|
|
'(python-flake8 python-pylint python-pyflakes))
|
|
|
|
(add-to-list 'flycheck-checkers 'python-pycheck)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2013-01-28 00:43:57 +01:00
|
|
|
** Eshell
|
|
|
|
|
|
|
|
Add ~unison~ to the list of =eshell-visual-commands= because it
|
|
|
|
expects unbuffered input and eshell just doesn't give that.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(eval-after-load "em-term"
|
|
|
|
'(add-to-list 'eshell-visual-commands "unison"))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Don't let eshell highlight it's prompt, this way I can decide the
|
|
|
|
colors for it myself.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(setq eshell-highlight-prompt nil)
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
In the prompt:
|
|
|
|
|
|
|
|
- Show the exit status of the last program/command run represented
|
|
|
|
by a green ~+~ and a red ~-~ sign.
|
|
|
|
- Show the current hostname with the =mode-line-buffer-id= face.
|
|
|
|
- Show an abbreviation of the current directory (as seen in ~fish~)
|
|
|
|
using the =font-lock-string-face= face.
|
|
|
|
- If we're in a git repository, show the current branch with the
|
|
|
|
=font-lock-function-name-face= face.
|
|
|
|
- Show the status of priviledges in blue.
|
|
|
|
|
|
|
|
And set the =eshell-prompt-regexp= to
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defun oni:eshell-prompt-function ()
|
|
|
|
"Show a pretty shell prompt."
|
|
|
|
(let ((status (if (zerop eshell-last-command-status) ?+ ?-))
|
|
|
|
(hostname (shell-command-to-string "hostname"))
|
|
|
|
(dir (abbreviate-file-name (eshell/pwd)))
|
|
|
|
(branch
|
|
|
|
(shell-command-to-string
|
|
|
|
"git branch --contains HEAD 2>/dev/null | sed -e '/^[^*]/d'"))
|
|
|
|
(userstatus (if (zerop (user-uid)) ?# ?$)))
|
|
|
|
(concat
|
|
|
|
(propertize (char-to-string status)
|
|
|
|
'face `(:foreground ,(if (= status ?+)
|
|
|
|
"green"
|
|
|
|
"red")))
|
|
|
|
" "
|
|
|
|
(propertize (substring hostname 0 -1) 'face 'mode-line-buffer-id)
|
|
|
|
" "
|
|
|
|
(propertize (oni:shorten-dir dir) 'face 'font-lock-string-face)
|
|
|
|
" "
|
|
|
|
(when (not (string= branch ""))
|
|
|
|
(propertize
|
|
|
|
;; Cut off "* " and "\n"
|
|
|
|
(substring branch 2 -1)
|
|
|
|
'face 'font-lock-function-name-face))
|
|
|
|
" \n"
|
|
|
|
(propertize (char-to-string userstatus)
|
|
|
|
'face `(:foreground "blue"))
|
|
|
|
"> ")))
|
|
|
|
|
|
|
|
(setq eshell-prompt-function 'oni:eshell-prompt-function
|
|
|
|
eshell-prompt-regexp "^[#$]> ")
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Don't truncate lines in eshell, wrap them.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defun oni:eshell-mode-func ()
|
|
|
|
"Function for `eshell-mode-hook'."
|
|
|
|
(setq truncate-lines nil))
|
|
|
|
|
|
|
|
(add-hook 'eshell-mode-hook 'oni:eshell-mode-func)
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Bind the ~f8~ key to easily show eshell.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :tangle init2.el
|
|
|
|
(defun oni:raise-eshell ()
|
|
|
|
"Start or switch back to `eshell'.
|
|
|
|
Also change directories to current working directory."
|
|
|
|
(interactive)
|
|
|
|
(let ((dir (file-name-directory
|
|
|
|
(or (buffer-file-name) "~/")))
|
|
|
|
(hasfile (not (eq (buffer-file-name) nil))))
|
|
|
|
(eshell)
|
|
|
|
(if (and hasfile (eq eshell-process-list nil))
|
|
|
|
(progn
|
|
|
|
(eshell/cd dir)
|
|
|
|
(eshell-reset)))))
|
|
|
|
|
|
|
|
(global-set-key (kbd "<f8>") 'oni:raise-eshell)
|
|
|
|
#+END_SRC
|