300 lines
9.8 KiB
EmacsLisp
Executable file
300 lines
9.8 KiB
EmacsLisp
Executable file
;; GROUP: Editing -> Editing Basics
|
|
|
|
(setq global-mark-ring-max 5000 ; increase mark ring to contains 5000 entries
|
|
mark-ring-max 5000 ; increase kill ring to contains 5000 entries
|
|
mode-require-final-newline t ; add a newline to end of file
|
|
)
|
|
|
|
;; set appearance of a tab that is represented by 2 spaces
|
|
(setq-default tab-width 2)
|
|
|
|
;; automatically indent when press RET
|
|
(global-set-key (kbd "RET") 'newline-and-indent)
|
|
|
|
;; activate whitespace-mode to view all whitespace characters
|
|
(global-set-key (kbd "C-c w") 'whitespace-mode)
|
|
|
|
(set-terminal-coding-system 'utf-8)
|
|
(set-keyboard-coding-system 'utf-8)
|
|
(set-language-environment "UTF-8")
|
|
(prefer-coding-system 'utf-8)
|
|
|
|
;; use space to indent by default
|
|
(setq-default indent-tabs-mode nil)
|
|
(delete-selection-mode)
|
|
(global-set-key (kbd "RET") 'newline-and-indent)
|
|
|
|
;; GROUP: Editing -> Killing
|
|
(setq kill-ring-max 5000 ; increase kill-ring capacity
|
|
kill-whole-line t ; if NIL, kill whole line and move the next line up
|
|
)
|
|
|
|
;; show whitespace in diff-mode
|
|
(add-hook 'diff-mode-hook (lambda ()
|
|
(setq-local whitespace-style
|
|
'(face
|
|
tabs
|
|
tab-mark
|
|
spaces
|
|
space-mark
|
|
trailing
|
|
indentation::space
|
|
indentation::tab
|
|
newline
|
|
newline-mark))
|
|
(whitespace-mode 1)))
|
|
|
|
;; Package: volatile-highlights --- show changes by "undo/yanks/..."
|
|
;; GROUP: Editing -> Volatile Highlights
|
|
(require 'volatile-highlights)
|
|
(volatile-highlights-mode t)
|
|
|
|
;; Package: clean-aindent-mode
|
|
;; GROUP: Editing -> Indent -> Clean Aindent
|
|
(require 'clean-aindent-mode)
|
|
(add-hook 'prog-mode-hook 'clean-aindent-mode)
|
|
|
|
|
|
;; PACKAGE: dtrt-indent
|
|
(require 'dtrt-indent)
|
|
(dtrt-indent-mode 1)
|
|
(setq dtrt-indent-verbosity 0)
|
|
|
|
;; PACKAGE: ws-butler
|
|
(require 'ws-butler)
|
|
(add-hook 'c-mode-common-hook 'ws-butler-mode)
|
|
(add-hook 'text-mode 'ws-butler-mode)
|
|
(add-hook 'fundamental-mode 'ws-butler-mode)
|
|
|
|
;; Package: undo-tree
|
|
;; GROUP: Editing -> Undo -> Undo Tree
|
|
(require 'undo-tree)
|
|
(global-undo-tree-mode)
|
|
|
|
;; Package: yasnippet
|
|
;; GROUP: Editing -> Yasnippet
|
|
(require 'yasnippet)
|
|
(yas-global-mode 1)
|
|
|
|
;; PACKAGE: smartparens
|
|
(require 'smartparens-config)
|
|
(setq sp-base-key-bindings 'paredit)
|
|
(setq sp-autoskip-closing-pair 'always)
|
|
(setq sp-hybrid-kill-entire-symbol nil)
|
|
(sp-use-paredit-bindings)
|
|
|
|
(show-smartparens-global-mode +1)
|
|
(smartparens-global-mode 1)
|
|
|
|
;; PACKAGE: comment-dwim-2
|
|
(global-set-key (kbd "M-;") 'comment-dwim-2)
|
|
|
|
;; Jump to end of snippet definition
|
|
(define-key yas-keymap (kbd "<return>") 'yas/exit-all-snippets)
|
|
|
|
;; Inter-field navigation
|
|
(defun yas/goto-end-of-active-field ()
|
|
(interactive)
|
|
(let* ((snippet (car (yas--snippets-at-point)))
|
|
(position (yas--field-end (yas--snippet-active-field snippet))))
|
|
(if (= (point) position)
|
|
(move-end-of-line 1)
|
|
(goto-char position))))
|
|
|
|
(defun yas/goto-start-of-active-field ()
|
|
(interactive)
|
|
(let* ((snippet (car (yas--snippets-at-point)))
|
|
(position (yas--field-start (yas--snippet-active-field snippet))))
|
|
(if (= (point) position)
|
|
(move-beginning-of-line 1)
|
|
(goto-char position))))
|
|
|
|
(define-key yas-keymap (kbd "C-e") 'yas/goto-end-of-active-field)
|
|
(define-key yas-keymap (kbd "C-a") 'yas/goto-start-of-active-field)
|
|
;; (define-key yas-minor-mode-map [(tab)] nil)
|
|
;; (define-key yas-minor-mode-map (kbd "TAB") nil)
|
|
;; (define-key yas-minor-mode-map (kbd "C-<tab>") 'yas-expand)
|
|
;; No dropdowns please, yas
|
|
(setq yas-prompt-functions '(yas/ido-prompt yas/completing-prompt))
|
|
|
|
;; No need to be so verbose
|
|
(setq yas-verbosity 1)
|
|
|
|
;; Wrap around region
|
|
(setq yas-wrap-around-region t)
|
|
|
|
(add-hook 'term-mode-hook (lambda() (setq yas-dont-activate t)))
|
|
|
|
;; PACKAGE: anzu
|
|
;; GROUP: Editing -> Matching -> Isearch -> Anzu
|
|
(require 'anzu)
|
|
(global-anzu-mode)
|
|
(global-set-key (kbd "M-%") 'anzu-query-replace)
|
|
(global-set-key (kbd "C-M-%") 'anzu-query-replace-regexp)
|
|
|
|
;; PACKAGE: iedit
|
|
(setq iedit-toggle-key-default nil)
|
|
(require 'iedit)
|
|
(global-set-key (kbd "C-;") 'iedit-mode)
|
|
|
|
;; Customized functions
|
|
(defun prelude-move-beginning-of-line (arg)
|
|
"Move point back to indentation of beginning of line.
|
|
|
|
Move point to the first non-whitespace character on this line.
|
|
If point is already there, move to the beginning of the line.
|
|
Effectively toggle between the first non-whitespace character and
|
|
the beginning of the line.
|
|
|
|
If ARG is not nil or 1, move forward ARG - 1 lines first. If
|
|
point reaches the beginning or end of the buffer, stop there."
|
|
(interactive "^p")
|
|
(setq arg (or arg 1))
|
|
|
|
;; Move lines first
|
|
(when (/= arg 1)
|
|
(let ((line-move-visual nil))
|
|
(forward-line (1- arg))))
|
|
|
|
(let ((orig-point (point)))
|
|
(back-to-indentation)
|
|
(when (= orig-point (point))
|
|
(move-beginning-of-line 1))))
|
|
|
|
(global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)
|
|
|
|
(defadvice kill-ring-save (before slick-copy activate compile)
|
|
"When called interactively with no active region, copy a single
|
|
line instead."
|
|
(interactive
|
|
(if mark-active (list (region-beginning) (region-end))
|
|
(message "Copied line")
|
|
(list (line-beginning-position)
|
|
(line-beginning-position 2)))))
|
|
|
|
(defadvice kill-region (before slick-cut activate compile)
|
|
"When called interactively with no active region, kill a single
|
|
line instead."
|
|
(interactive
|
|
(if mark-active (list (region-beginning) (region-end))
|
|
(list (line-beginning-position)
|
|
(line-beginning-position 2)))))
|
|
|
|
;; kill a line, including whitespace characters until next non-whiepsace character
|
|
;; of next line
|
|
(defadvice kill-line (before check-position activate)
|
|
(if (member major-mode
|
|
'(emacs-lisp-mode scheme-mode lisp-mode
|
|
c-mode c++-mode objc-mode
|
|
latex-mode plain-tex-mode))
|
|
(if (and (eolp) (not (bolp)))
|
|
(progn (forward-char 1)
|
|
(just-one-space 0)
|
|
(backward-char 1)))))
|
|
|
|
;; taken from prelude-editor.el
|
|
;; automatically indenting yanked text if in programming-modes
|
|
(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 1000
|
|
"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)))))
|
|
|
|
;; prelude-core.el
|
|
(defun indent-buffer ()
|
|
"Indent the currently visited buffer."
|
|
(interactive)
|
|
(indent-region (point-min) (point-max)))
|
|
|
|
;; prelude-editing.el
|
|
(defcustom prelude-indent-sensitive-modes
|
|
'(coffee-mode python-mode slim-mode haml-mode yaml-mode)
|
|
"Modes for which auto-indenting is suppressed."
|
|
:type 'list)
|
|
|
|
(defun indent-region-or-buffer ()
|
|
"Indent a region if selected, otherwise the whole buffer."
|
|
(interactive)
|
|
(unless (member major-mode prelude-indent-sensitive-modes)
|
|
(save-excursion
|
|
(if (region-active-p)
|
|
(progn
|
|
(indent-region (region-beginning) (region-end))
|
|
(message "Indented selected region."))
|
|
(progn
|
|
(indent-buffer)
|
|
(message "Indented buffer.")))
|
|
(whitespace-cleanup))))
|
|
|
|
(global-set-key (kbd "C-c i") 'indent-region-or-buffer)
|
|
|
|
;; add duplicate line function from Prelude
|
|
;; taken from prelude-core.el
|
|
(defun prelude-get-positions-of-line-or-region ()
|
|
"Return positions (beg . end) of the current line
|
|
or region."
|
|
(let (beg end)
|
|
(if (and mark-active (> (point) (mark)))
|
|
(exchange-point-and-mark))
|
|
(setq beg (line-beginning-position))
|
|
(if mark-active
|
|
(exchange-point-and-mark))
|
|
(setq end (line-end-position))
|
|
(cons beg end)))
|
|
|
|
;; smart openline
|
|
(defun prelude-smart-open-line (arg)
|
|
"Insert an empty line after the current line.
|
|
Position the cursor at its beginning, according to the current mode.
|
|
With a prefix ARG open line above the current line."
|
|
(interactive "P")
|
|
(if arg
|
|
(prelude-smart-open-line-above)
|
|
(progn
|
|
(move-end-of-line nil)
|
|
(newline-and-indent))))
|
|
|
|
(defun prelude-smart-open-line-above ()
|
|
"Insert an empty line above the current line.
|
|
Position the cursor at it's beginning, according to the current mode."
|
|
(interactive)
|
|
(move-beginning-of-line nil)
|
|
(newline-and-indent)
|
|
(forward-line -1)
|
|
(indent-according-to-mode))
|
|
|
|
(global-set-key (kbd "M-o") 'prelude-smart-open-line)
|
|
(global-set-key (kbd "M-o") 'open-line)
|
|
|
|
(provide 'setup-editing)
|