2017-08-28 18:45:11 +01:00
|
|
|
;;; programming.el --- Module file for programming configuration.
|
|
|
|
;;
|
|
|
|
;; Copyright (C) 2017 Wojciech Kozlowski
|
|
|
|
;;
|
|
|
|
;; Author: Wojciech Kozlowski <wojciech.kozlowski@vivaldi.net>
|
2017-08-28 19:21:48 +01:00
|
|
|
;; Created: 28 Aug 2017
|
2017-08-28 18:45:11 +01:00
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This module sets up packages and configuration for editing source code in
|
|
|
|
;; all languages.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
;;; Required packages:
|
|
|
|
|
|
|
|
(setq init-packages/programming-packages
|
|
|
|
|
2017-08-29 21:05:06 +01:00
|
|
|
'(company
|
|
|
|
yasnippet)
|
2017-08-28 18:45:11 +01:00
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Configuration:
|
|
|
|
|
|
|
|
(defun init-packages/init-programming ()
|
|
|
|
|
2017-08-29 21:05:06 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Company - complete anything.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package company
|
|
|
|
:init
|
|
|
|
(add-hook 'after-init-hook 'global-company-mode)
|
|
|
|
:config
|
|
|
|
(setq company-backends (delete 'company-clang company-backends)))
|
|
|
|
|
2017-08-28 22:48:11 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Enable yasnippet.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package yasnippet
|
|
|
|
:init
|
|
|
|
(yas-global-mode 1))
|
|
|
|
|
2017-08-28 19:21:48 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Line numbers.
|
2017-08-28 22:19:58 +01:00
|
|
|
;;
|
|
|
|
;; Ideally, we could just use linum-format "%4d \u2502". However, the
|
|
|
|
;; unicode character for the vertical line causes the screen to flicker on
|
|
|
|
;; some screens when typing or moving the cursor. Using `nlinum' does not
|
|
|
|
;; solve the problem. A compromise is to instead use a whitespace character
|
|
|
|
;; of a different colour.
|
|
|
|
;;
|
|
|
|
;; Furthermore, since `linum' can struggle with large buffers, it is disabled
|
|
|
|
;; once the number of lines cannot fit into linum-format anymore. `nlinum'
|
|
|
|
;; is meant to solve the problem, but it updates line numbers after a visible
|
|
|
|
;; pause if a line is inderted/deleted.
|
2017-08-28 19:21:48 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2017-08-28 22:19:58 +01:00
|
|
|
(defun linum-format-func (line)
|
|
|
|
(concat
|
|
|
|
(propertize (format "%4d " line) 'face 'linum)
|
|
|
|
(propertize " " 'face 'mode-line-inactive)))
|
|
|
|
|
|
|
|
(setq-default linum-format 'linum-format-func)
|
|
|
|
(add-hook 'prog-mode-hook '(lambda ()
|
|
|
|
(unless (> (count-lines (point-min) (point-max))
|
|
|
|
9999)
|
|
|
|
(linum-mode))))
|
2017-08-28 19:21:48 +01:00
|
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Formatting settings.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(setq-default c-default-style "linux")
|
|
|
|
|
2017-08-28 22:19:38 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Trailing whitespace.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; The following setting of `show-trailing-whitespace' is incompatible with
|
|
|
|
;; fci-mode. The only known workaround is to have whitespace mode on with
|
|
|
|
;; whitespace-style set such that only trailing whitespace is shown. At the
|
|
|
|
;; moment, just rely on `ws-butler'.
|
|
|
|
|
|
|
|
;; (add-hook 'prog-mode-hook (lambda ()
|
|
|
|
;; (interactive)
|
|
|
|
;; (setq show-trailing-whitespace t)))
|
|
|
|
|
2017-08-28 19:21:48 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Automatically indent yanked text in programming mode.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(defvar yank-indent-modes
|
|
|
|
'(LaTeX-mode TeX-mode)
|
|
|
|
"Modes in which to indent regions that are yanked (or yank-popped).
|
|
|
|
Only modes that don't derive from `prog-mode' should be
|
|
|
|
listed here.")
|
|
|
|
|
|
|
|
(defvar yank-indent-blacklisted-modes
|
|
|
|
'(python-mode slim-mode haml-mode)
|
|
|
|
"Modes for which auto-indenting is suppressed.")
|
|
|
|
|
|
|
|
(defvar yank-advised-indent-threshold 10000
|
|
|
|
"Threshold (# chars) over which indentation does not
|
|
|
|
automatically occur.")
|
|
|
|
|
|
|
|
(defun yank-advised-indent-function (beg end)
|
|
|
|
"Do indentation, as long as the region isn't too large."
|
|
|
|
(if (<= (- end beg) yank-advised-indent-threshold)
|
|
|
|
(indent-region beg end nil)))
|
|
|
|
|
|
|
|
(defadvice yank (after yank-indent activate)
|
|
|
|
"If current mode is one of 'yank-indent-modes,
|
|
|
|
indent yanked text (with prefix arg don't indent)."
|
|
|
|
(if (and (not (ad-get-arg 0))
|
|
|
|
(not (member major-mode yank-indent-blacklisted-modes))
|
|
|
|
(or (derived-mode-p 'prog-mode)
|
|
|
|
(member major-mode yank-indent-modes)))
|
|
|
|
(let ((transient-mark-mode nil))
|
|
|
|
(yank-advised-indent-function (region-beginning) (region-end)))))
|
|
|
|
|
|
|
|
(defadvice yank-pop (after yank-pop-indent activate)
|
|
|
|
"If current mode is one of `yank-indent-modes',
|
|
|
|
indent yanked text (with prefix arg don't indent)."
|
|
|
|
(when (and (not (ad-get-arg 0))
|
|
|
|
(not (member major-mode yank-indent-blacklisted-modes))
|
|
|
|
(or (derived-mode-p 'prog-mode)
|
|
|
|
(member major-mode yank-indent-modes)))
|
|
|
|
(let ((transient-mark-mode nil))
|
|
|
|
(yank-advised-indent-function (region-beginning) (region-end)))))
|
|
|
|
|
|
|
|
)
|