Starter Kit Other Mode

This is part of the Emacs Starter Kit.

Starter Kit Other Mode

Eval after load

This macro is stolen from lunaryorn setup (see .emacs config) eval parameter after package or component has been loaded.

(unless (fboundp 'with-eval-after-load)
  (defmacro with-eval-after-load (file &rest body)
    "Execute BODY after FILE is loaded. Forward compatibility wrapper."
    `(eval-after-load ,file
       `(funcall (function ,(lambda () ,@body))))))

(defmacro starter-kit-after (feature &rest forms)
    "After FEATURE is loaded, evaluate FORMS. FORMS is byte compiled.
     FEATURE may be a named feature or a file name, see `eval-after-load' for details."
    (declare (indent 1) (debug t))
    ;; Byte compile the body.  If the feature is not available, ignore warnings.
    ;; Taken from
    ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2012-11/msg01262.html
    `(,(if (or (not (boundp 'byte-compile-current-file))
               (not byte-compile-current-file)
               (if (symbolp feature)
                   (require feature nil :no-error)
                 (load feature :no-message :no-error)))
           'progn
         (message "starter-kit-after: cannot find %s" feature)
         'with-no-warnings)
      (with-eval-after-load ',feature ,@forms)))

Coding Hook

(add-hook 'emacs-lisp-mode-hook 'run-starter-kit-coding-hook)
(add-hook 'sh-mode-hook         'run-starter-kit-coding-hook)
(add-hook 'latex-mode-hook      'run-starter-kit-coding-hook)
(add-hook 'python-mode-hook     'run-starter-kit-coding-hook)

Modes setting

CUA mode

(cua-mode t)

Undo tree

(starter-kit-after undo-tree (diminish 'undo-tree-mode));; "⤺"))
(global-undo-tree-mode)

recentf

(starter-kit-after recentf
                   (setq recentf-max-saved-items 100))
(recentf-mode t)

Transparently open compressed files

(auto-compression-mode t)

Highlight matching parentheses when the point is on them.

(show-paren-mode t)
(setq show-paren-delay 0
      show-paren-style 'mixed)

(require 'highlight-parentheses)
(defun turn-on-highlight-parentheses-mode ()
  (highlight-parentheses-mode t))
(define-global-minor-mode global-highlight-parentheses-mode
  highlight-parentheses-mode
  turn-on-highlight-parentheses-mode)
(setq hl-paren-colors
      '("orange1" "yellow1" "greenyellow" "green1"
        "springgreen1" "cyan1" "slateblue1" "magenta1" "purple"))
(diminish 'highlight-parentheses-mode);; "♓")
(global-highlight-parentheses-mode)

Highlight everything strange

(starter-kit-after whitespace
                   (diminish 'whitespace-mode);; "␣")
                   (setq whitespace-style '(face trailing lines-tail tabs)
                         whitespace-line-column 80))

isearch with flex support

(require 'flex-isearch)
(global-flex-isearch-mode 1)
(setq flex-isearch-auto 'on-failed)

Show a column wise indicator

(starter-kit-after fill-column-indicator
                   (setq fci-rule-width 3))
(setq-default fill-column 80)

Highlight current line   nottangle

(global-hl-line-mode t)

Auto revert buffer

(global-auto-revert-mode t)
;; revert without asking
(setq revert-without-query '(".*"))

Smartparens settings

(starter-kit-after smartparens
                   (setq sp-ignore-modes-list '(calc-mode dired-mode ibuffer-mode
                                                          minibuffer-incative-mode sr-mode))
                   (diminish 'smartparens-mode))

which-func-mode   nottangle

Set function name in the header part of emacs (from http://emacsredux.com/blog/2014/04/05/which-function-mode/).

(require 'which-func)
(add-to-list 'which-func-modes 'org-mode)
(setq-default header-line-format
              '((which-func-mode ("" which-func-format " "))))
(setq mode-line-misc-info
      ;; We remove Which Function Mode from the mode line, because it's mostly
      ;; invisible here anyway.
      (assq-delete-all 'which-func-mode mode-line-misc-info))

Winner mode

(winner-mode 1)

Idle hightlight face

Use a less intrusive color for idle-hightlight-mode

(defface idle-highlight
  '((t (:inherit match)))
  "Face used to highlight other occurrences of the word at point."
  :group 'idle-highlight)
(starter-kit-after idle-highlight
  (diminish 'idle-highlight-mode))

Drag stuff mode   nottangle

See https://github.com/rejeep/drag-stuff

(starter-kit-after drag-stuff
                   (add-to-list 'drag-stuff-except-modes 'org-mode)
                   (diminish 'drag-stuff-mode));; "⇅"))
(drag-stuff-global-mode)

Magit settings

(require 'magit)

Do not ask for confirmation

(setq magit-stage-all-confirm nil)

Do not show untracked material

(setq magit-omit-untracked-dir-contents t)

Fullscreen magit-status

From Magnars blog

(defadvice magit-status (around magit-fullscreen activate)
  (window-configuration-to-register :magit-fullscreen)
  ad-do-it
  (delete-other-windows))

(defun magit-quit-session ()
  "Restores the previous window configuration and kills the magit buffer"
  (interactive)
  (kill-buffer)
  (jump-to-register :magit-fullscreen))

(global-set-key (kbd "M-s") 'magit-status)

(define-key magit-status-mode-map (kbd "q") 'magit-quit-session)
(define-key magit-status-mode-map (kbd "p") 'magit-push)
(require 'magit-svn)
(define-key magit-svn-mode-map    (kbd "p") 'magit-svn-dcommit)

Magit commit mode

(defun magit-exit-commit-mode ()
  (interactive)
  (kill-buffer)
  (delete-window))

(eval-after-load "git-commit-mode"
  '(define-key git-commit-mode-map (kbd "C-c C-k") 'magit-exit-commit-mode))

(defun magit-commit-mode-init ()
  (when (looking-at "\n")
    (open-line 1)))

(add-hook 'git-commit-mode-hook 'magit-commit-mode-init)

(defadvice git-commit-commit (after delete-window activate)
  (delete-window))

(add-hook 'git-commit-mode-hook (lambda () (auto-complete-mode t)))

Colored diff   nottangle

(setq magit-diff-refine-hunk 'all)

Diminish magit auto revert mode

(diminish 'magit-auto-revert-mode)

Automatically enable magit-svn-mode

Stolen from http://danlamanna.com/2013/03/11/svn-externals-with-git-svn-and-magit/

(add-hook 'magit-mode-hook (lambda()
                             (require 'magit-svn)
                             (if (magit-svn-get-ref-info)
                                 (magit-svn-mode))))

Git gutter settings

(require 'git-gutter)
(setq git-gutter-disabled-modes '(asm-mode image-mode org-mode))
(diminish 'git-gutter-mode)
(global-git-gutter-mode t)
;; If you would like to use git-gutter.el and linum-mode
(git-gutter:linum-setup)
(global-set-key (kbd "C-x C-g") 'git-gutter:toggle)
;; Jump to next/previous hunk
(global-set-key (kbd "C-x p") 'git-gutter:previous-hunk)
(global-set-key (kbd "C-x n") 'git-gutter:next-hunk)

;; Stage current hunk
(global-set-key (kbd "C-x v s") 'git-gutter:stage-hunk)

;; Revert current hunk
(global-set-key (kbd "C-x v r") 'git-gutter:revert-hunk)

direx & direx-k

(require 'popwin)
(popwin-mode 1)
(require 'direx)
(push '(direx:direx-mode :position left :width 40 :dedicated t :stick t)
popwin:special-display-config)
(global-set-key (kbd "C-ù") 'direx-project:jump-to-project-root-other-window)
(setq direx:leaf-icon "  "
      direx:open-icon "▾ "
      direx:closed-icon "▸ ")
(defface direx-k-modified
  '((t (:inherit warning :weight bold)))
  "Face of added file in git repository"
  :group 'dired-k)

(defface direx-k-untracked
  '((t (:inherit error)))
  "Face of untracked file in git repository"
  :group 'dired-k)
(require 'direx-k)
(define-key direx:direx-mode-map (kbd "g") 'direx-k)

diff-hl settings

Tweak face by removing the foreground colors

(starter-kit-after diff-hl
  (set-face-foreground 'diff-hl-insert nil)
  (set-face-foreground 'diff-hl-change nil)
  (set-face-foreground 'diff-hl-delete nil)
  )
;;(global-diff-hl-mode)

latex-mode

(add-to-list 'auto-mode-alist '("\\.tikz\\'" . latex-mode))
(add-hook 'latex-mode-hook 'turn-on-orgtbl)
;;(add-hook 'latex-mode-hook 'turn-on-auto-fill)

markdown-mode

(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))

multi-web-mode

(setq mweb-default-major-mode 'html-mode)
(setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
                  (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
                  (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
(multi-web-global-mode 1)

cmake-mode

(require 'cmake-mode)
 (setq auto-mode-alist
       (append '(("CMakeLists\\.txt\\'" . cmake-mode)
                 ("\\.cmake\\'" . cmake-mode))
               auto-mode-alist))

css-mode

(defvar hexcolour-keywords
  '(("#[abcdef[:digit:]]\\{6\\}"
     (0 (put-text-property
         (match-beginning 0)
         (match-end 0)
         'face (list :background
                     (match-string-no-properties 0)))))))
(defun hexcolour-add-to-font-lock ()
  (font-lock-add-keywords nil hexcolour-keywords))

(add-hook 'css-mode-hook 'hexcolour-add-to-font-lock)

trac-wiki-mode

Define some usual trac-wiki projects.

(require 'trac-wiki)
(trac-wiki-define-project "trac-LAL"
                          "https://trac.lal.in2p3.fr/NEMO2/" t)

(trac-wiki-define-project "trac-LPC"
                          "https://nemo.lpc-caen.in2p3.fr/" t)

(autoload 'trac-wiki "trac-wiki"
  "Trac wiki editing entry-point." t)

Wrap region mode

(starter-kit-after wrap-region (diminish 'wrap-region-mode))

yasnippet mode

yasnippet is yet another snippet expansion system for Emacs. It is inspired by TextMate's templating syntax (watch the video on YouTube or see the intro and tutorial)

(require 'yasnippet)
(yas-global-mode 1)
(setq yas-snippet-dirs '(concat starter-kit-dir "/snippets"))
(starter-kit-after yasnippet (diminish 'yas-minor-mode))

auto-complete+ido-at-point mode

(require 'auto-complete-config)
;; (global-auto-complete-mode t)
(ac-config-default)
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
(define-key ac-completing-map (kbd "ESC") 'ac-stop)
(starter-kit-after auto-complete (diminish 'auto-complete-mode))

expand-region mode

(require 'expand-region)
(global-set-key (kbd "C-w") 'er/expand-region)

multiple-cursors mode

(require 'multiple-cursors)
(global-set-key (kbd "C->") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-<") 'mc/mark-next-like-this)

Browse kill-ring

(require 'browse-kill-ring)
(global-set-key "\M-y" 'browse-kill-ring)

Diminish modeline clutter

(diminish 'auto-fill-function)
(diminish 'abbrev-mode)
(diminish 'inertias-global-minor-mode)

lorem ipsum

(require 'lorem-ipsum)
File under version control - commit 135971e - 2014-11-29