Skip to content

nrichart/dot_emacs.d

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is my emacs config that is made of a melting pot of multiple sources.

Configurations

Meta

All changes to the configuration should be done in init.org, not in init.el. Any changes in the init.el will be overwritten by saving init.org. The init.el in this repo should not be tracked by git, and is replaced the first time Emacs is started (assuming it has been renamed to ~/.emacs.d).

Emacs can’t load .org-files directly, but org-mode provides functions to extract the code blocks and write them to a file. There are multiple ways of handling this; like suggested by this StackOverflow post, one could just use org-babel-load-file, but I had problems with byte-compilation. Previously I tracked both the org.- and el.-files, but the git commits got a little messy. So here is a new approach.

When this configuration is loaded for the first time, the init.el is the file that is loaded. It looks like this:

;;; init.el --- Starting point for Nicolas Richart's Emacs Configuration

;;; Commentary:

;;; Code:

;; This file replaces itself with the actual configuration at first run.

;; We can't tangle without org!
(require 'org)
;; Open the configuration
(find-file (concat user-emacs-directory "init.org"))
;; tangle it
(org-babel-tangle)
;; load it
(load-file (concat user-emacs-directory "init.el"))
;; finally byte-compile it
;(byte-compile-file (concat user-emacs-directory "init.el"))

(provide 'init)

;;; init.el ends here

It tangles the org-file, so that this file is overwritten with the actual configuration.

There is no reason to track the init.el that is generated; by running the following command git will not bother tracking it:

git update-index --assume-unchanged init.el

If one wishes to make changes to the repo-version of init.el start tracking again with:

git update-index --no-assume-unchanged init.el

The init.el should (after the first run) mirror the source blocks in the init.org. We can use C-c C-v t to run org-babel-tangle, which extracts the code blocks from the current file into a source-specific file (in this case a .el-file).

To avoid doing this each time a change is made we can add a function to the after-save-hook ensuring to always tangle and byte-compile the org-document after changes.

(defun tangle-init ()
  "If the current buffer is 'init.org' the code-blocks are
tangled, and the tangled file is compiled."
  (when (equal (buffer-file-name)
               (expand-file-name (concat user-emacs-directory "init.org")))
    ;; Avoid running hooks when tangling.
    (let ((prog-mode-hook nil))
      (org-babel-tangle)
      ;;(byte-compile-file (concat user-emacs-directory "init.el"))
      )))

(add-hook 'after-save-hook 'tangle-init)
;; prefer newer non-byte compiled sources to older byte compiled ones
(setq load-prefer-newer t)

;; customisations
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;; load custom but ignore error if doesn't exist
(load custom-file t)

Configuring the package system and bootstrapping use-package

This configures the package system built-in Emacs. We need use-package for all the remaining configuration file so it has to be installed first

;;; Package management
(require 'package)
;; we use use-package to do this for us
(setq package-enable-at-startup nil)
;; use https for both melpa and gelpa if available
(if (gnutls-available-p)
    (setq package-archives '(("melpa" . "https://melpa.org/packages/")
	                          ("gnu" . "https://elpa.gnu.org/packages/")))
  (setq package-archives '(("melpa" . "http://melpa.org/packages/")
                           ("gnu" . "http://elpa.gnu.org/packages/"))))

(package-initialize)

;; uncomment to debug package loading times
;; (setq use-package-verbose t)

;; Bootstrap `use-package' from melpa
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

We install the alert package for some nice notification of something goes wrong or is not installed properly

(use-package alert
  :ensure t
  :init (when (eq system-type 'gnu/linux)
          (setq alert-default-style 'notifications)))

(when (version< emacs-version "24.4")
  (alert "Emacs version too old - please run 24 or newer"
         :severity 'high))

General configuration

This part contain the general configuration of the built-in parts of Emacs

   ;; For css-mode, temporarily.
   (defalias 'apropos-macrop 'macrop)

   ;; To be able to load the .dir-locals.el files
   (setq enable-local-variables :safe)

   ;; gpg preferences
   (setq epa-armor t)
   (setq epg-gpg-program "gpg2")

   ;; automatically garbage collect when switch away from emacs
   (add-hook 'focus-out-hook 'garbage-collect)

   ;; enable narrow-to-region
   (put 'narrow-to-region 'disabled nil)

   ;; set a reasonable fill and comment column
   (setq-default fill-column 79)
   (setq-default comment-column 78)

   ;; just use y or n not yes or no
   (defalias 'yes-or-no-p 'y-or-n-p)

   ;; inhibit startup message and splash screen
   (setq inhibit-startup-message t)
   ;; remove message from initial scratch buffer
   (setq initial-scratch-message nil)

   ;; Make Tab complete if the line is indented
   (setq tab-always-indent 'complete)

   ;; disable menu, tool and scroll-bars, show time
   (menu-bar-mode 0)
   (tool-bar-mode 0)
   (scroll-bar-mode 0)
   (when (fboundp 'horizontal-scroll-bar-mode)
     (horizontal-scroll-bar-mode 0))
   (display-time-mode 1)
   ;; Show line column numbers in mode line
   (line-number-mode 1)
   (column-number-mode 1)
   ;; Parent highlight
   (show-paren-mode 1)

   ;; Prefer space over tab
   (setq indent-tabs-mode nil)

   ;; Moves backup files in a different folder
   (defvar emacs-backup-directory
     (concat user-emacs-directory "backups/")
     "This variable dictates where to put backups.")

   (setq backup-directory-alist
	   `((".*" . ,emacs-backup-directory)))

   ;; prompt when trying to switch out of a dedicated window
   (setq switch-to-buffer-in-dedicated-window 'prompt)

   ;; ensure scrolling forwards / backwards preserves original location such that
   ;; they undo each other
   (setq scroll-preserve-screen-position 'always)

   (defun apm-emoji-fontset-init ()
     "Set fontset to display emoji correctly."
     (if (eq system-type 'darwin)
	   ;; For NS/Cocoa
	   (set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") nil 'prepend)
	 ;; For Linux
	 (if (font-info "Symbola")
	     (set-fontset-font t 'symbol (font-spec :family "Symbola") nil 'prepend)
	   (alert "Symbola is not installed (ttf-ancient-fonts)"))))

   (defvar apm-preferred-font-family "Inconsolata"
     "Preferred font family to use.")

   (defvar apm-preferred-font-family-package "fonts-inconsolata"
     "Package to install to get `apm-preferred-font-family'.")

   (defvar apm-preferred-font-height 120
     "Preferred font height to use.")

   (defun apm-graphic-frame-init ()
     "Initialise properties specific to graphical display."
     (interactive)
     (when (display-graphic-p)
	 (apm-emoji-fontset-init)
	 (setq frame-title-format '(buffer-file-name "%f" ("%b")))
	 ;; don't use gtk style tooltips so instead can use pos-tip etc
	 (custom-set-variables
	  '(x-gtk-use-system-tooltips nil))
	 (tooltip-mode -1)
	 (blink-cursor-mode -1)
	 (if (font-info apm-preferred-font-family)
	     (set-face-attribute 'default nil
				 :family apm-preferred-font-family
				 :height apm-preferred-font-height)
	   (alert (format "%s font not installed (%s)"
			  apm-preferred-font-family
			  apm-preferred-font-family-package)))
	 (if (font-info "FontAwesome")
	     ;; make sure to use FontAwesome for it's range in the unicode
	     ;; private use area since on Windows this doesn't happen
	     ;; automagically
	     (set-fontset-font "fontset-default" '(#xf000 . #xf8ff) "FontAwesome")
	   (alert "FontAwesome is not installed (fonts-font-awesome)."))))

   ;; make sure graphical properties get set on client frames
   (add-hook 'server-visit-hook #'apm-graphic-frame-init)
   (apm-graphic-frame-init)

   (define-key key-translation-map [?\C-h] [?\C-?])

   ;; Use regex searches and replace by default.
   (global-set-key (kbd "C-s") 'isearch-forward-regexp)
   (global-set-key (kbd "C-r") 'isearch-backward-regexp)
   (global-set-key (kbd "M-%") 'query-replace-regexp)
   (global-set-key (kbd "C-M-s") 'isearch-forward)
   (global-set-key (kbd "C-M-r") 'isearch-backward)
   (global-set-key (kbd "C-M-%") 'query-replace)

   ;; Some global key binding
   (global-set-key (kbd "C-c ;") 'comment-region)
   (global-set-key (kbd "M-g") 'goto-line)
   (global-set-key [f8] 'grep-find)

   ;; from http://endlessparentheses.com/fill-and-unfill-paragraphs-with-a-single-key.html
   (defun endless/fill-or-unfill ()
     "Like `fill-paragraph', but unfill if used twice."
     (interactive)
     (let ((fill-column
	      (if (eq last-command 'endless/fill-or-unfill)
		  (progn (setq this-command nil)
			 (point-max))
		fill-column)))
	 (call-interactively #'fill-paragraph)))

   (global-set-key [remap fill-paragraph] #'endless/fill-or-unfill)

   ;; general modes in text-mode or derived from
   (defun apm-text-mode-setup ()
     "Setup `text-mode' buffers."
     ;; use visual line mode to do soft word wrapping
     (visual-line-mode 1)

     (setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))

     (visual-fill-column-mode 1)
     ;; and use adaptive-wrap to 'indent' paragraphs appropriately with visual-line-mode
     (adaptive-wrap-prefix-mode 1) 
     ;; Enable flyspell
     (flyspell-mode 1)
     ;; give warning if words misspelled when typing
     (ispell-minor-mode 1))

   (add-hook 'text-mode-hook #'apm-text-mode-setup)

License

The code I used for this configuration are under “Public License” or “GPLv3”. This file is under “GPLv3” to be compatible with the strictest.

List of packages to install and use

Interface Enhancement

  • Ivy - flexible, simple tools for minibuffer completion in Emacs.
    • Ivy, a generic completion mechanism for Emacs.
    • Counsel, a collection of Ivy-enhanced versions of common Emacs commands.
    • Swiper, an Ivy-enhanced alternative to isearch.
  • crux - A Collection of Ridiculously Useful eXtensions for Emacs
  • smex - A smart M-x enhancement for Emacs.
(use-package ivy
  :ensure t
  :diminish ivy-mode
  :commands (ivy-mode)
  :bind (("C-c C-r" . ivy-resume)
         ([remap switch-to-buffer] . ivy-switch-buffer))
  :init (progn
          (setq ivy-count-format ""
                ivy-display-style 'fancy)
          (ivy-mode 1)))

(use-package counsel
  :ensure t
  :bind (("M-y" . counsel-yank-pop)
         ("M-x" . counsel-M-x)
         ("C-x C-i" . counsel-imenu)
         ("C-x C-f" . counsel-find-file)
         ("C-h f" . counsel-describe-function)
         ("C-h v" . counsel-describe-variable))
  :init (progn
          (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
          (setq counsel-find-file-at-point t))
  )

(use-package crux
  :ensure t
  :bind (([remap move-beginning-of-line] . crux-move-beginning-of-line)
         ("C-c o" . crux-open-with)))

(use-package smex
  :ensure t
  :config (smex-initialize))

File Manager

  • Dired - [built-in] Dir ectory Ed itor. A customizable great file manager.

Navigation

  • anzu - displays current match and total matches.
  • imenu - [built-in] Menus for accessing locations in documents.
(use-package anzu
  :ensure t
  :diminish anzu-mode
  :init (global-anzu-mode)
  :bind (("M-%" . anzu-query-replace-regexp)
         ("C-M-%" . anzu-query-replace)))

Visual

  • rainbow-mode - Display color on color-code string (hex/rgb) directly.
  • whitespace - [built-in] Visualize blanks (tab/space/newline).
  • prettify-symbol-mode - [built-in] displaying characters as fancy symbols (e.g. lambda -> λ)
  • emojify - Display emojis in Emacs.
(use-package rainbow-mode
  :ensure t
  :diminish rainbow-mode
  :commands (rainbow-mode)
  :init (dolist (hook '(css-mode-hook html-mode-hook))
          (add-hook hook #'rainbow-mode)))

(use-package whitespace
  :diminish whitespace-mode
  :bind ([f3] . whitespace-cleanup)
  :config
  (defun show-whitespace ()
    "Show tabs and trailing white space."
    (if (not (eq major-mode 'Buffer-menu-mode))
        (setq font-lock-keywords
              (append font-lock-keywords
                      '(("^[\t]+"  (0 'tab-face t))
                        ("[ \t]+$" (0 'trailing-space-face t))
                        ("XXX" (0 'todo-face t))
                        ("TODO" (0 'todo-face t))
                        ("FIXME" (0 'todo-face t))
                        ("\\todo" (0 'todo-face t))
                        )))))
  (make-face 'tab-face)
  (make-face 'trailing-space-face)
  (make-face 'todo-face)
  (set-face-background 'tab-face "blue")
  (set-face-background 'trailing-space-face "blue")
  (set-face-foreground 'todo-face "green")
  (add-hook 'font-lock-mode-hook 'show-whitespace)
  (add-hook 'text-mode-hook 'font-lock-mode)
  )

Project management

(use-package counsel-projectile
  :ensure t
  :init (counsel-projectile-mode))

(use-package projectile
  :ensure t
  :defer t
  :diminish projectile-mode
  :bind (([f9] . projectile-compile-project)
         ("C-x C-g" . projectile-find-file))
  :bind-keymap
        ("C-c p" . projectile-command-map)
  :init (progn
          (setq projectile-enable-caching t)
          (projectile-mode))
  :config (progn
            (add-to-list 'projectile-project-root-files "configure.ac")
            (add-to-list 'projectile-project-root-files ".clang_complete")
            (add-to-list 'projectile-project-root-files ".clang_complete.in")
            (add-to-list 'projectile-project-root-files "AndroidManifest.xml")
            (with-eval-after-load 'ivy
              (setq projectile-completion-system 'ivy))))

(use-package projectile-ripgrep
  :ensure t
  :commands projectile-ripgrep)

Programming

  • Aggressive-indent - Keeps your code always indented automatically.
  • compile - [built-in] Compile command default for M-x compile
  • Doxymacs - Doxymacs is Doxygen + {X}Emacs.
  • prog-mode - [built-in] common to all programming modes
  • realgud - front-end to external debuggers
;  (use-package aggressive-indent
;    :ensure t
;    :defer t
;    :diminish aggressive-indent-mode
;    :config (aggressive-indent-global-mode t))

  (use-package compile
    ;; :bind ([f9] . compile)
    ;; automatically scroll to first error on output
    :config (setq compilation-scroll-output 'first-error))

  (defun apm-doxymacs-setup()
    (doxymacs-mode)
    (doxymacs-font-lock)
    (setq doxymacs-doxygen-style "JavaDoc"))

  (use-package doxymacs
    :defer t
    :load-path "vendor/doxymacs"
    :commands (doxymacs-mode doxymacs-font-lock)
    :diminish doxymacs-mode
    :config (add-hook 'cc-mode-common-hook #'apm-doxymacs-setup)
    )

  (defun apm-prog-mode-setup ()
    "Tweaks and customisations for all programming modes."
    ;; turn on spell checking for strings and comments
    (flyspell-prog-mode)
    ;; highlight TODO etc in comments only
    ;; (fic-mode 1)
    )

  (use-package prog-mode
    :config (progn
              (when (boundp 'prettify-symbols-unprettify-at-point)
                ;; show original text when point is over a prettified symbol
                (setq prettify-symbols-unprettify-at-point 'right-edge))
              ;; prettify symbols (turn lambda -> λ)
              (global-prettify-symbols-mode 1)
              (add-hook 'prog-mode-hook #'apm-prog-mode-setup)))

  (use-package realgud
    :ensure t)

  (use-package yasnippet
    :ensure t
    :diminish yas-minor-mode
    :config (yas-global-mode 1))

Completion

(use-package abbrev
  :diminish abbrev-mode
  :config (progn
            (setq save-abbrevs t)
            (setq-default abbrev-mode t)))

(use-package company
  :ensure t
  :commands global-company-mode
  ;; Use Company for completion
  :bind (:map company-mode-map ([remap completion-at-point] . company-complete))
  :init (progn
          ;; set default lighter as nothing so in general it is not displayed
          ;; but will still be shown when completion popup is active to show the
          ;; backend which is in use
          (setq company-lighter-base "")
          (global-company-mode 1))
  :config (progn
            ;; some better default values
            (setq company-idle-delay 0.5)
            (setq company-tooltip-limit 10)
            (setq company-minimum-prefix-length 2)

            ;; align annotations in tooltip
            (setq company-tooltip-align-annotations t)

            ;; nicer keybindings
            (define-key company-active-map (kbd "C-n") 'company-select-next)
            (define-key company-active-map (kbd "C-p") 'company-select-previous)
            (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)

            (define-key company-active-map [tab] 'company-complete-common-or-cycle)
            (define-key company-active-map (kbd "TAB") 'company-complete-common-or-cycle)

            ;; put most often used completions at stop of list
            (setq company-transformers '(company-sort-by-occurrence))))

(use-package company-anaconda
  :ensure t
  :commands (company-anaconda)
  :after company
  :init (add-to-list 'company-backends #'company-anaconda))

(use-package company-auctex
  :ensure t
  ;; loaded in apm-latex-mode-setup
  :defer t)

(use-package company-dabbrev
  :after company
  ;; keep original case
  :config (setq company-dabbrev-downcase nil))

(use-package company-flx
  :ensure t
  :after company
  :init (company-flx-mode 1))

(use-package company-irony
  :ensure t
  :after company
  :init (add-to-list 'company-backends 'company-irony))

(use-package company-irony-c-headers
  :ensure t
  :after company
  :init (progn
          (setq company-irony-c-headers--compiler-executable
                (or (executable-find "clang++-5.0")
                    (executable-find "clang++")))
          ;; group with company-irony but beforehand so we get first pick
          (add-to-list 'company-backends '(company-irony-c-headers company-irony))))

(use-package company-jedi
  :ensure t
  :after company)

(use-package company-emoji
  :ensure t
  :after company
  :init (add-to-list 'company-backends 'company-emoji))

(use-package company-math
  :ensure t
  :defer t
  :after company
  ;; Add backend for math characters
  :init (progn
          (add-to-list 'company-backends 'company-math-symbols-unicode)
          (add-to-list 'company-backends 'company-math-symbols-latex)))

(use-package company-quickhelp
  :ensure t
  :defer t
  :init (add-hook 'company-mode-hook #'company-quickhelp-mode)
  :config (setq company-quickhelp-delay 0.1))

(use-package company-shell
  :ensure t
  :defer t
  :after company
  :init (add-to-list 'company-backends 'company-shell))

(use-package company-statistics
  :ensure t
  :after company
  :config (company-statistics-mode 1))

(use-package company-tern
  :ensure t
  :after company)

(use-package company-try-hard
  :ensure t
  :after company
  :config (progn
            (global-set-key (kbd "C-<tab>") #'company-try-hard)
            (define-key company-active-map (kbd "C-<tab>") #'company-try-hard)))

(use-package company-web
  :ensure t
  :defer t
  :after company
  :init (add-to-list 'company-backends 'company-web-html))

(use-package flx
  :ensure t)

Document

  • eldoc - [built-in] shows function arguments / variable doc in minibuffer when coding.
  • devhelp - Searches in devhelp for documentation
(use-package eldoc
  :diminish eldoc-mode
  :config (global-eldoc-mode 1))

(defun apm-devhelp-setup ()
  "Setup devhelp integration."
  (require 'devhelp)
  (local-set-key (kbd "<f2>") #'devhelp-toggle-automatic-assistant)
  (local-set-key (kbd  "<f1>") #'devhelp-assistant-word-at-point))

(use-package devhelp
  :load-path "vendor/"
  :defer t
  :init (add-hook 'c++-mode-hook #'apm-devhelp-setup))

Error Checking

(use-package flycheck
  :ensure t
  :diminish flycheck-mode
  :config (progn
            (global-flycheck-mode 1)
            (setq flycheck-check-syntax-automatically '(save new-line)
                  flycheck-idle-change-delay 5.0
                  flycheck-display-errors-delay 0.9
                  flycheck-highlighting-mode 'symbols
                  flycheck-indication-mode 'left-fringe
                  ;; 'flycheck-fringe-bitmap-double-arrow
                  flycheck-standard-error-navigation t ; [M-g n/p]
                  flycheck-deferred-syntax-check nil
                  )))

(use-package flycheck-clangcheck
  :ensure t
  :after flycheck
  )

(use-package flycheck-irony
  :ensure t
  :after flycheck
  :config (progn
            (add-hook 'flycheck-mode-hook #'flycheck-irony-setup)
            (flycheck-add-next-checker 'irony '(warning . c/c++-cppcheck))))

(use-package flycheck-clang-tidy
  :ensure t
  :after flycheck
  :config (progn
            (add-hook 'flycheck-mode-hook #'flycheck-clang-tidy-setup)
            (flycheck-add-next-checker 'c/c++-clang-tidy '(warning . irony))
            (setq flycheck-c/c++-clang-tidy-executable
                  (or (executable-find "clang-tidy-5.0")
                      (executable-find "clang-tidy")))))

(use-package flycheck-package
  :ensure t
  :defer t
  :after flycheck
  :init (flycheck-package-setup))

(use-package flycheck-pos-tip
  :ensure t
  :config (flycheck-pos-tip-mode 1))

Programming Language

C/C++

  • CC Mode - [built-in] An Emacs and XEmacs mode for editing C and other languages with similar syntax.
  • cmake-mode - [included in cmake] major-mode for editing CMake sources
  • cmake-font-lock - Enhanced font-lock rules for CMake.
  • cwarn - [built-in] highlight suspicious C and C++ constructions
  • irony-mode - A C/C++ minor mode for Emacs powered by libclang.
  • irony-eldoc - irony-mode support for eldoc-mode
  • modern-cpp-font-lock - Font-locking for “Modern C++”
;; show #if 0 / #endif etc regions in comment face - taken from
;; http://stackoverflow.com/questions/4549015/in-c-c-mode-in-emacs-change-face-of-code-in-if-0-endif-block-to-comment-fa
(defun c-mode-font-lock-if0 (limit)
  "Fontify #if 0 / #endif as comments for c modes etc.
Bound search to LIMIT as a buffer position to find appropriate
code sections."
  (save-restriction
    (widen)
    (save-excursion
      (goto-char (point-min))
      (let ((depth 0) str start start-depth)
        (while (re-search-forward "^\\s-*#\\s-*\\(if\\|else\\|endif\\)" limit 'move)
          (setq str (match-string 1))
          (if (string= str "if")
              (progn
                (setq depth (1+ depth))
                (when (and (null start) (looking-at "\\s-+0"))
                  (setq start (match-end 0)
                        start-depth depth)))
            (when (and start (= depth start-depth))
              (c-put-font-lock-face start (match-beginning 0) 'font-lock-comment-face)
              (setq start nil))
            (when (string= str "endif")
              (setq depth (1- depth)))))
        (when (and start (> depth 0))
          (c-put-font-lock-face start (point) 'font-lock-comment-face)))))
  nil)

(use-package apm-c
  :load-path "lisp/"
  :commands (apm-c-mode-setup)
  :init (dolist (hook '(c-mode-hook c++-mode-hook))
          (add-hook hook 'apm-c-mode-setup)))

;; c-mode and other derived modes (c++, java etc) etc
(defun apm-c-mode-common-setup ()
  "Tweaks and customisations for all modes derived from c-common-mode."
  (auto-fill-mode 1)
  ;; diminish auto-fill in the modeline
  (with-eval-after-load 'diminish
    (diminish 'auto-fill-function))
  ;; turn on auto-newline and hungry-delete
  ;; (c-toggle-auto-hungry-state t)
  ;; ensure fill-paragraph takes doxygen @ markers as start of new
  ;; paragraphs properly
  (setq paragraph-start "^[ ]*\\(//+\\|\\**\\)[ ]*\\([ ]*$\\|@param\\)\\|^\f")

  ;; show #if 0 / #endif etc regions in comment face
  (font-lock-add-keywords
   nil
   '((c-mode-font-lock-if0 (0 font-lock-comment-face prepend))) 'add-to-end))

(use-package cc-mode
  :defer t
  :init (add-hook 'c-mode-common-hook #'apm-c-mode-common-setup))

(use-package clang-format
  :ensure t
  :bind (:map c++-mode-map
         ([f5] . clang-format-buffer)
         ([S-tab] . clang-format-region))
  :config
  (setq clang-format-executable
        (or (executable-find "clang-format-7")
            (executable-find "clang-format")))
  )

(use-package cmake-mode
  :ensure t)

(use-package cmake-font-lock
  :ensure t)

(defun apm-irony-mode-setup ()
  "Setup irony-mode."
  (irony-cdb-autosetup-compile-options)
  (with-eval-after-load 'company-irony
    (company-irony-setup-begin-commands))
  (with-eval-after-load 'irony-eldoc
    (irony-eldoc)))

;; autogenerate a .clang_complete if there is an associated .clang_complete.in
(defun apm-autogenerate-clang-complete ()
  "Autogenerate a .clang_complete if needed when opening a project."
  (when (and (fboundp 'projectile-project-root)
             ;; handle if not in project by returning nil
             (not (null (condition-case nil
                            (projectile-project-root)
                          (error nil))))
             (file-exists-p (concat (file-name-as-directory
                                     (projectile-project-root))
                                    ".clang_complete.in")))
    (projectile-with-default-dir (projectile-project-root)
      (shell-command "make .clang_complete"))))

(defun apm-irony-cdb-clang-complete--auto-generate-clang-complete (command &rest args)
  "Try and autogenerate a .clang_complete (COMMAND ARGS are ignored)."
  (apm-autogenerate-clang-complete))

;; show suspicious c constructs automatically
(use-package cwarn
  :diminish cwarn-mode
  :init (global-cwarn-mode 1))

(use-package irony
  :ensure t
  :diminish irony-mode
  :commands (irony-mode)
  :bind (:map irony-mode-map ([remap completion-at-point] . irony-completion-at-point-async)
              ([remap complete-symbol] . irony-completion-at-point-async))
  :init (progn
          (advice-add 'irony-cdb-clang-complete :before 'apm-irony-cdb-clang-complete--auto-generate-clang-complete)
          (add-hook 'c-mode-hook 'irony-mode)
          (add-hook 'c++-mode-hook 'irony-mode)
          (add-hook 'irony-mode-hook 'apm-irony-mode-setup)))

(use-package irony-eldoc
  :ensure t
  :defer t)

(use-package modern-cpp-font-lock
  :ensure t
  :defer t
  :diminish modern-c++-font-lock-mode
  :init (add-hook 'c++-mode-hook #'modern-c++-font-lock-mode))

Python

  • anaconda-mode - Code navigation, documentation lookup and completion for Python.
  • ein - IPython notebook client for Emacs
  • Elpy - An Emacs Python development environment.
  • Jedi - A Python auto-completion package.
  • swig - Major mode for swig files
  • yaml - Major mode for editing YAML files
(use-package anaconda-mode
  :ensure t
  :diminish (anaconda-mode . " 🐍 ")
  ;; enable with apm-python-mode-setup below
  :defer t)

(use-package ein
  :ensure t
  :config (add-hook 'ein:connect-mode-hook 'ein:jedi-setup))

                                        ;  (use-package elpy
                                        ;    :ensure t
                                        ;    :config (elpy-enable))

(use-package jedi
  :ensure t)

(defun apm-python-mode-setup ()
  "Tweaks and customisations for `python-mode'."
  (setq python-shell-interpreter "ipython3"
        python-shell-interpreter-args "--simple-prompt")
  (setq python-indent-offset 4)
  (add-to-list 'company-backends 'company-jedi)
  (anaconda-mode 1)
  (anaconda-eldoc-mode 1))

(use-package python
  :defer t
  :init (add-hook 'python-mode-hook #'apm-python-mode-setup))

(use-package swig-mode
  :load-path "vendor/"
  :mode "\\.i\\'"
  )

(use-package yaml-mode
  :ensure t
  )

Emacs Lisp

  • lisp-mode - [built-in] A simple Emacs Lisp REPL.
(defun apm-emacs-lisp-mode-setup ()
  "Setup Emacs Lisp mode."
  (setq mode-name "🐮")
  ;; use aggressive indent
  ;; (aggressive-indent-mode 1)
  ;; (fic-mode 1)
  ;; make imenu list each package for easy navigation - from
  ;; https://github.com/jwiegley/use-package/issues/80#issuecomment-46687774
  (when (string= buffer-file-name (expand-file-name "init.el" "~/dot_emacs.d"))
    (add-to-list
     'imenu-generic-expression
     '("Packages" "^\\s-*(\\(use-package\\)\\s-+\\(\\(\\sw\\|\\s_\\)+\\)" 2))))

(use-package lisp-mode
  :config (add-hook 'emacs-lisp-mode-hook #'apm-emacs-lisp-mode-setup))

Web development

  • web-mode - major mode for editing various html templates (PHP, JSP, ASP, ERB…etc).
(defun apm-web-mode-setup ()
  "Setup web mode."
  (setq mode-name ""))

(use-package web-mode
  :ensure t
  :commands web-mode
  :config (progn
            ;; use smartparens instead
            (setq web-mode-enable-auto-pairing nil)
            (add-hook 'web-mode-hook #'apm-web-mode-setup))
  :mode ("\\.php\\'" . web-mode))

Javascript

  • js3-mode - Improved JavaScript editing mode.
  • tern - Emacs flavor of the popular JavaScript analysis engine
  • json-mode - Major mode for editing JSON files.
(use-package js3-mode
  :ensure t
  :defer t
  :mode ("\\.js\\'" . js3-mode)
  :init (progn
          (add-to-list 'company-backends 'company-tern)
          (add-hook 'js3-mode-hook
                    (lambda () (setq mode-name "js3"))))
  :config
  (setq js3-consistent-level-indent-inner-bracket t))

(use-package tern
  :ensure t
  :config (add-hook 'js3-mode-hook (lambda () (tern-mode t))))

(use-package json-mode
  :ensure t)

Shell Scripts

  • sh-script - [built-in] Major mode for editing Unix and GNU/Linux shell script code.
(use-package sh-script
  :init (setq-default sh-basic-offset 2
                      sh-indentation 2))

Version control

(use-package magit
  :ensure t
  :defer t
  :bind ("C-x g" . magit-status))

(use-package gitconfig-mode
  :ensure t
  :defer t)

(use-package gitignore-mode
  :ensure t
  :defer t)

(use-package gl-conf-mode
  :load-path "vendor/gitolite-emacs"
  :mode  "gitolite\\.conf\\'"
  )

Integration

Console

  • ansi-color - [built-in] Translate ANSI escape sequences into faces
  • EShell - [built-in] A shell-like command interpreter implemented in Emacs Lisp.
  • Term - [built-in] A terminal emulator in Emacs.
  • multi-term - Managing multiple terminal buffers in Emacs.
(use-package ansi-color
  ;; show colours correctly in shell
  :config (ansi-color-for-comint-mode-on))

(defun apm-eshell-mode-setup ()
  "Initialise 'eshell-mode'."
  (setq mode-name ""))

(use-package eshell
  :commands eshell
  :config (add-hook 'eshell-mode-hook #'apm-eshell-mode-setup))

(defun netw-multiterm-mode-setup ()
  "Initialize 'multiterm-mode"
  (yas-minor-mode -1)
  (setq mode-name "")
  (setq show-trailing-whitespace nil))

(use-package multi-term
  :ensure t
  :bind ("C-x m" . multi-term)
  :config
  (add-hook 'term-mode-hook #'netw-multiterm-mode-setup))

Continuous Integration

  • jenkins - Minimalistic Jenkins client for Emacs
  • tracwiki-mode - Emacs Major mode for working with Trac
(use-package jenkins
  :ensure t
  :commands (jenkins)
  ;; don't set jenkins-api-token here - do it in custom.el so it is not checked
  ;; into git
  :config (setq jenkins-hostname "http://scitasadm.epfl.ch/jenkins/"
                jenkins-username 'user-login-name))

(use-package tracwiki-mode
  :ensure t
  :defer t
  :commands tracwiki
  :config (tracwiki-define-project
           "akantu"
           "https://lsmssrv1.epfl.ch/akantu-trac"))

Text edition

Markdown

  • Markdown-mode - markdown-mode is a major mode for editing Markdown-formatted text files in GNU Emacs.
(use-package markdown-mode
  :ensure t
  :defer t
  :mode
  (("\\.md\\'" . markdown-mode)
   ("\\.markdown\\'" . markdown-mode))
  :config (progn
            (unless (executable-find markdown-command)
              (alert "markdown not found - is it installed?"))))

LaTeX

  • AUCTeX - an extensible package for writing and formatting TeX files.
  • RefTeX - [built-in] Adds support for labels, references, citations, and index entries.
(defun apm-latex-mode-setup ()
  "Tweaks and customisations for LaTeX mode."
  ;; smartparens latex support
  (use-package smartparens-latex
     :ensure smartparens)
  ;; Enable source-correlate for Control-click forward/reverse search.
  (TeX-source-correlate-mode 1)
  ;; enable math mode in latex
  (LaTeX-math-mode 1)
  ;; Enable reftex
  (turn-on-reftex)
  ;; integrate with company
  (company-auctex-init))

(use-package auctex
  :ensure t
  :defer t
  :mode ("\\.tex\\'" . LaTeX-mode)
  :init (progn
          (setq-default TeX-auto-save t)
          (setq-default TeX-parse-self t)
          (setq-default TeX-PDF-mode t)
          (setq-default TeX-master nil)
          (setq-default reftex-plug-into-AUCTeX t)
          (setq-default TeX-source-correlate-start-server t)

          (add-hook 'LaTeX-mode-hook #'apm-latex-mode-setup)))

PDF

  • PDF Tools - major mode for rendering PDF files, much better than DocView, and has much richer set of features
(use-package pdf-tools
  :ensure t
  ;; only try and install when needed
  :mode ("\\.pdf\\'" . pdf-tools-install))

Note

Org-mode

  • Org - [built-in] Write notes, GTD, authoring, publish and wash dishes.
(use-package org
  :config
  (progn
    (setq org-src-fontify-natively t)
    ;(set-face-attribute 'org-block-background nil :background "#373844")
    ))

Internet

IRC

  • ERC - [built-in] A powerful, modular, and extensible IRC client.
(defun apm-erc-alert (&optional match-type nick message)
  "Show an alert when nick mentioned with MATCH-TYPE NICK and MESSAGE."
  (if (or (null match-type) (not (eq match-type 'fool)))
      (let (alert-log-messages)
        (alert (or message (buffer-string)) :severity 'high
               :title (concat "ERC: " (or nick (buffer-name)))
               :data message))))

(use-package erc
  :defer t
  :config (progn
            (setq erc-nick "networms")
            ;; notify via alert when mentioned
            (add-hook 'erc-text-matched-hook 'apm-erc-alert)))

Package Management

  • package.el - [built-in] Install and manage Emacs packages easily.
    • paradox - Modernizing Emacs’ Package Menu with package ratings, usage statistics, customizability & more.
  • use-package - A declaration macro to isolate package configuration in a way that is performance-oriented and tidy.
(use-package paradox
  :ensure t
  :commands (paradox-list-packages)
  ;; don't bother trying to integrate with github
  :init (setq paradox-github-token nil))

Appearance

Theme

  ;; (use-package fancy-battery
  ;;   :ensure t
  ;;   :config (fancy-battery-mode 1))

  ;; (use-package spaceline-config           ; A beautiful mode line
  ;;   :ensure spaceline
  ;;   :init (setq spaceline-workspace-numbers-unicode t
  ;;               spaceline-window-numbers-unicode t)
  ;;   :config
  ;;   (spaceline-compile
  ;;    'lunaryorn
  ;;    ;; Left side of the mode line (all the important stuff)
  ;;    '(((buffer-modified buffer-size input-method) :face highlight-face)
  ;;      anzu
  ;;      '(buffer-id remote-host buffer-encoding-abbrev)
  ;;      ((point-position line-column buffer-position hud) :separator " | ")
  ;;      major-mode
  ;;      process
  ;;      (flycheck-error flycheck-warning flycheck-info)
  ;;      (python-pyvenv :fallback python-pyenv)
  ;;      ((which-function projectile-root) :separator " @ ")
  ;;      ((minor-modes :separator spaceline-minor-modes-separator) :when active))
  ;;    ;; Right segment (the unimportant stuff)
  ;;    '((workspace-number window-number)
  ;;      (battery :when active)
  ;;      (version-control :when active)))

  ;;   (setq-default mode-line-format '("%e" (:eval (spaceline-ml-lunaryorn)))))

  ;; (use-package powerline                  ; The work-horse of Spaceline
  ;;   :ensure t
  ;;   :after spaceline-config
  ;;   :config (progn
  ;;             (setq powerline-height (truncate (* 1.0 (frame-char-height))))
  ;;             (setq powerline-default-separator 'utf-8)))

  (use-package minions
    :ensure t
    )

  (use-package doom-modeline
    :ensure t
    :after (minions)
    :config (progn
		 (minions-mode 1)
		 (doom-modeline-mode 1)

		 ;; How tall the mode-line should be. It's only respected in GUI.
		 (setq doom-modeline-height 1)
		 (set-face-attribute 'mode-line nil :height apm-preferred-font-height)
		 (set-face-attribute 'mode-line-inactive nil :height apm-preferred-font-height)

		 ;; How wide the mode-line bar should be. It's only respected in GUI.
		 (setq doom-modeline-bar-width 1)

		 ;; 
		 (setq doom-modeline-buffer-file-name-style 'relative-from-project )
         
		 ;; Whether display mu4e notifications. It requires `mu4e-alert' package.
		 (setq doom-modeline-mu4e nil)
         
		 ;; built-in `project' on 26+
		 (setq doom-modeline-project-detection 'project)
		 ;; or `find-in-porject' if it's installed
		 ;; (setq doom-modeline-project-detection 'projectile)

		 (setq auto-revert-check-vc-info t)
		 )
    )

  ;; (use-package anti-zenburn-theme
  ;;   :ensure t)

  (use-package dracula-theme
    :ensure t
    :config (load-theme 'dracula t)
    )

  ;; (use-package color-theme-sanityinc-tomorrow
  ;;  :ensure t
  ;;   :config (load-theme 'sanityinc-tomorrow-night t)
  ;; )

  ;(use-package solarized-theme
  ;  :ensure t
  ;  :config (load-theme 'solarized-light t)
  ;)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 90.4%
  • YASnippet 9.4%
  • Roff 0.2%