2016-10-14 14:03:30 +02:00
;; Main options
2012-10-12 22:02:52 +02:00
2017-05-08 09:00:14 +02:00
;; Minimal UI. Run early to hide it as soon as possible.
2014-03-08 11:48:35 +01:00
( setq inhibit-startup-screen t )
( if ( fboundp 'tool-bar-mode ) ( tool-bar-mode -1 ) )
( menu-bar-mode -1 )
( when ( fboundp 'set-scroll-bar-mode )
( set-scroll-bar-mode 'left )
( scroll-bar-mode -1 )
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map ( kbd " C-<f6> " ) 'toggle-scroll-bar ) )
2014-03-08 11:48:35 +01:00
2013-06-18 17:14:31 +02:00
;; Remember last cursor position.
2013-05-31 19:01:32 +02:00
( require 'saveplace )
( setq save-place-file ( concat emacs-cache-folder " saveplace " ) )
2016-10-05 06:56:16 +02:00
( setq-default save-place-mode t )
2014-03-03 21:05:09 +01:00
;; When the daemon is killed abruptly, places are not saved. Adding this hook
;; allows to save places at a strategic moment.
( add-hook 'before-save-hook 'save-place-kill-emacs-hook )
2013-05-31 19:01:32 +02:00
2014-03-10 11:26:12 +01:00
;; url-cookie
( setq url-cookie-file ( concat emacs-cache-folder " url.cookies " ) )
2014-02-21 20:14:50 +01:00
;; Bookmark file to cache folder.
( setq bookmark-default-file ( concat emacs-cache-folder " emacs.bmk " ) )
2016-09-23 15:26:24 +02:00
;; Recent files.
2016-06-09 18:20:38 +02:00
( setq recentf-save-file ( concat emacs-cache-folder " recentf " ) )
2013-06-18 17:14:31 +02:00
;; Disable autosave features.
2013-05-31 19:01:32 +02:00
( setq auto-save-default nil )
2013-06-04 20:51:04 +02:00
( setq auto-save-list-file-prefix nil )
2013-05-31 19:01:32 +02:00
2013-06-18 17:14:31 +02:00
;; Place backup files in specific directory.
2013-05-31 19:01:32 +02:00
( setq backup-directory-alist
2013-07-09 11:25:15 +02:00
` ( ( " .* " . , ( concat emacs-cache-folder " backups/ " ) ) ) )
2013-06-12 22:56:30 +02:00
;; Other backup options.
2016-12-11 06:15:54 +01:00
; (setq backup-inhibited t)
; (setq make-backup-files t)
; (setq version-control t)
2013-05-31 19:01:32 +02:00
2013-02-28 22:09:31 +01:00
;; Default mode
( setq default-major-mode 'text-mode )
2013-06-18 17:14:31 +02:00
;; Disable suspend key since it is useless on Emacs server.
2013-06-12 17:05:10 +02:00
( global-unset-key ( kbd " C-z " ) )
( global-unset-key ( kbd " C-x C-z " ) )
2013-03-04 17:31:57 +01:00
;; Make questions less annoying.
2013-01-10 17:33:33 +01:00
( defalias 'yes-or-no-p 'y-or-n-p )
2012-10-12 15:23:36 +02:00
2013-10-20 18:19:19 +02:00
;; Allow some protected functions.
( put 'upcase-region 'disabled nil )
( put 'downcase-region 'disabled nil )
2014-02-23 13:54:39 +01:00
( put 'narrow-to-page 'disabled nil )
2013-10-20 18:19:19 +02:00
2013-06-27 17:06:07 +02:00
;; Print column number in mode line.
2013-01-10 17:33:33 +01:00
( column-number-mode 1 )
2012-10-12 15:23:36 +02:00
2013-06-27 17:06:07 +02:00
;; Print buffer size in mode line.
( size-indication-mode 1 )
2013-03-04 17:31:57 +01:00
;; Kill whole line including \n.
2013-01-10 17:33:33 +01:00
( setq kill-whole-line t )
2012-10-12 15:23:36 +02:00
2013-02-26 12:04:44 +01:00
;; Alternative scrolling
2017-05-08 09:00:14 +02:00
( setq scroll-error-top-bottom t )
2012-10-12 15:23:36 +02:00
2017-05-08 09:00:14 +02:00
;; Narrow page navigation.
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map ( kbd " C-x M-n " ) ( lambda ( ) ( interactive ) ( narrow-to-page 1 ) ) )
( define-key mickey-minor-mode-map ( kbd " C-x M-p " ) ( lambda ( ) ( interactive ) ( narrow-to-page -1 ) ) )
2014-02-23 13:54:39 +01:00
2012-10-12 15:23:36 +02:00
;; Line numbers
2013-05-24 11:44:23 +02:00
( add-hook 'find-file-hook ( lambda ( ) ( linum-mode 1 ) ) )
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map ( kbd " C-<f5> " ) 'linum-mode )
2017-05-21 23:50:23 +02:00
;; Emacs-nox does not display a fringe after the linum: Setting linum-format in
;; linum-before-numbering-hook is not the right approach as it will change the
;; type of linum-format in the middle. See linum-update-window.
;; See http://stackoverflow.com/questions/3626632/right-align-line-numbers-with-linum-mode
;; and http://stackoverflow.com/questions/3626632/right-align-line-numbers-with-linum-mode.
;; The complexity is not worth the benefit.
2012-10-12 15:23:36 +02:00
;; Indentation
2014-10-24 14:58:38 +02:00
( setq-default tab-width 2 )
( defvaralias 'standard-indent 'tab-width )
( setq-default indent-tabs-mode t )
2014-10-30 18:18:08 +01:00
2014-10-30 20:51:42 +01:00
;; Lisp should not use tabs.
2017-05-15 07:46:59 +02:00
( mapc
2014-10-30 20:51:42 +01:00
( lambda ( hook )
( add-hook
hook
( lambda ( )
( setq indent-tabs-mode nil ) ) ) )
' ( lisp-mode-hook emacs-lisp-mode-hook ) )
2016-06-09 18:25:18 +02:00
( add-hook
'emacs-lisp-mode-hook
( lambda ( )
( local-set-key ( kbd " M-. " ) 'find-symbol-at-point ) ) )
2014-11-10 00:02:42 +01:00
( add-hook
'change-log-mode-hook
( lambda ( )
( setq tab-width 2 )
( setq left-margin 2 ) ) )
2014-10-30 18:18:08 +01:00
;; This needs to be set globally since they are defined as local variable and
;; Emacs does not know how to set an alias on a local variable.
( defvaralias 'c-basic-offset 'tab-width )
( defvaralias 'sh-basic-offset 'tab-width )
2012-10-12 15:23:36 +02:00
;; Line by line scrolling
( setq scroll-step 1 )
2015-04-26 17:17:08 +02:00
;; Autofill tweak.
2014-02-23 13:54:39 +01:00
( setq sentence-end-double-space nil )
2016-06-10 18:05:05 +02:00
;; There is no prog-mode-hook on Emacs<24.
2016-06-08 14:14:29 +02:00
( require 'functions ) ; for `page-number-mode'
2014-03-09 12:24:26 +01:00
( add-hook
'prog-mode-hook
( lambda ( )
2016-06-10 18:05:05 +02:00
( page-number-mode t ) ) )
2014-03-05 10:58:42 +01:00
2016-06-10 18:05:05 +02:00
( define-key mickey-minor-mode-map ( kbd " C-<f7> " ) 'whitespace-mode )
2014-11-12 15:09:14 +01:00
( setq
whitespace-style
2016-06-10 18:05:05 +02:00
' ( face empty indentation space-after-tab space-before-tab tab-mark trailing ) )
;; `whitespace-report' will mistakenly always report empty lines at
;; beginning and end of buffer as long as there is at least one empty line.
;; `whitespace-cleanup' works properly however.
;; DONE: Reported at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23740.
2014-01-09 11:53:09 +01:00
; (setq whitespace-action '(report-on-bogus))
2013-03-08 15:46:03 +01:00
2014-10-26 18:04:11 +01:00
;; WARNING: this can break some configuration files needing whitespaces at the
2017-05-08 09:00:14 +02:00
;; end. This can also slow down saving on big files.
2016-06-08 14:14:29 +02:00
; (require 'functions) ; for `sanitize'
2014-10-26 18:04:11 +01:00
; (add-hook 'before-save-hook 'sanitize)
2016-10-17 09:11:51 +02:00
( add-hook 'before-save-hook 'delete-trailing-whitespace )
2013-03-08 15:46:03 +01:00
2014-02-21 20:41:11 +01:00
;; Hippie expand.
2016-06-09 11:27:24 +02:00
;; (define-key mickey-minor-mode-map (kbd "M-/") 'hippie-expand)
2014-02-21 20:41:11 +01:00
2012-10-12 15:23:36 +02:00
;; Abbreviation support
2014-02-13 17:30:36 +01:00
( setq-default abbrev-mode t )
2012-10-12 15:23:36 +02:00
;; Set Fill Column
( setq-default fill-column 80 )
( add-hook 'text-mode-hook 'turn-on-auto-fill )
2013-09-30 19:11:22 +02:00
;; Set man pages to display on a 80 character wide window.
2012-10-12 15:23:36 +02:00
( setenv " MANWIDTH " " 80 " )
2016-07-21 13:37:46 +02:00
;; Enforce horizontal splitting. 140 means that the window is large enough to
;; hold 2 other windows of 70 columns.
( setq split-height-threshold nil )
( setq split-width-threshold 140 )
2013-06-18 17:14:31 +02:00
;; Windmove mode: easy window switching with Shift+arrows.
2012-10-12 15:23:36 +02:00
( when ( fboundp 'windmove-default-keybindings )
2016-10-16 05:28:19 +02:00
( define-key mickey-minor-mode-map ( kbd " M-s-h " ) 'windmove-left )
( define-key mickey-minor-mode-map ( kbd " M-s-j " ) 'windmove-down )
( define-key mickey-minor-mode-map ( kbd " M-s-k " ) 'windmove-up )
( define-key mickey-minor-mode-map ( kbd " M-s-l " ) 'windmove-right ) )
2012-10-12 15:23:36 +02:00
2013-06-18 17:14:31 +02:00
;; Make Emacs use environment browser, or w3m if BROWSER is not set.
2013-02-26 18:30:31 +01:00
( setq browse-url-generic-program
( executable-find
( let ( ( b ( getenv " BROWSER " ) ) )
( if b b " w3m " ) ) )
browse-url-browser-function 'browse-url-generic )
2012-11-13 18:46:20 +01:00
2014-03-05 10:58:42 +01:00
;; Default ispell dictionnay. If not set, Emacs uses the current locale.
2015-04-17 15:47:48 +02:00
( setq ispell-dictionary " english " )
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map
2014-02-21 15:23:25 +01:00
( kbd " <f5> " )
2015-04-17 15:47:48 +02:00
( lambda ( ) ( interactive ) ( ispell-change-dictionary " english " ) ) )
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map
2014-02-21 15:23:25 +01:00
( kbd " <f6> " )
2015-04-17 15:47:48 +02:00
( lambda ( ) ( interactive ) ( ispell-change-dictionary " francais " ) ) )
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map
2014-02-21 15:23:25 +01:00
( kbd " <f7> " )
2015-04-17 15:47:48 +02:00
( lambda ( ) ( interactive ) ( ispell-change-dictionary " svenska " ) ) )
2012-12-21 21:30:54 +01:00
2013-01-08 00:36:02 +01:00
;; Long paragraphs. Useful for quick navigation with backward-paragraph and
;; forward-paragraph.
( setq paragraph-start "
" )
2013-01-10 15:57:07 +01:00
;; Show matching parenthesis
( show-paren-mode 1 )
;; By default, there’ s a small delay before showing a matching parenthesis. Set
;; it to 0 to deactivate.
( setq show-paren-delay 0 )
2016-10-05 06:56:16 +02:00
( setq show-paren-when-point-inside-paren t )
2013-01-10 15:57:07 +01:00
2013-03-01 16:43:21 +01:00
;; Electric Pairs to auto-complete () [] {} "" etc. You can use it on regions.
2015-09-10 09:57:58 +02:00
;; (if (>= emacs-major-version 24)
;; (electric-pair-mode 1))
2013-02-27 22:35:16 +01:00
2016-11-27 12:40:13 +01:00
;; Run terminal asynchronously in current `default-directory'.
;; This requires SHELL_CD to be used in the shell config.
( define-key mickey-minor-mode-map ( kbd " C-x M-RET " )
( lambda ( ) ( interactive )
( let ( ( term ( getenv " TERMCMD " ) ) )
( when ( executable-find term )
( start-process " dummy " nil " env " ( concat " SHELL_CD= " default-directory ) term ) ) ) ) )
2013-03-01 16:43:21 +01:00
;; Calendar ISO display.
2013-02-27 22:35:16 +01:00
( setq calendar-week-start-day 1 )
( setq calendar-date-style 'iso )
2013-02-28 22:09:31 +01:00
2013-09-30 19:59:13 +02:00
;; Compilation bindings and conveniences.
2014-03-13 13:50:56 +01:00
( setq compilation-ask-about-save nil )
2017-05-22 16:12:30 +02:00
( with-eval-after-load 'compile
;; Making `compilation-directory' local only works with `recompile'
;; and if `compile' is never used. In such a scenario,
;; `compile-command' is not saved by `recompile' itself which adds a
;; lot of bookkeeping.
;; (make-variable-buffer-local 'compilation-directory)
;; (make-variable-buffer-local 'compile-history)
( make-variable-buffer-local 'compile-command ) )
2017-05-08 11:51:23 +02:00
;; Don't set these bindings in mickey as we might have to override them from
;; mode hooks.
( global-set-key ( kbd " C-<f10> " ) 'compile )
2017-05-11 19:38:28 +02:00
( global-set-key ( kbd " <f10> " ) ( lambda ( ) ( interactive ) ( compile compile-command ) ) ) ; Do not use recompile since we want to change de compilation folder to the current buffer.
2017-05-08 11:51:23 +02:00
( global-set-key ( kbd " <f11> " ) 'previous-error )
( global-set-key ( kbd " <f12> " ) 'next-error )
2014-03-13 13:50:56 +01:00
2013-09-30 19:59:13 +02:00
;; Code browsing: make C-M-e jump to next function instead of the end of the current function.
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map ( kbd " C-M-e " ) ( lambda ( ) ( interactive ) ( beginning-of-defun -1 ) ) )
2013-06-12 17:05:10 +02:00
2013-06-12 23:40:20 +02:00
;; Common LISP
( setq inferior-lisp-program " clisp " )
2015-04-25 13:47:00 +02:00
( defadvice desktop-owner ( after pry-from-cold-dead-hands activate )
" Don't allow dead emacsen to own the desktop file. "
( when ( not ( emacs-process-p ad-return-value ) )
( setq ad-return-value nil ) ) )
2017-05-08 09:00:14 +02:00
;; Desktop-mode
2017-04-28 07:24:51 +02:00
;; Let Emacs auto-load/save sessions only when running the daemon.
2017-05-08 09:00:14 +02:00
;; `server-running-p' is only useful once the daemon is started and cannot be
;; used for initialization. We use `daemonp' instead.
2017-04-28 07:24:51 +02:00
( when ( daemonp )
2013-06-16 16:57:23 +02:00
( desktop-save-mode 1 )
( setq history-length 250 )
( setq desktop-dirname ( concat emacs-cache-folder " desktop " ) )
2015-04-17 16:16:10 +02:00
( unless ( file-directory-p desktop-dirname )
( make-directory desktop-dirname t ) )
2013-06-16 16:57:23 +02:00
( setq desktop-path ` ( , desktop-dirname ) )
2017-05-12 08:34:17 +02:00
;; TODO: `compile-history' should be buffer local but that does not work.
;; http://user42.tuxfamily.org/compile-history-local/index.html
;; http://stackoverflow.com/questions/22995203/one-compile-command-per-buffer-not-directory
; (add-to-list 'desktop-locals-to-save 'compile-history)
2015-05-09 17:38:03 +02:00
( add-to-list 'desktop-locals-to-save 'compile-command ) )
2013-06-16 16:57:23 +02:00
2014-02-21 20:14:50 +01:00
;; GMP documentation
2017-05-22 16:12:30 +02:00
( with-eval-after-load " info-look "
( let ( ( mode-value ( assoc 'c-mode ( assoc 'symbol info-lookup-alist ) ) ) )
( setcar ( nthcdr 3 mode-value )
( cons ' ( " (gmp)Function Index " nil " ^ -.* " " \\ > " )
( nth 3 mode-value ) ) ) ) )
2013-11-11 13:51:16 +01:00
2017-05-08 09:00:14 +02:00
;; Buffer names.
2014-02-21 20:14:50 +01:00
( require 'uniquify )
( setq uniquify-buffer-name-style 'forward )
2013-07-04 10:37:18 +02:00
2014-03-13 16:13:21 +01:00
;; Skeleton settings
( require 'functions )
;; Do not expand abbrevs in skeletons.
( setq-default skeleton-further-elements ' ( ( abbrev-mode nil ) ) )
( add-hook 'skeleton-end-hook 'skeleton-make-markers )
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map ( kbd " C-> " ) 'skeleton-next-position )
( define-key mickey-minor-mode-map ( kbd " C-< " ) ( lambda ( ) ( interactive ) ( skeleton-next-position t ) ) )
2014-03-13 16:13:21 +01:00
2014-02-12 18:31:00 +01:00
;; Disable prompt (but leave warning) on git symlink.
( setq vc-follow-symlinks t )
2014-03-20 09:03:53 +01:00
;; Clipboard and primary selection.
2017-05-08 09:00:14 +02:00
; (setq select-enable-clipboard t)
( setq select-enable-primary t )
2014-03-20 09:03:53 +01:00
2014-03-31 11:44:14 +02:00
;; Bibtex
( setq bibtex-entry-format ' ( opts-or-alts required-fields numerical-fields whitespace realign last-comma delimiters braces sort-fields ) )
( setq bibtex-field-delimiters 'double-quotes )
2015-09-23 14:32:47 +02:00
( add-hook
'bibtex-mode-hook
( lambda ( )
( setq indent-tabs-mode nil ) ) )
2014-03-31 11:44:14 +02:00
2017-05-22 11:13:56 +02:00
;; Remove auto-fill in web edits because wikis and forums do not like it.
;; This works for qutebrowser, but may need changes for other browsers.
( add-hook
'find-file-hook
( lambda ( )
( when ( string-match ( concat ( getenv " BROWSER " ) " -editor-* " ) ( buffer-name ) )
( when ( require 'with-editor nil t )
;; Just like git commits.
( with-editor-mode ) )
( auto-fill-mode -1 ) ) ) )
2013-07-09 10:57:02 +02:00
;; Mutt support.
2017-05-22 11:13:56 +02:00
( add-to-list 'auto-mode-alist ' ( " /tmp/mutt-.* " . mail-mode ) )
( add-hook
'find-file-hook
( lambda ( )
( when ( and ( string-match " /tmp/mutt-.* " ( buffer-file-name ) )
( require 'with-editor nil t ) )
;; Just like git commits.
( with-editor-mode ) ) ) )
2013-07-09 10:57:02 +02:00
;; Arch Linux PKGBUILD.
( add-to-list 'auto-mode-alist ' ( " PKGBUILD " . sh-mode ) )
;; Subtitles support.
( add-to-list 'auto-mode-alist ' ( " \\ .srt \\ ' " . text-mode ) )
2014-02-12 18:49:41 +01:00
2017-05-22 11:13:56 +02:00
( add-hook
'mail-mode-hook
'mail-text )
2015-05-09 13:16:10 +02:00
;; Easy code folding toggle.
2016-10-08 05:10:11 +02:00
; (add-hook 'prog-mode-hook 'hs-minor-mode)
; (add-hook 'prog-mode-hook (lambda () (local-set-key (kbd "C-c h") 'hs-toggle-hiding)))
2015-04-17 16:16:10 +02:00
2015-05-09 13:16:10 +02:00
;; Move mouse away.
2015-05-14 16:45:04 +02:00
; (mouse-avoidance-mode 'banish)
2015-05-09 13:16:10 +02:00
2015-05-11 19:38:16 +02:00
;; Display defun in mode line.
( which-function-mode )
;; Replace maximized binding for fullscreen.
2017-05-08 09:00:14 +02:00
; (define-key mickey-minor-mode-map (kbd "M-<f10>") 'toggle-frame-fullscreen)
2015-05-11 19:38:16 +02:00
2016-06-10 18:05:05 +02:00
;; Scroll zooming.
2016-06-09 11:27:24 +02:00
( define-key mickey-minor-mode-map ( kbd " C-<wheel-down> " ) 'text-scale-decrease )
( define-key mickey-minor-mode-map ( kbd " C-<mouse-5> " ) 'text-scale-decrease )
( define-key mickey-minor-mode-map ( kbd " C-<wheel-up> " ) 'text-scale-increase )
( define-key mickey-minor-mode-map ( kbd " C-<mouse-4> " ) 'text-scale-increase )
2015-06-02 10:05:14 +02:00
( setq text-scale-mode-step 1.1 )
2015-11-02 13:34:04 +01:00
;; Sort
( setq sort-fold-case t )
2016-10-05 06:56:16 +02:00
;; Replace not-so-useful comment-dwim binding.
( define-key mickey-minor-mode-map " \M -; " 'comment-line )
2016-10-06 14:37:53 +02:00
; In case you find eldoc too distracting.
;; (global-eldoc-mode 0)
2016-09-23 15:26:24 +02:00
2016-11-06 06:48:41 +01:00
;; Replace `kill-buffer' binding by `kill-this-buffer'.
( define-key mickey-minor-mode-map ( kbd " C-x k " ) 'kill-this-buffer )
2016-12-10 17:53:59 +01:00
( setq ediff-window-setup-function 'ediff-setup-windows-plain
ediff-split-window-function 'split-window-horizontally )
2014-03-08 11:48:35 +01:00
( provide 'main )