2015-09-16 09:24:25 +00:00
|
|
|
|
;;; funcs.el --- Spacemacs Base Layer functions File
|
2015-01-14 04:12:56 +00:00
|
|
|
|
;;
|
2017-01-06 03:51:13 +00:00
|
|
|
|
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
|
2015-01-14 04:12:56 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
2016-07-14 08:13:55 +00:00
|
|
|
|
(require 'cl-lib)
|
|
|
|
|
|
2016-06-24 15:54:47 +00:00
|
|
|
|
(defun spacemacs//run-local-vars-mode-hook ()
|
|
|
|
|
"Run a hook for the major-mode after the local variables have been processed."
|
2016-06-26 18:04:13 +00:00
|
|
|
|
(run-hooks (intern (format "%S-local-vars-hook" major-mode))))
|
2016-06-24 15:54:47 +00:00
|
|
|
|
|
2014-12-11 04:46:35 +00:00
|
|
|
|
(defun spacemacs/split-and-new-line ()
|
|
|
|
|
"Split a quoted string or s-expression and insert a new line with
|
|
|
|
|
auto-indent."
|
|
|
|
|
(interactive)
|
|
|
|
|
(sp-split-sexp 1)
|
|
|
|
|
(sp-newline))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/push-mark-and-goto-beginning-of-line ()
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
"Push a mark at current location and go to the beginning of the line."
|
2014-12-11 04:46:35 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(push-mark (point))
|
|
|
|
|
(evil-beginning-of-line))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/push-mark-and-goto-end-of-line ()
|
|
|
|
|
"Push a mark at current location and go to the end of the line."
|
|
|
|
|
(interactive)
|
|
|
|
|
(push-mark (point))
|
|
|
|
|
(evil-end-of-line))
|
|
|
|
|
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
(defun spacemacs/evil-insert-line-above (count)
|
|
|
|
|
"Insert one or several lines above the current point's line without changing
|
2013-04-18 21:21:31 +00:00
|
|
|
|
the current state and point position."
|
|
|
|
|
(interactive "p")
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
(dotimes (_ count) (save-excursion (evil-insert-newline-above))))
|
2013-04-18 21:21:31 +00:00
|
|
|
|
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
(defun spacemacs/evil-insert-line-below (count)
|
|
|
|
|
"Insert one or several lines below the current point's line without changing
|
2013-04-18 21:21:31 +00:00
|
|
|
|
the current state and point position."
|
|
|
|
|
(interactive "p")
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
(dotimes (_ count) (save-excursion (evil-insert-newline-below))))
|
2013-04-18 21:21:31 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/evil-goto-next-line-and-indent (&optional count)
|
2016-12-16 19:14:27 +00:00
|
|
|
|
"Match the current lines indentation to the next line.
|
|
|
|
|
A COUNT argument matches the indentation to the next COUNT lines."
|
2014-11-17 02:30:48 +00:00
|
|
|
|
(interactive "p")
|
|
|
|
|
(let ((counter (or count 1)))
|
|
|
|
|
(while (> counter 0)
|
|
|
|
|
(join-line 1)
|
2015-10-17 01:23:20 +00:00
|
|
|
|
(newline-and-indent)
|
2014-11-17 02:30:48 +00:00
|
|
|
|
(setq counter (1- counter)))))
|
|
|
|
|
|
2015-03-26 16:26:09 +00:00
|
|
|
|
;; from Prelude
|
2015-05-11 02:49:07 +00:00
|
|
|
|
;; TODO: dispatch these in the layers
|
2015-03-26 16:26:09 +00:00
|
|
|
|
(defvar spacemacs-indent-sensitive-modes
|
2017-01-21 11:57:41 +00:00
|
|
|
|
'(asm-mode
|
|
|
|
|
coffee-mode
|
2016-04-17 16:59:30 +00:00
|
|
|
|
elm-mode
|
2015-03-26 16:26:09 +00:00
|
|
|
|
haml-mode
|
2016-02-21 02:25:45 +00:00
|
|
|
|
haskell-mode
|
|
|
|
|
slim-mode
|
2015-03-26 16:26:09 +00:00
|
|
|
|
makefile-mode
|
2016-02-21 02:25:45 +00:00
|
|
|
|
makefile-bsdmake-mode
|
2015-03-26 16:26:09 +00:00
|
|
|
|
makefile-gmake-mode
|
|
|
|
|
makefile-imake-mode
|
2016-02-23 19:53:44 +00:00
|
|
|
|
python-mode
|
|
|
|
|
yaml-mode)
|
2015-03-26 16:26:09 +00:00
|
|
|
|
"Modes for which auto-indenting is suppressed.")
|
2015-05-04 12:28:59 +00:00
|
|
|
|
|
|
|
|
|
(defcustom spacemacs-yank-indent-threshold 1000
|
|
|
|
|
"Threshold (# chars) over which indentation does not automatically occur."
|
|
|
|
|
:type 'number
|
|
|
|
|
:group 'spacemacs)
|
|
|
|
|
|
2016-03-25 11:55:14 +00:00
|
|
|
|
(defcustom spacemacs-large-file-modes-list
|
|
|
|
|
'(archive-mode tar-mode jka-compr git-commit-mode image-mode
|
|
|
|
|
doc-view-mode doc-view-mode-maybe ebrowse-tree-mode
|
|
|
|
|
pdf-view-mode)
|
|
|
|
|
"Major modes which `spacemacs/check-large-file' will not be
|
|
|
|
|
automatically applied to."
|
|
|
|
|
:group 'spacemacs
|
|
|
|
|
:type '(list symbol))
|
|
|
|
|
|
|
|
|
|
|
2015-03-26 16:26:09 +00:00
|
|
|
|
(defun spacemacs/indent-region-or-buffer ()
|
|
|
|
|
"Indent a region if selected, otherwise the whole buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(unless (member major-mode spacemacs-indent-sensitive-modes)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if (region-active-p)
|
|
|
|
|
(progn
|
|
|
|
|
(indent-region (region-beginning) (region-end))
|
|
|
|
|
(message "Indented selected region."))
|
|
|
|
|
(progn
|
|
|
|
|
(evil-indent (point-min) (point-max))
|
|
|
|
|
(message "Indented buffer.")))
|
|
|
|
|
(whitespace-cleanup))))
|
|
|
|
|
|
2012-12-20 21:51:11 +00:00
|
|
|
|
;; from https://gist.github.com/3402786
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/toggle-maximize-buffer ()
|
2014-05-01 01:41:26 +00:00
|
|
|
|
"Maximize buffer"
|
2012-12-20 21:51:11 +00:00
|
|
|
|
(interactive)
|
2015-05-28 04:05:29 +00:00
|
|
|
|
(if (and (= 1 (length (window-list)))
|
2016-02-16 17:35:36 +00:00
|
|
|
|
(assoc ?_ register-alist))
|
|
|
|
|
(jump-to-register ?_)
|
2012-12-20 21:51:11 +00:00
|
|
|
|
(progn
|
2016-02-16 17:35:36 +00:00
|
|
|
|
(window-configuration-to-register ?_)
|
2012-12-20 21:51:11 +00:00
|
|
|
|
(delete-other-windows))))
|
|
|
|
|
|
2016-07-01 18:20:28 +00:00
|
|
|
|
;; https://tsdh.wordpress.com/2007/03/28/deleting-windows-vertically-or-horizontally/
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(defun spacemacs/maximize-horizontally ()
|
2016-07-01 18:20:28 +00:00
|
|
|
|
"Delete all windows left or right of the current window."
|
|
|
|
|
(interactive)
|
|
|
|
|
(require 'windmove)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (condition-case nil (windmove-left) (error nil))
|
|
|
|
|
(delete-window))
|
|
|
|
|
(while (condition-case nil (windmove-right) (error nil))
|
|
|
|
|
(delete-window))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/toggle-centered-buffer-mode ()
|
|
|
|
|
"Toggle `spacemacs-centered-buffer-mode'."
|
|
|
|
|
(interactive)
|
|
|
|
|
(when (require 'centered-buffer-mode nil t)
|
|
|
|
|
(call-interactively 'spacemacs-centered-buffer-mode)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/centered-buffer-mode-full-width ()
|
2016-07-05 23:36:15 +00:00
|
|
|
|
"Center buffer in the frame."
|
2016-07-01 18:20:28 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(when (require 'centered-buffer-mode nil t)
|
|
|
|
|
(spacemacs/maximize-horizontally)
|
|
|
|
|
(call-interactively 'spacemacs-centered-buffer-mode)))
|
|
|
|
|
|
2016-07-26 10:00:26 +00:00
|
|
|
|
(defun spacemacs/useful-buffer-p (buffer)
|
|
|
|
|
"Determines if a buffer is useful."
|
|
|
|
|
(let ((buf-name (buffer-name buffer)))
|
|
|
|
|
(or (with-current-buffer buffer
|
|
|
|
|
(derived-mode-p 'comint-mode))
|
|
|
|
|
(cl-loop for useful-regexp in spacemacs-useful-buffers-regexp
|
|
|
|
|
thereis (string-match-p useful-regexp buf-name))
|
|
|
|
|
(cl-loop for useless-regexp in spacemacs-useless-buffers-regexp
|
|
|
|
|
never (string-match-p useless-regexp buf-name)))))
|
2016-06-26 03:40:41 +00:00
|
|
|
|
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(defun spacemacs/useless-buffer-p (buffer)
|
2016-07-14 08:13:55 +00:00
|
|
|
|
"Determines if a buffer is useless."
|
2016-07-26 10:00:26 +00:00
|
|
|
|
(not (spacemacs/useful-buffer-p buffer)))
|
2016-07-14 08:13:55 +00:00
|
|
|
|
|
2016-08-23 15:58:23 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/swap-windows (window1 window2)
|
|
|
|
|
"Swap two windows.
|
|
|
|
|
WINDOW1 and WINDOW2 must be valid windows. They may contain child
|
|
|
|
|
windows."
|
|
|
|
|
(let ((state1 (window-state-get window1))
|
|
|
|
|
(state2 (window-state-get window2)))
|
|
|
|
|
;; to put state into dedicated windows, we must undedicate them first (not
|
|
|
|
|
;; needed with Emacs 25.1)
|
|
|
|
|
(dolist (win (list window1 window2))
|
|
|
|
|
(if (window-live-p win)
|
|
|
|
|
(set-window-dedicated-p win nil)
|
|
|
|
|
;; win has sub-windows, undedicate all of them
|
|
|
|
|
(walk-window-subtree (lambda (leaf-window)
|
|
|
|
|
(set-window-dedicated-p leaf-window nil))
|
|
|
|
|
win)))
|
|
|
|
|
(window-state-put state1 window2)
|
|
|
|
|
(window-state-put state2 window1)))
|
|
|
|
|
|
2016-11-12 20:22:46 +00:00
|
|
|
|
;; from @bmag
|
|
|
|
|
(defun spacemacs/window-layout-toggle ()
|
|
|
|
|
"Toggle between horizontal and vertical layout of two windows."
|
|
|
|
|
(interactive)
|
2016-11-15 07:25:44 +00:00
|
|
|
|
(if (= (count-windows) 2)
|
2016-11-12 20:22:46 +00:00
|
|
|
|
(let* ((window-tree (car (window-tree)))
|
|
|
|
|
(current-split-vertical-p (car window-tree))
|
|
|
|
|
(first-window (nth 2 window-tree))
|
|
|
|
|
(second-window (nth 3 window-tree))
|
|
|
|
|
(second-window-state (window-state-get second-window))
|
|
|
|
|
(splitter (if current-split-vertical-p
|
|
|
|
|
#'split-window-horizontally
|
|
|
|
|
#'split-window-vertically)))
|
|
|
|
|
(delete-other-windows first-window)
|
|
|
|
|
;; `window-state-put' also re-selects the window if needed, so we don't
|
|
|
|
|
;; need to call `select-window'
|
2016-11-15 07:25:44 +00:00
|
|
|
|
(window-state-put second-window-state (funcall splitter)))
|
|
|
|
|
(error "Can't toggle window layout when the number of windows isn't two.")))
|
2016-11-12 20:22:46 +00:00
|
|
|
|
|
2016-08-23 15:58:23 +00:00
|
|
|
|
;; originally from magnars and modified by ffevotte for dedicated windows
|
|
|
|
|
;; support, it has quite diverged by now
|
|
|
|
|
(defun spacemacs/rotate-windows-forward (count)
|
rotate-windows and -backwards, comment correction
Changes to the comment in the `spacemacs/rotate-windows` function
Sentences reordered:
From:
Default behavior.
Additional behavior. Prefix argument behavior.
To:
Default behavior,
Prefix argument behavior,
Additional behavior.
Spelling:
First sentence:
"your" replaced with "each",
"forwards" added to the end.
Second sentence (after reordering the last two sentences):
"Giving" removed,
"takes" replaced with "rotates",
"kindows" corrected to "windows",
"rotate" (next to last word) removed
(Optional) Third sentence (after reordering):
"(locked)" added after "Dedicated", it might clarify that a dedicated window means that it is locked.
After these changes:
Before:
"Rotate your windows.
Dedicated windows are left untouched. Giving a negative prefix
argument takes the kindows rotate backwards."
After:
"Rotate each window forwards.
A negative prefix argument rotates each window backwards.
Dedicated (locked) windows are left untouched."
The comment in the function: `spacemacs/rotate-windows-backward`
"your" replaced with "each",
"s" added to "backward",
added the same additional behavior comment as in the "main" rotation function,
"Dedicated (locked) windows are left untouched."
Before:
"Rotate your windows backward."
After:
"Rotate each window backwards.
Dedicated (locked) windows are left untouched."
2016-08-20 12:02:09 +00:00
|
|
|
|
"Rotate each window forwards.
|
|
|
|
|
A negative prefix argument rotates each window backwards.
|
|
|
|
|
Dedicated (locked) windows are left untouched."
|
2015-04-13 19:29:46 +00:00
|
|
|
|
(interactive "p")
|
2016-08-23 15:58:23 +00:00
|
|
|
|
(let* ((non-dedicated-windows (cl-remove-if 'window-dedicated-p (window-list)))
|
|
|
|
|
(states (mapcar #'window-state-get non-dedicated-windows))
|
2015-04-13 19:29:46 +00:00
|
|
|
|
(num-windows (length non-dedicated-windows))
|
|
|
|
|
(step (+ num-windows count)))
|
2016-08-23 15:58:23 +00:00
|
|
|
|
(if (< num-windows 2)
|
|
|
|
|
(error "You can't rotate a single window!")
|
|
|
|
|
(dotimes (i num-windows)
|
|
|
|
|
(window-state-put
|
|
|
|
|
(elt states i)
|
|
|
|
|
(elt non-dedicated-windows (% (+ step i) num-windows)))))))
|
2012-12-18 05:48:12 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/rotate-windows-backward (count)
|
rotate-windows and -backwards, comment correction
Changes to the comment in the `spacemacs/rotate-windows` function
Sentences reordered:
From:
Default behavior.
Additional behavior. Prefix argument behavior.
To:
Default behavior,
Prefix argument behavior,
Additional behavior.
Spelling:
First sentence:
"your" replaced with "each",
"forwards" added to the end.
Second sentence (after reordering the last two sentences):
"Giving" removed,
"takes" replaced with "rotates",
"kindows" corrected to "windows",
"rotate" (next to last word) removed
(Optional) Third sentence (after reordering):
"(locked)" added after "Dedicated", it might clarify that a dedicated window means that it is locked.
After these changes:
Before:
"Rotate your windows.
Dedicated windows are left untouched. Giving a negative prefix
argument takes the kindows rotate backwards."
After:
"Rotate each window forwards.
A negative prefix argument rotates each window backwards.
Dedicated (locked) windows are left untouched."
The comment in the function: `spacemacs/rotate-windows-backward`
"your" replaced with "each",
"s" added to "backward",
added the same additional behavior comment as in the "main" rotation function,
"Dedicated (locked) windows are left untouched."
Before:
"Rotate your windows backward."
After:
"Rotate each window backwards.
Dedicated (locked) windows are left untouched."
2016-08-20 12:02:09 +00:00
|
|
|
|
"Rotate each window backwards.
|
|
|
|
|
Dedicated (locked) windows are left untouched."
|
2013-02-20 19:06:31 +00:00
|
|
|
|
(interactive "p")
|
2016-08-23 15:58:23 +00:00
|
|
|
|
(spacemacs/rotate-windows-forward (* -1 count)))
|
2013-02-19 23:12:10 +00:00
|
|
|
|
|
2016-10-21 04:23:33 +00:00
|
|
|
|
(defun spacemacs/move-buffer-to-window (windownum follow-focus-p)
|
|
|
|
|
"Moves a buffer to a window, using the spacemacs numbering. follow-focus-p
|
|
|
|
|
controls whether focus moves to new window (with buffer), or stays on
|
|
|
|
|
current"
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((b (current-buffer))
|
|
|
|
|
(w1 (selected-window))
|
2016-12-10 01:31:19 +00:00
|
|
|
|
(w2 (winum-get-window-by-number windownum)))
|
2016-10-21 04:23:33 +00:00
|
|
|
|
(unless (eq w1 w2)
|
|
|
|
|
(set-window-buffer w2 b)
|
|
|
|
|
(switch-to-prev-buffer)
|
|
|
|
|
(unrecord-window-buffer w1 b)))
|
2016-12-10 01:31:19 +00:00
|
|
|
|
(when follow-focus-p (select-window (winum-get-window-by-number windownum))))
|
2016-10-21 04:23:33 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/swap-buffers-to-window (windownum follow-focus-p)
|
|
|
|
|
"Swaps visible buffers between active window and selected window.
|
|
|
|
|
follow-focus-p controls whether focus moves to new window (with buffer), or
|
|
|
|
|
stays on current"
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((b1 (current-buffer))
|
|
|
|
|
(w1 (selected-window))
|
2016-12-10 01:31:19 +00:00
|
|
|
|
(w2 (winum-get-window-by-number windownum))
|
2016-10-21 04:23:33 +00:00
|
|
|
|
(b2 (window-buffer w2)))
|
|
|
|
|
(unless (eq w1 w2)
|
|
|
|
|
(set-window-buffer w1 b2)
|
|
|
|
|
(set-window-buffer w2 b1)
|
|
|
|
|
(unrecord-window-buffer w1 b1)
|
|
|
|
|
(unrecord-window-buffer w2 b2)))
|
2017-04-26 10:14:52 +00:00
|
|
|
|
(when follow-focus-p (winum-select-window-by-number windownum)))
|
2016-10-21 04:23:33 +00:00
|
|
|
|
|
|
|
|
|
(dotimes (i 9)
|
|
|
|
|
(let ((n (+ i 1)))
|
|
|
|
|
(eval `(defun ,(intern (format "buffer-to-window-%s" n)) (&optional arg)
|
|
|
|
|
,(format "Move buffer to the window with number %i." n)
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(if arg
|
|
|
|
|
(spacemacs/swap-buffers-to-window ,n t)
|
2016-10-23 14:43:11 +00:00
|
|
|
|
(spacemacs/move-buffer-to-window ,n t))))
|
|
|
|
|
(eval `(defun ,(intern (format "move-buffer-window-no-follow-%s" n)) ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(spacemacs/move-buffer-to-window ,n nil)))
|
|
|
|
|
(eval `(defun ,(intern (format "swap-buffer-window-no-follow-%s" n)) ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(spacemacs/swap-buffers-to-window ,n nil)))
|
|
|
|
|
))
|
2016-10-21 04:23:33 +00:00
|
|
|
|
|
2016-06-01 08:04:23 +00:00
|
|
|
|
(defun spacemacs/rename-file (filename &optional new-filename)
|
|
|
|
|
"Rename FILENAME to NEW-FILENAME.
|
|
|
|
|
|
|
|
|
|
When NEW-FILENAME is not specified, asks user for a new name.
|
|
|
|
|
|
|
|
|
|
Also renames associated buffer (if any exists), invalidates
|
|
|
|
|
projectile cache when it's possible and update recentf list."
|
|
|
|
|
(interactive "f")
|
|
|
|
|
(when (and filename (file-exists-p filename))
|
|
|
|
|
(let* ((buffer (find-buffer-visiting filename))
|
|
|
|
|
(short-name (file-name-nondirectory filename))
|
|
|
|
|
(new-name (if new-filename new-filename
|
|
|
|
|
(read-file-name
|
|
|
|
|
(format "Rename %s to: " short-name)))))
|
|
|
|
|
(cond ((get-buffer new-name)
|
|
|
|
|
(error "A buffer named '%s' already exists!" new-name))
|
|
|
|
|
(t
|
|
|
|
|
(let ((dir (file-name-directory new-name)))
|
|
|
|
|
(when (and (not (file-exists-p dir)) (yes-or-no-p (format "Create directory '%s'?" dir)))
|
|
|
|
|
(make-directory dir t)))
|
|
|
|
|
(rename-file filename new-name 1)
|
|
|
|
|
(when buffer
|
|
|
|
|
(kill-buffer buffer)
|
2016-06-17 18:44:00 +00:00
|
|
|
|
(find-file new-name))
|
2016-06-01 08:04:23 +00:00
|
|
|
|
(when (fboundp 'recentf-add-file)
|
|
|
|
|
(recentf-add-file new-name)
|
|
|
|
|
(recentf-remove-if-non-kept filename))
|
|
|
|
|
(when (and (configuration-layer/package-usedp 'projectile)
|
|
|
|
|
(projectile-project-p))
|
|
|
|
|
(call-interactively #'projectile-invalidate-cache))
|
2016-06-17 18:44:00 +00:00
|
|
|
|
(message "File '%s' successfully renamed to '%s'" short-name (file-name-nondirectory new-name)))))))
|
2016-06-01 08:04:23 +00:00
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
|
;; from magnars
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/rename-current-buffer-file ()
|
2017-04-14 17:39:14 +00:00
|
|
|
|
"Rename the current buffer and the file it is visiting.
|
|
|
|
|
If the buffer isn't visiting a file, ask if it should
|
|
|
|
|
be saved to a file, or just renamed."
|
2012-12-29 20:39:39 +00:00
|
|
|
|
(interactive)
|
2016-07-12 06:04:13 +00:00
|
|
|
|
(let* ((name (buffer-name))
|
2017-04-14 17:39:14 +00:00
|
|
|
|
(filename (buffer-file-name)))
|
|
|
|
|
(if (and filename (file-exists-p filename))
|
|
|
|
|
;; the buffer is visiting a file
|
|
|
|
|
(let* ((dir (file-name-directory filename))
|
|
|
|
|
(new-name (read-file-name "New name: " dir)))
|
|
|
|
|
(cond ((get-buffer new-name)
|
|
|
|
|
(error "A buffer named '%s' already exists!" new-name))
|
|
|
|
|
(t
|
|
|
|
|
(let ((dir (file-name-directory new-name)))
|
|
|
|
|
(when (and (not (file-exists-p dir))
|
|
|
|
|
(yes-or-no-p
|
|
|
|
|
(format "Create directory '%s'?" dir)))
|
|
|
|
|
(make-directory dir t)))
|
|
|
|
|
(rename-file filename new-name 1)
|
|
|
|
|
(rename-buffer new-name)
|
|
|
|
|
(set-visited-file-name new-name)
|
|
|
|
|
(set-buffer-modified-p nil)
|
|
|
|
|
(when (fboundp 'recentf-add-file)
|
2016-01-31 22:29:50 +00:00
|
|
|
|
(recentf-add-file new-name)
|
|
|
|
|
(recentf-remove-if-non-kept filename))
|
2017-04-14 17:39:14 +00:00
|
|
|
|
(when (and (configuration-layer/package-usedp 'projectile)
|
|
|
|
|
(projectile-project-p))
|
|
|
|
|
(call-interactively #'projectile-invalidate-cache))
|
|
|
|
|
(message "File '%s' successfully renamed to '%s'"
|
|
|
|
|
name (file-name-nondirectory new-name)))))
|
|
|
|
|
;; the buffer is not visiting a file
|
|
|
|
|
(let ((key))
|
|
|
|
|
(while (not (memq key '(?s ?r)))
|
|
|
|
|
(setq key (read-key (propertize
|
|
|
|
|
(format
|
|
|
|
|
(concat "Buffer '%s' is not visiting a file: "
|
|
|
|
|
"[s]ave to file or [r]ename buffer?")
|
|
|
|
|
name) 'face 'minibuffer-prompt)))
|
|
|
|
|
(cond ((eq key ?s) ; save to file
|
|
|
|
|
;; this allows for saving a new empty (unmodified) buffer
|
|
|
|
|
(unless (buffer-modified-p) (set-buffer-modified-p t))
|
|
|
|
|
(save-buffer))
|
|
|
|
|
((eq key ?r) ; rename buffer
|
|
|
|
|
(let ((new-name (read-string "New buffer name: ")))
|
|
|
|
|
(while (get-buffer new-name)
|
|
|
|
|
;; ask to rename again, if the new buffer name exists
|
|
|
|
|
(if (yes-or-no-p
|
|
|
|
|
(format (concat "A buffer named '%s' already exists: "
|
|
|
|
|
"Rename again?") new-name))
|
|
|
|
|
(setq new-name (read-string "New buffer name: "))
|
|
|
|
|
(keyboard-quit)))
|
|
|
|
|
(rename-buffer new-name)
|
|
|
|
|
(message "Buffer '%s' successfully renamed to '%s'"
|
|
|
|
|
name new-name)))
|
|
|
|
|
;; ?\a = C-g, ?\e = Esc and C-[
|
|
|
|
|
((memq key '(?\a ?\e)) (keyboard-quit))))))))
|
2012-12-29 20:39:39 +00:00
|
|
|
|
|
2016-06-01 08:04:23 +00:00
|
|
|
|
(defun spacemacs/delete-file (filename &optional ask-user)
|
|
|
|
|
"Remove specified file or directory.
|
|
|
|
|
|
|
|
|
|
Also kills associated buffer (if any exists) and invalidates
|
|
|
|
|
projectile cache when it's possible.
|
|
|
|
|
|
|
|
|
|
When ASK-USER is non-nil, user will be asked to confirm file
|
|
|
|
|
removal."
|
|
|
|
|
(interactive "f")
|
|
|
|
|
(when (and filename (file-exists-p filename))
|
|
|
|
|
(let ((buffer (find-buffer-visiting filename)))
|
|
|
|
|
(when buffer
|
|
|
|
|
(kill-buffer buffer)))
|
|
|
|
|
(when (or (not ask-user)
|
|
|
|
|
(yes-or-no-p "Are you sure you want to delete this file? "))
|
|
|
|
|
(delete-file filename)
|
|
|
|
|
(when (and (configuration-layer/package-usedp 'projectile)
|
|
|
|
|
(projectile-project-p))
|
|
|
|
|
(call-interactively #'projectile-invalidate-cache)))))
|
|
|
|
|
|
2016-12-22 13:52:25 +00:00
|
|
|
|
(defun spacemacs/delete-file-confirm (filename)
|
|
|
|
|
"Remove specified file or directory after users approval.
|
|
|
|
|
|
|
|
|
|
FILENAME is deleted using `spacemacs/delete-file' function.."
|
|
|
|
|
(interactive "f")
|
|
|
|
|
(funcall-interactively #'spacemacs/delete-file filename t))
|
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
|
;; from magnars
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/delete-current-buffer-file ()
|
2012-12-29 20:39:39 +00:00
|
|
|
|
"Removes file connected to current buffer and kills buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((filename (buffer-file-name))
|
|
|
|
|
(buffer (current-buffer))
|
|
|
|
|
(name (buffer-name)))
|
|
|
|
|
(if (not (and filename (file-exists-p filename)))
|
|
|
|
|
(ido-kill-buffer)
|
2014-11-23 05:38:56 +00:00
|
|
|
|
(when (yes-or-no-p "Are you sure you want to delete this file? ")
|
2014-11-29 03:47:03 +00:00
|
|
|
|
(delete-file filename t)
|
2012-12-29 20:39:39 +00:00
|
|
|
|
(kill-buffer buffer)
|
2016-06-01 06:18:44 +00:00
|
|
|
|
(when (and (configuration-layer/package-usedp 'projectile)
|
|
|
|
|
(projectile-project-p))
|
|
|
|
|
(call-interactively #'projectile-invalidate-cache))
|
2012-12-29 20:39:39 +00:00
|
|
|
|
(message "File '%s' successfully removed" filename)))))
|
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
|
;; from magnars
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/sudo-edit (&optional arg)
|
2016-12-08 15:52:29 +00:00
|
|
|
|
(interactive "P")
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(let ((fname (if (or arg (not buffer-file-name))
|
|
|
|
|
(read-file-name "File: ")
|
|
|
|
|
buffer-file-name)))
|
2015-12-08 17:42:20 +00:00
|
|
|
|
(find-file
|
|
|
|
|
(cond ((string-match-p "^/ssh:" fname)
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert fname)
|
|
|
|
|
(search-backward ":")
|
|
|
|
|
(let ((last-match-end nil)
|
|
|
|
|
(last-ssh-hostname nil))
|
|
|
|
|
(while (string-match "@\\\([^:|]+\\\)" fname last-match-end)
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(setq last-ssh-hostname (or (match-string 1 fname)
|
|
|
|
|
last-ssh-hostname))
|
2015-12-08 17:42:20 +00:00
|
|
|
|
(setq last-match-end (match-end 0)))
|
|
|
|
|
(insert (format "|sudo:%s" (or last-ssh-hostname "localhost"))))
|
|
|
|
|
(buffer-string)))
|
|
|
|
|
(t (concat "/sudo:root@localhost:" fname))))))
|
2012-12-29 20:39:39 +00:00
|
|
|
|
|
2015-10-30 16:20:02 +00:00
|
|
|
|
;; check when opening large files - literal file open
|
|
|
|
|
(defun spacemacs/check-large-file ()
|
2016-06-02 08:46:27 +00:00
|
|
|
|
(let* ((filename (buffer-file-name))
|
|
|
|
|
(size (nth 7 (file-attributes filename))))
|
2016-03-25 11:55:14 +00:00
|
|
|
|
(when (and
|
|
|
|
|
(not (memq major-mode spacemacs-large-file-modes-list))
|
|
|
|
|
size (> size (* 1024 1024 dotspacemacs-large-file-size))
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(y-or-n-p (format (concat "%s is a large file, open literally to "
|
|
|
|
|
"avoid performance issues?")
|
2016-06-02 08:46:27 +00:00
|
|
|
|
filename)))
|
2016-03-12 16:45:41 +00:00
|
|
|
|
(setq buffer-read-only t)
|
|
|
|
|
(buffer-disable-undo)
|
|
|
|
|
(fundamental-mode))))
|
2015-10-30 16:20:02 +00:00
|
|
|
|
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(defun spacemacs/delete-window (&optional arg)
|
|
|
|
|
"Delete the current window.
|
|
|
|
|
If the universal prefix argument is used then kill the buffer too."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(if (equal '(4) arg)
|
|
|
|
|
(kill-buffer-and-window)
|
|
|
|
|
(delete-window)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/ace-delete-window (&optional arg)
|
|
|
|
|
"Ace delete window.
|
|
|
|
|
If the universal prefix argument is used then kill the buffer too."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(require 'ace-window)
|
|
|
|
|
(aw-select
|
|
|
|
|
" Ace - Delete Window"
|
|
|
|
|
(lambda (window)
|
|
|
|
|
(when (equal '(4) arg)
|
|
|
|
|
(with-selected-window window
|
|
|
|
|
(spacemacs/kill-this-buffer arg)))
|
|
|
|
|
(aw-delete-window window))))
|
|
|
|
|
|
2016-06-04 12:46:31 +00:00
|
|
|
|
;; our own implementation of kill-this-buffer from menu-bar.el
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(defun spacemacs/kill-this-buffer (&optional arg)
|
|
|
|
|
"Kill the current buffer.
|
|
|
|
|
If the universal prefix argument is used then kill also the window."
|
|
|
|
|
(interactive "P")
|
2016-06-04 12:46:31 +00:00
|
|
|
|
(if (window-minibuffer-p)
|
|
|
|
|
(abort-recursive-edit)
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(if (equal '(4) arg)
|
|
|
|
|
(kill-buffer-and-window)
|
|
|
|
|
(kill-buffer))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/ace-kill-this-buffer (&optional arg)
|
|
|
|
|
"Ace kill visible buffer in a window.
|
|
|
|
|
If the universal prefix argument is used then kill also the window."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(require 'ace-window)
|
|
|
|
|
(let (golden-ratio-mode)
|
|
|
|
|
(aw-select
|
|
|
|
|
" Ace - Kill buffer in Window"
|
|
|
|
|
(lambda (window)
|
|
|
|
|
(with-selected-window window
|
|
|
|
|
(spacemacs/kill-this-buffer arg))))))
|
2016-06-04 12:46:31 +00:00
|
|
|
|
|
2013-01-02 22:08:45 +00:00
|
|
|
|
;; found at http://emacswiki.org/emacs/KillingBuffers
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(defun spacemacs/kill-other-buffers (&optional arg)
|
|
|
|
|
"Kill all other buffers.
|
|
|
|
|
If the universal prefix argument is used then will the windows too."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(when (yes-or-no-p (format "Killing all buffers except \"%s\"? "
|
|
|
|
|
(buffer-name)))
|
2015-11-03 12:53:10 +00:00
|
|
|
|
(mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
|
2016-06-26 03:40:41 +00:00
|
|
|
|
(when (equal '(4) arg) (delete-other-windows))
|
2015-11-03 12:53:10 +00:00
|
|
|
|
(message "Buffers deleted!")))
|
2013-01-02 22:08:45 +00:00
|
|
|
|
|
2013-01-08 16:09:21 +00:00
|
|
|
|
;; from http://dfan.org/blog/2009/02/19/emacs-dedicated-windows/
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/toggle-current-window-dedication ()
|
2013-01-08 16:09:21 +00:00
|
|
|
|
"Toggle dedication state of a window."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((window (selected-window))
|
|
|
|
|
(dedicated (window-dedicated-p window)))
|
|
|
|
|
(set-window-dedicated-p window (not dedicated))
|
|
|
|
|
(message "Window %sdedicated to %s"
|
|
|
|
|
(if dedicated "no longer " "")
|
|
|
|
|
(buffer-name))))
|
|
|
|
|
|
2013-11-15 13:03:14 +00:00
|
|
|
|
;; http://camdez.com/blog/2013/11/14/emacs-show-buffer-file-name/
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/show-and-copy-buffer-filename ()
|
2016-01-26 03:15:15 +00:00
|
|
|
|
"Show and copy the full path to the current file in the minibuffer."
|
2013-11-15 13:03:14 +00:00
|
|
|
|
(interactive)
|
2016-02-18 18:36:16 +00:00
|
|
|
|
;; list-buffers-directory is the variable set in dired buffers
|
|
|
|
|
(let ((file-name (or (buffer-file-name) list-buffers-directory)))
|
2013-11-15 13:03:14 +00:00
|
|
|
|
(if file-name
|
2016-02-18 18:36:16 +00:00
|
|
|
|
(message (kill-new file-name))
|
2013-11-15 13:03:14 +00:00
|
|
|
|
(error "Buffer not visiting a file"))))
|
2013-04-15 15:12:39 +00:00
|
|
|
|
|
2013-11-26 05:24:50 +00:00
|
|
|
|
;; adapted from bozhidar
|
2013-11-15 15:55:23 +00:00
|
|
|
|
;; http://emacsredux.com/blog/2013/05/18/instant-access-to-init-dot-el/
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/find-user-init-file ()
|
2013-11-26 05:24:50 +00:00
|
|
|
|
"Edit the `user-init-file', in the current window."
|
2013-11-15 15:55:23 +00:00
|
|
|
|
(interactive)
|
2013-11-18 02:14:33 +00:00
|
|
|
|
(find-file-existing user-init-file))
|
2013-11-15 15:55:23 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/find-dotfile ()
|
2014-11-10 05:38:58 +00:00
|
|
|
|
"Edit the `dotfile', in the current window."
|
|
|
|
|
(interactive)
|
2014-11-22 02:55:00 +00:00
|
|
|
|
(find-file-existing (dotspacemacs/location)))
|
2014-11-10 05:38:58 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/ediff-dotfile-and-template ()
|
2015-04-22 12:52:22 +00:00
|
|
|
|
"ediff the current `dotfile' with the template"
|
|
|
|
|
(interactive)
|
|
|
|
|
(ediff-files (dotspacemacs/location)
|
|
|
|
|
(concat dotspacemacs-template-directory ".spacemacs.template")))
|
|
|
|
|
|
2017-04-13 21:58:20 +00:00
|
|
|
|
(defun spacemacs/new-empty-buffer (&optional split)
|
|
|
|
|
"Create a new buffer called untitled(<n>).
|
|
|
|
|
A SPLIT argument with the value: `left',
|
|
|
|
|
`below', `above' or `right', opens the new
|
|
|
|
|
buffer in a split window."
|
2015-09-10 11:26:57 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((newbuf (generate-new-buffer-name "untitled")))
|
2017-04-13 21:58:20 +00:00
|
|
|
|
(case split
|
|
|
|
|
('left (split-window-horizontally))
|
|
|
|
|
('below (spacemacs/split-window-vertically-and-switch))
|
|
|
|
|
('above (split-window-vertically))
|
|
|
|
|
('right (spacemacs/split-window-horizontally-and-switch)))
|
2017-04-18 19:10:33 +00:00
|
|
|
|
;; pass non-nil force-same-window to prevent `switch-to-buffer' from
|
|
|
|
|
;; displaying buffer in another window
|
|
|
|
|
(switch-to-buffer newbuf nil 'force-same-window)))
|
2015-09-10 11:26:57 +00:00
|
|
|
|
|
2017-04-13 21:58:20 +00:00
|
|
|
|
(defun spacemacs/new-empty-buffer-left ()
|
|
|
|
|
"Create a new buffer called untitled(<n>),
|
|
|
|
|
in a split window to the left."
|
|
|
|
|
(interactive)
|
|
|
|
|
(spacemacs/new-empty-buffer 'left))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/new-empty-buffer-below ()
|
|
|
|
|
"Create a new buffer called untitled(<n>),
|
|
|
|
|
in a split window below."
|
|
|
|
|
(interactive)
|
|
|
|
|
(spacemacs/new-empty-buffer 'below))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/new-empty-buffer-above ()
|
|
|
|
|
"Create a new buffer called untitled(<n>),
|
|
|
|
|
in a split window above."
|
|
|
|
|
(interactive)
|
|
|
|
|
(spacemacs/new-empty-buffer 'above))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/new-empty-buffer-right ()
|
|
|
|
|
"Create a new buffer called untitled(<n>),
|
|
|
|
|
in a split window to the right."
|
|
|
|
|
(interactive)
|
|
|
|
|
(spacemacs/new-empty-buffer 'right))
|
|
|
|
|
|
2015-10-08 21:52:49 +00:00
|
|
|
|
;; from https://gist.github.com/timcharper/493269
|
|
|
|
|
(defun spacemacs/split-window-vertically-and-switch ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(split-window-vertically)
|
|
|
|
|
(other-window 1))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/split-window-horizontally-and-switch ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(split-window-horizontally)
|
|
|
|
|
(other-window 1))
|
|
|
|
|
|
2015-09-11 04:05:08 +00:00
|
|
|
|
(defun spacemacs/layout-triple-columns ()
|
|
|
|
|
" Set the layout to triple columns. "
|
|
|
|
|
(interactive)
|
|
|
|
|
(delete-other-windows)
|
|
|
|
|
(dotimes (i 2) (split-window-right))
|
|
|
|
|
(balance-windows))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/layout-double-columns ()
|
|
|
|
|
" Set the layout to double columns. "
|
|
|
|
|
(interactive)
|
|
|
|
|
(delete-other-windows)
|
|
|
|
|
(split-window-right))
|
|
|
|
|
|
2015-05-15 21:28:47 +00:00
|
|
|
|
(defun spacemacs/insert-line-above-no-indent (count)
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
"Insert a new line above with no indentation."
|
2015-05-15 21:28:47 +00:00
|
|
|
|
(interactive "p")
|
2015-07-04 12:10:00 +00:00
|
|
|
|
(let ((p (+ (point) count)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if (eq (line-number-at-pos) 1)
|
|
|
|
|
(evil-move-beginning-of-line)
|
|
|
|
|
(progn
|
|
|
|
|
(evil-previous-line)
|
|
|
|
|
(evil-move-end-of-line)))
|
|
|
|
|
(while (> count 0)
|
|
|
|
|
(insert "\n")
|
|
|
|
|
(setq count (1- count))))
|
|
|
|
|
(goto-char p)))
|
2015-05-15 21:28:47 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/insert-line-below-no-indent (count)
|
Comment corrections and two functions reordered
Misspellings:
"beginnign" changed to "beginning",
"Insert one of several lines" changed to "Insert one or several lines" in two functions,
"identation" changed to "indentation",
Missing comment copied from the function that inserts a line
in the opposite direction:
(defun spacemacs/insert-line-below-no-indent (count)
"Insert a new line below with no indentation."
and renamed the direction, resulting in:
"Insert a new line above with no indentation."
Duplicate comments removed, the comments inside the functions,
are better explanations of what the function does.
Functions reordered:
The functions:
(defun spacemacs/evil-insert-line-below (count)
and
(defun spacemacs/evil-insert-line-above (count)
were written in a illogical order,
the "above" function should be written before the "below" function,
with this change, the function order will match other functions
with "above" and "below" in their names,
for example these:
(defun spacemacs/insert-line-above-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L535
(defun spacemacs/insert-line-below-no-indent (count)
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-base/funcs.el#L549
evil-commands.el
line 2205: (defun evil-open-above (count)
line 2219: (defun evil-open-below (count)
line 2310: (defun evil-copy-from-above (arg)
line 2326: (defun evil-copy-from-below (arg)
evil-common.el
line 1892: (defun evil-insert-newline-above ()
line 1901: (defun evil-insert-newline-below ()
2016-07-31 09:47:27 +00:00
|
|
|
|
"Insert a new line below with no indentation."
|
2015-05-15 21:28:47 +00:00
|
|
|
|
(interactive "p")
|
|
|
|
|
(save-excursion
|
|
|
|
|
(evil-move-end-of-line)
|
|
|
|
|
(while (> count 0)
|
|
|
|
|
(insert "\n")
|
|
|
|
|
(setq count (1- count)))))
|
|
|
|
|
|
2016-11-23 12:49:56 +00:00
|
|
|
|
;; see https://github.com/gempesaw/dotemacs/blob/emacs/dg-elisp/dg-defun.el
|
|
|
|
|
(defun spacemacs/rudekill-matching-buffers (regexp &optional internal-too)
|
|
|
|
|
"Kill - WITHOUT ASKING - buffers whose name matches the specified REGEXP. See
|
|
|
|
|
the `kill-matching-buffers` for grateful killing. The optional 2nd argument
|
|
|
|
|
indicates whether to kill internal buffers too.
|
|
|
|
|
|
|
|
|
|
Returns the count of killed buffers."
|
|
|
|
|
(let* ((buffers (remove-if-not
|
|
|
|
|
(lambda (buffer)
|
|
|
|
|
(let ((name (buffer-name buffer)))
|
|
|
|
|
(and name (not (string-equal name ""))
|
|
|
|
|
(or internal-too (/= (aref name 0) ?\s))
|
|
|
|
|
(string-match regexp name))))
|
|
|
|
|
(buffer-list))))
|
|
|
|
|
(mapc 'kill-buffer buffers)
|
|
|
|
|
(length buffers)))
|
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/kill-matching-buffers-rudely (regexp &optional internal-too)
|
2016-11-23 12:49:56 +00:00
|
|
|
|
"Kill - WITHOUT ASKING - buffers whose name matches the specified REGEXP. See
|
|
|
|
|
the `kill-matching-buffers` for grateful killing. The optional 2nd argument
|
|
|
|
|
indicates whether to kill internal buffers too.
|
|
|
|
|
|
|
|
|
|
Returns a message with the count of killed buffers."
|
2014-03-06 16:24:09 +00:00
|
|
|
|
(interactive "sKill buffers matching this regular expression: \nP")
|
2016-11-23 12:49:56 +00:00
|
|
|
|
(message
|
|
|
|
|
(format "%d buffer(s) killed."
|
|
|
|
|
(spacemacs/rudekill-matching-buffers regexp internal-too))))
|
2014-05-01 01:41:26 +00:00
|
|
|
|
|
2014-12-12 22:59:49 +00:00
|
|
|
|
;; advise to prevent server from closing
|
|
|
|
|
|
|
|
|
|
(defvar spacemacs-really-kill-emacs nil
|
|
|
|
|
"prevent window manager close from closing instance.")
|
|
|
|
|
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(defun spacemacs//persistent-server-running-p ()
|
2015-03-30 01:41:09 +00:00
|
|
|
|
"Requires spacemacs-really-kill-emacs to be toggled and
|
|
|
|
|
dotspacemacs-persistent-server to be t"
|
|
|
|
|
(and (fboundp 'server-running-p)
|
|
|
|
|
(server-running-p)
|
|
|
|
|
dotspacemacs-persistent-server))
|
2015-03-26 06:05:40 +00:00
|
|
|
|
|
2014-12-12 22:59:49 +00:00
|
|
|
|
(defadvice kill-emacs (around spacemacs-really-exit activate)
|
|
|
|
|
"Only kill emacs if a prefix is set"
|
2015-03-30 01:41:09 +00:00
|
|
|
|
(if (and (not spacemacs-really-kill-emacs)
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(spacemacs//persistent-server-running-p))
|
2015-03-26 06:05:40 +00:00
|
|
|
|
(spacemacs/frame-killer)
|
2015-03-30 01:41:09 +00:00
|
|
|
|
ad-do-it))
|
2014-12-12 22:59:49 +00:00
|
|
|
|
|
|
|
|
|
(defadvice save-buffers-kill-emacs (around spacemacs-really-exit activate)
|
|
|
|
|
"Only kill emacs if a prefix is set"
|
|
|
|
|
(if (or spacemacs-really-kill-emacs (not dotspacemacs-persistent-server))
|
2015-01-27 04:38:35 +00:00
|
|
|
|
ad-do-it
|
|
|
|
|
(spacemacs/frame-killer)))
|
2014-12-12 22:59:49 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/save-buffers-kill-emacs ()
|
2015-01-29 16:19:55 +00:00
|
|
|
|
"Save all changed buffers and exit Spacemacs"
|
2014-12-12 22:59:49 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq spacemacs-really-kill-emacs t)
|
|
|
|
|
(save-buffers-kill-emacs))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/kill-emacs ()
|
2015-01-29 16:19:55 +00:00
|
|
|
|
"Lose all changes and exit Spacemacs"
|
2014-12-12 22:59:49 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq spacemacs-really-kill-emacs t)
|
|
|
|
|
(kill-emacs))
|
|
|
|
|
|
2015-01-29 16:19:55 +00:00
|
|
|
|
(defun spacemacs/prompt-kill-emacs ()
|
|
|
|
|
"Prompt to save changed buffers and exit Spacemacs"
|
|
|
|
|
(interactive)
|
|
|
|
|
(setq spacemacs-really-kill-emacs t)
|
|
|
|
|
(save-some-buffers)
|
|
|
|
|
(kill-emacs))
|
|
|
|
|
|
2014-12-12 22:59:49 +00:00
|
|
|
|
(defun spacemacs/frame-killer ()
|
2015-01-29 16:19:55 +00:00
|
|
|
|
"Kill server buffer and hide the main Emacs window"
|
2014-12-12 22:59:49 +00:00
|
|
|
|
(interactive)
|
2016-02-24 15:32:45 +00:00
|
|
|
|
(condition-case-unless-debug nil
|
2015-09-08 19:06:57 +00:00
|
|
|
|
(delete-frame nil 1)
|
|
|
|
|
(error
|
|
|
|
|
(make-frame-invisible nil 1))))
|
2014-12-12 22:59:49 +00:00
|
|
|
|
|
2015-01-12 17:22:17 +00:00
|
|
|
|
(defun spacemacs/toggle-frame-fullscreen ()
|
|
|
|
|
"Respect the `dotspacemacs-fullscreen-use-non-native' variable when
|
|
|
|
|
toggling fullscreen."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if dotspacemacs-fullscreen-use-non-native
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(spacemacs/toggle-frame-fullscreen-non-native)
|
2015-01-12 17:22:17 +00:00
|
|
|
|
(toggle-frame-fullscreen)))
|
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/toggle-fullscreen ()
|
2014-07-11 04:14:30 +00:00
|
|
|
|
"Toggle full screen on X11 and Carbon"
|
2014-07-11 03:31:02 +00:00
|
|
|
|
(interactive)
|
2014-07-11 04:14:30 +00:00
|
|
|
|
(cond
|
|
|
|
|
((eq window-system 'x)
|
|
|
|
|
(set-frame-parameter nil 'fullscreen
|
|
|
|
|
(when (not (frame-parameter nil 'fullscreen))
|
|
|
|
|
'fullboth)))
|
|
|
|
|
((eq window-system 'mac)
|
2014-07-11 03:52:39 +00:00
|
|
|
|
(set-frame-parameter
|
|
|
|
|
nil 'fullscreen
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(when (not (frame-parameter nil 'fullscreen)) 'fullscreen)))))
|
2014-09-28 21:56:12 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/toggle-frame-fullscreen-non-native ()
|
2015-01-12 17:22:17 +00:00
|
|
|
|
"Toggle full screen non-natively. Uses the `fullboth' frame paramerter
|
|
|
|
|
rather than `fullscreen'. Useful to fullscreen on OSX w/o animations."
|
|
|
|
|
(interactive)
|
|
|
|
|
(modify-frame-parameters
|
|
|
|
|
nil
|
|
|
|
|
`((maximized
|
|
|
|
|
. ,(unless (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
|
|
|
|
|
(frame-parameter nil 'fullscreen)))
|
|
|
|
|
(fullscreen
|
|
|
|
|
. ,(if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
|
|
|
|
|
(if (eq (frame-parameter nil 'maximized) 'maximized)
|
|
|
|
|
'maximized)
|
|
|
|
|
'fullboth)))))
|
|
|
|
|
|
2015-05-04 12:28:59 +00:00
|
|
|
|
;; taken from Prelude: https://github.com/bbatsov/prelude
|
|
|
|
|
(defmacro spacemacs|advise-commands (advice-name commands class &rest body)
|
|
|
|
|
"Apply advice named ADVICE-NAME to multiple COMMANDS.
|
|
|
|
|
The body of the advice is in BODY."
|
|
|
|
|
`(progn
|
|
|
|
|
,@(mapcar (lambda (command)
|
2015-05-11 03:31:36 +00:00
|
|
|
|
`(defadvice ,command
|
2015-05-11 03:42:11 +00:00
|
|
|
|
(,class ,(intern (format "%S-%s" command advice-name))
|
2015-05-11 03:31:36 +00:00
|
|
|
|
activate)
|
2015-05-04 12:28:59 +00:00
|
|
|
|
,@body))
|
|
|
|
|
commands)))
|
|
|
|
|
|
2014-11-23 05:38:56 +00:00
|
|
|
|
(defun spacemacs/safe-revert-buffer ()
|
|
|
|
|
"Prompt before reverting the file."
|
|
|
|
|
(interactive)
|
|
|
|
|
(revert-buffer nil nil))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/safe-erase-buffer ()
|
|
|
|
|
"Prompt before erasing the content of the file."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if (y-or-n-p (format "Erase content of buffer %s ? " (current-buffer)))
|
|
|
|
|
(erase-buffer)))
|
2014-11-23 15:23:40 +00:00
|
|
|
|
|
2016-10-04 05:24:52 +00:00
|
|
|
|
(defun spacemacs//find-ert-test-buffer (ert-test)
|
|
|
|
|
"Return the buffer where ERT-TEST is defined."
|
|
|
|
|
(car (find-definition-noselect (ert-test-name ert-test) 'ert-deftest)))
|
|
|
|
|
|
2014-11-23 15:23:40 +00:00
|
|
|
|
(defun spacemacs/ert-run-tests-buffer ()
|
|
|
|
|
"Run all the tests in the current buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-buffer)
|
|
|
|
|
(load-file (buffer-file-name))
|
2016-10-04 05:24:52 +00:00
|
|
|
|
(let ((cbuf (current-buffer)))
|
|
|
|
|
(ert '(satisfies (lambda (test)
|
|
|
|
|
(eq cbuf (spacemacs//find-ert-test-buffer test)))))))
|
2014-11-24 04:10:04 +00:00
|
|
|
|
|
2016-08-06 16:14:30 +00:00
|
|
|
|
(defun spacemacs//open-in-external-app (file-path)
|
|
|
|
|
"Open `file-path' in external application."
|
|
|
|
|
(cond
|
|
|
|
|
((spacemacs/system-is-mswindows) (w32-shell-execute "open" (replace-regexp-in-string "/" "\\\\" file-path)))
|
|
|
|
|
((spacemacs/system-is-mac) (shell-command (format "open \"%s\"" file-path)))
|
|
|
|
|
((spacemacs/system-is-linux) (let ((process-connection-type nil))
|
|
|
|
|
(start-process "" nil "xdg-open" file-path)))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/open-file-or-directory-in-external-app (arg)
|
|
|
|
|
"Open current file in external application.
|
|
|
|
|
If the universal prefix argument is used then open the folder
|
|
|
|
|
containing the current file by the default explorer."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(if arg
|
|
|
|
|
(spacemacs//open-in-external-app (expand-file-name default-directory))
|
2016-08-17 18:33:56 +00:00
|
|
|
|
(let ((file-path (if (derived-mode-p 'dired-mode)
|
2016-08-06 16:14:30 +00:00
|
|
|
|
(dired-get-file-for-visit)
|
|
|
|
|
buffer-file-name)))
|
|
|
|
|
(if file-path
|
|
|
|
|
(spacemacs//open-in-external-app file-path)
|
|
|
|
|
(message "No file associated to this buffer.")))))
|
2015-02-10 00:44:52 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/switch-to-minibuffer-window ()
|
2015-02-14 22:59:47 +00:00
|
|
|
|
"switch to minibuffer window (if active)"
|
|
|
|
|
(interactive)
|
|
|
|
|
(when (active-minibuffer-window)
|
|
|
|
|
(select-window (active-minibuffer-window))))
|
2015-02-14 04:07:38 +00:00
|
|
|
|
|
2015-04-08 22:33:27 +00:00
|
|
|
|
;; http://stackoverflow.com/a/10216338/4869
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/copy-whole-buffer-to-clipboard ()
|
2015-04-08 22:33:27 +00:00
|
|
|
|
"Copy entire buffer to clipboard"
|
|
|
|
|
(interactive)
|
|
|
|
|
(clipboard-kill-ring-save (point-min) (point-max)))
|
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/copy-clipboard-to-whole-buffer ()
|
2015-04-08 22:33:27 +00:00
|
|
|
|
"Copy clipboard and replace buffer"
|
|
|
|
|
(interactive)
|
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
|
(clipboard-yank)
|
|
|
|
|
(deactivate-mark))
|
2015-05-04 12:28:59 +00:00
|
|
|
|
|
2015-07-05 04:12:59 +00:00
|
|
|
|
;; BEGIN align functions
|
|
|
|
|
|
2015-06-04 00:23:16 +00:00
|
|
|
|
;; modified function from http://emacswiki.org/emacs/AlignCommands
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/align-repeat (start end regexp &optional justify-right after)
|
2015-06-04 00:23:16 +00:00
|
|
|
|
"Repeat alignment with respect to the given regular expression.
|
|
|
|
|
If JUSTIFY-RIGHT is non nil justify to the right instead of the
|
|
|
|
|
left. If AFTER is non-nil, add whitespace to the left instead of
|
|
|
|
|
the right."
|
|
|
|
|
(interactive "r\nsAlign regexp: ")
|
2016-08-23 05:12:19 +00:00
|
|
|
|
(let* ((ws-regexp (if (string-empty-p regexp)
|
|
|
|
|
"\\(\\s-+\\)"
|
|
|
|
|
"\\(\\s-*\\)"))
|
|
|
|
|
(complete-regexp (if after
|
|
|
|
|
(concat regexp ws-regexp)
|
|
|
|
|
(concat ws-regexp regexp)))
|
|
|
|
|
(group (if justify-right -1 1)))
|
|
|
|
|
(message "%S" complete-regexp)
|
2015-06-04 00:23:16 +00:00
|
|
|
|
(align-regexp start end complete-regexp group 1 t)))
|
|
|
|
|
|
|
|
|
|
;; Modified answer from http://emacs.stackexchange.com/questions/47/align-vertical-columns-of-numbers-on-the-decimal-point
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defun spacemacs/align-repeat-decimal (start end)
|
2015-06-04 00:23:16 +00:00
|
|
|
|
"Align a table of numbers on decimal points and dollar signs (both optional)"
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(require 'align)
|
|
|
|
|
(align-region start end nil
|
|
|
|
|
'((nil (regexp . "\\([\t ]*\\)\\$?\\([\t ]+[0-9]+\\)\\.?")
|
|
|
|
|
(repeat . t)
|
|
|
|
|
(group 1 2)
|
|
|
|
|
(spacing 1 1)
|
|
|
|
|
(justify nil t)))
|
|
|
|
|
nil))
|
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(defmacro spacemacs|create-align-repeat-x (name regexp &optional justify-right default-after)
|
|
|
|
|
(let ((new-func (intern (concat "spacemacs/align-repeat-" name))))
|
2015-06-04 00:23:16 +00:00
|
|
|
|
`(defun ,new-func (start end switch)
|
|
|
|
|
(interactive "r\nP")
|
|
|
|
|
(let ((after (not (eq (if switch t nil) (if ,default-after t nil)))))
|
2015-09-03 20:21:37 +00:00
|
|
|
|
(spacemacs/align-repeat start end ,regexp ,justify-right after)))))
|
2015-06-04 00:23:16 +00:00
|
|
|
|
|
2015-08-23 01:47:30 +00:00
|
|
|
|
(spacemacs|create-align-repeat-x "comma" "," nil t)
|
|
|
|
|
(spacemacs|create-align-repeat-x "semicolon" ";" nil t)
|
|
|
|
|
(spacemacs|create-align-repeat-x "colon" ":" nil t)
|
|
|
|
|
(spacemacs|create-align-repeat-x "equal" "=")
|
|
|
|
|
(spacemacs|create-align-repeat-x "math-oper" "[+\\-*/]")
|
|
|
|
|
(spacemacs|create-align-repeat-x "ampersand" "&")
|
|
|
|
|
(spacemacs|create-align-repeat-x "bar" "|")
|
|
|
|
|
(spacemacs|create-align-repeat-x "left-paren" "(")
|
|
|
|
|
(spacemacs|create-align-repeat-x "right-paren" ")" t)
|
2017-01-06 17:52:17 +00:00
|
|
|
|
(spacemacs|create-align-repeat-x "left-curly-brace" "{")
|
|
|
|
|
(spacemacs|create-align-repeat-x "right-curly-brace" "}" t)
|
|
|
|
|
(spacemacs|create-align-repeat-x "left-square-brace" "\\[")
|
|
|
|
|
(spacemacs|create-align-repeat-x "right-square-brace" "\\]" t)
|
2016-02-25 19:16:34 +00:00
|
|
|
|
(spacemacs|create-align-repeat-x "backslash" "\\\\")
|
2015-07-05 04:12:59 +00:00
|
|
|
|
|
|
|
|
|
;; END align functions
|
|
|
|
|
|
2015-08-28 06:13:40 +00:00
|
|
|
|
(defun spacemacs/dos2unix ()
|
|
|
|
|
"Converts the current buffer to UNIX file format."
|
|
|
|
|
(interactive)
|
|
|
|
|
(set-buffer-file-coding-system 'undecided-unix nil))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/unix2dos ()
|
|
|
|
|
"Converts the current buffer to DOS file format."
|
|
|
|
|
(interactive)
|
|
|
|
|
(set-buffer-file-coding-system 'undecided-dos nil))
|
|
|
|
|
|
2015-07-05 04:12:59 +00:00
|
|
|
|
(defun spacemacs/copy-file ()
|
|
|
|
|
"Write the file under new name."
|
|
|
|
|
(interactive)
|
|
|
|
|
(call-interactively 'write-file))
|
2015-07-06 10:13:41 +00:00
|
|
|
|
|
2016-07-07 22:35:43 +00:00
|
|
|
|
;; from https://www.emacswiki.org/emacs/CopyingWholeLines
|
|
|
|
|
(defun spacemacs/duplicate-line-or-region (&optional n)
|
|
|
|
|
"Duplicate current line, or region if active.
|
|
|
|
|
With argument N, make N copies.
|
|
|
|
|
With negative N, comment out original line and use the absolute value."
|
|
|
|
|
(interactive "*p")
|
|
|
|
|
(let ((use-region (use-region-p)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((text (if use-region ; Get region if active, otherwise line
|
|
|
|
|
(buffer-substring (region-beginning) (region-end))
|
|
|
|
|
(prog1 (thing-at-point 'line)
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(if (< 0 (forward-line 1)) ; Go to beginning of next line, or make a new one
|
|
|
|
|
(newline))))))
|
|
|
|
|
(dotimes (i (abs (or n 1))) ; Insert N times, or once if not specified
|
|
|
|
|
(insert text))))
|
|
|
|
|
(if use-region nil ; Only if we're working with a line (not a region)
|
|
|
|
|
(let ((pos (- (point) (line-beginning-position)))) ; Save column
|
|
|
|
|
(if (> 0 n) ; Comment out original with negative arg
|
|
|
|
|
(comment-region (line-beginning-position) (line-end-position)))
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(forward-char pos)))))
|
|
|
|
|
|
2015-08-27 22:17:16 +00:00
|
|
|
|
(defun spacemacs/uniquify-lines ()
|
2016-12-24 15:24:51 +00:00
|
|
|
|
"Remove duplicate adjacent lines in a region or the current buffer"
|
2015-08-27 22:17:16 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
2016-12-24 15:24:51 +00:00
|
|
|
|
(let* ((region-active (or (region-active-p) (evil-visual-state-p)))
|
|
|
|
|
(beg (if region-active (region-beginning) (point-min)))
|
|
|
|
|
(end (if region-active (region-end) (point-max))))
|
2015-08-27 22:17:16 +00:00
|
|
|
|
(goto-char beg)
|
|
|
|
|
(while (re-search-forward "^\\(.*\n\\)\\1+" end t)
|
|
|
|
|
(replace-match "\\1"))))))
|
|
|
|
|
|
2016-12-24 11:06:21 +00:00
|
|
|
|
(defun spacemacs/sort-lines (&optional reverse)
|
|
|
|
|
"Sort lines in a region or the current buffer.
|
|
|
|
|
A non-nil argument sorts in reverse order."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(let* ((region-active (or (region-active-p) (evil-visual-state-p)))
|
|
|
|
|
(beg (if region-active (region-beginning) (point-min)))
|
|
|
|
|
(end (if region-active (region-end) (point-max))))
|
|
|
|
|
(sort-lines reverse beg end)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/sort-lines-reverse ()
|
|
|
|
|
"Sort lines in reverse order, in a region or the current buffer."
|
2015-08-27 22:17:16 +00:00
|
|
|
|
(interactive)
|
2016-12-24 11:06:21 +00:00
|
|
|
|
(spacemacs/sort-lines -1))
|
2016-12-24 15:01:41 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/sort-lines-by-column (&optional reverse)
|
2017-03-10 20:00:20 +00:00
|
|
|
|
"Sort lines by the selected column,
|
|
|
|
|
using a visual block/rectangle selection.
|
|
|
|
|
A non-nil argument sorts in REVERSE order."
|
2016-12-24 15:01:41 +00:00
|
|
|
|
(interactive "P")
|
2017-03-10 20:00:20 +00:00
|
|
|
|
(if (and
|
|
|
|
|
;; is there an active selection
|
|
|
|
|
(or (region-active-p) (evil-visual-state-p))
|
|
|
|
|
;; is it a block or rectangle selection
|
|
|
|
|
(or (eq evil-visual-selection 'block) (eq rectangle-mark-mode t))
|
|
|
|
|
;; is the selection height 2 or more lines
|
|
|
|
|
(>= (1+ (- (line-number-at-pos (region-end))
|
|
|
|
|
(line-number-at-pos (region-beginning)))) 2))
|
|
|
|
|
(sort-columns reverse (region-beginning) (region-end))
|
|
|
|
|
(error "Sorting by column requires a block/rect selection on 2 or more lines.")))
|
2016-12-24 15:01:41 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/sort-lines-by-column-reverse ()
|
2017-03-10 20:00:20 +00:00
|
|
|
|
"Sort lines by the selected column in reverse order,
|
|
|
|
|
using a visual block/rectangle selection."
|
2016-12-24 15:01:41 +00:00
|
|
|
|
(interactive)
|
2017-01-14 20:15:11 +00:00
|
|
|
|
(spacemacs/sort-lines-by-column -1))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
|
|
|
|
|
;; BEGIN linum mouse helpers
|
|
|
|
|
|
|
|
|
|
(defvar spacemacs-linum-mdown-line nil
|
|
|
|
|
"Define persistent variable for linum selection")
|
|
|
|
|
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(defun spacemacs//line-at-click ()
|
2015-09-08 01:16:15 +00:00
|
|
|
|
"Determine the visual line at click"
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((click-y (cddr (mouse-position)))
|
|
|
|
|
(debug-on-error t)
|
|
|
|
|
(line-move-visual t))
|
|
|
|
|
(goto-char (window-start))
|
|
|
|
|
(next-line (1- click-y))
|
|
|
|
|
(1+ (line-number-at-pos))
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/md-select-linum (event)
|
|
|
|
|
"Set point as spacemacs-linum-mdown-line"
|
|
|
|
|
(interactive "e")
|
|
|
|
|
(mouse-select-window event)
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(goto-line (spacemacs//line-at-click))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(set-mark (point))
|
|
|
|
|
(setq spacemacs-linum-mdown-line
|
|
|
|
|
(line-number-at-pos)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/mu-select-linum ()
|
|
|
|
|
"Select code block between point and spacemacs-linum-mdown-line"
|
|
|
|
|
(interactive)
|
|
|
|
|
(when spacemacs-linum-mdown-line
|
|
|
|
|
(let (mu-line)
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(setq mu-line (spacemacs//line-at-click))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(goto-line (max spacemacs-linum-mdown-line mu-line))
|
|
|
|
|
(set-mark (line-end-position))
|
|
|
|
|
(goto-line (min spacemacs-linum-mdown-line mu-line))
|
|
|
|
|
(setq spacemacs-linum-mdown-line nil))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/select-current-block ()
|
|
|
|
|
"Select the current block of text between blank lines."
|
|
|
|
|
(interactive)
|
2016-12-22 13:40:07 +00:00
|
|
|
|
(let (p1)
|
|
|
|
|
(when (re-search-backward "\n[ \t]*\n" nil "move")
|
|
|
|
|
(re-search-forward "\n[ \t]*\n"))
|
|
|
|
|
(setq p1 (point))
|
|
|
|
|
(if (re-search-forward "\n[ \t]*\n" nil "move")
|
|
|
|
|
(re-search-backward "\n[ \t]*\n"))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(set-mark p1)))
|
|
|
|
|
|
|
|
|
|
;; END linum mouse helpers
|
|
|
|
|
|
|
|
|
|
;; From http://xugx2007.blogspot.ca/2007/06/benjamin-rutts-emacs-c-development-tips.html
|
|
|
|
|
(setq compilation-finish-function
|
|
|
|
|
(lambda (buf str)
|
|
|
|
|
|
|
|
|
|
(if (or (string-match "exited abnormally" str)
|
|
|
|
|
(string-match "FAILED" (buffer-string)))
|
|
|
|
|
|
|
|
|
|
;; there were errors
|
|
|
|
|
(message "There were errors. SPC-e-n to visit.")
|
|
|
|
|
(unless (or (string-match "Grep finished" (buffer-string))
|
|
|
|
|
(string-match "Ag finished" (buffer-string))
|
|
|
|
|
(string-match "nosetests" (buffer-name)))
|
|
|
|
|
|
|
|
|
|
;; no errors
|
|
|
|
|
(message "compilation ok.")))))
|
|
|
|
|
|
|
|
|
|
;; from http://www.emacswiki.org/emacs/WordCount
|
|
|
|
|
(defun spacemacs/count-words-analysis (start end)
|
|
|
|
|
"Count how many times each word is used in the region.
|
|
|
|
|
Punctuation is ignored."
|
|
|
|
|
(interactive "r")
|
2017-01-19 22:16:56 +00:00
|
|
|
|
(let (words
|
|
|
|
|
alist_words_compare
|
|
|
|
|
(formated "")
|
|
|
|
|
(overview (call-interactively 'count-words)))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(while (re-search-forward "\\w+" end t)
|
|
|
|
|
(let* ((word (intern (match-string 0)))
|
|
|
|
|
(cell (assq word words)))
|
|
|
|
|
(if cell
|
|
|
|
|
(setcdr cell (1+ (cdr cell)))
|
|
|
|
|
(setq words (cons (cons word 1) words))))))
|
2015-09-28 21:28:19 +00:00
|
|
|
|
(defun alist_words_compare (a b)
|
|
|
|
|
"Compare elements from an associative list of words count.
|
|
|
|
|
Compare them on count first,and in case of tie sort them alphabetically."
|
|
|
|
|
(let ((a_key (car a))
|
|
|
|
|
(a_val (cdr a))
|
|
|
|
|
(b_key (car b))
|
|
|
|
|
(b_val (cdr b)))
|
|
|
|
|
(if (eq a_val b_val)
|
|
|
|
|
(string-lessp a_key b_key)
|
|
|
|
|
(> a_val b_val))))
|
|
|
|
|
(setq words (cl-sort words 'alist_words_compare))
|
|
|
|
|
(while words
|
|
|
|
|
(let* ((word (pop words))
|
|
|
|
|
(name (car word))
|
|
|
|
|
(count (cdr word)))
|
|
|
|
|
(setq formated (concat formated (format "[%s: %d], " name count)))))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(when (interactive-p)
|
2015-09-28 21:28:19 +00:00
|
|
|
|
(if (> (length formated) 2)
|
2017-01-19 22:16:56 +00:00
|
|
|
|
(message (format "%s\nWord count: %s"
|
|
|
|
|
overview
|
|
|
|
|
(substring formated 0 -2)))
|
2015-09-28 21:28:19 +00:00
|
|
|
|
(message "No words.")))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
words))
|
|
|
|
|
|
|
|
|
|
;; indent on paste
|
|
|
|
|
;; from Prelude: https://github.com/bbatsov/prelude
|
|
|
|
|
(defun spacemacs/yank-advised-indent-function (beg end)
|
|
|
|
|
"Do indentation, as long as the region isn't too large."
|
|
|
|
|
(if (<= (- end beg) spacemacs-yank-indent-threshold)
|
|
|
|
|
(indent-region beg end nil)))
|
|
|
|
|
|
|
|
|
|
(spacemacs|advise-commands
|
2015-09-12 01:01:11 +00:00
|
|
|
|
"indent" (yank yank-pop evil-paste-before evil-paste-after) around
|
2015-09-08 01:16:15 +00:00
|
|
|
|
"If current mode is not one of spacemacs-indent-sensitive-modes
|
|
|
|
|
indent yanked text (with universal arg don't indent)."
|
2015-09-12 01:01:11 +00:00
|
|
|
|
(evil-start-undo-step)
|
|
|
|
|
ad-do-it
|
2015-09-08 01:16:15 +00:00
|
|
|
|
(if (and (not (equal '(4) (ad-get-arg 0)))
|
|
|
|
|
(not (member major-mode spacemacs-indent-sensitive-modes))
|
|
|
|
|
(or (derived-mode-p 'prog-mode)
|
|
|
|
|
(member major-mode spacemacs-indent-sensitive-modes)))
|
2015-09-12 01:01:11 +00:00
|
|
|
|
(let ((transient-mark-mode nil)
|
|
|
|
|
(save-undo buffer-undo-list))
|
|
|
|
|
(spacemacs/yank-advised-indent-function (region-beginning)
|
|
|
|
|
(region-end))))
|
|
|
|
|
(evil-end-undo-step))
|
2015-09-08 01:16:15 +00:00
|
|
|
|
|
2016-05-18 00:08:08 +00:00
|
|
|
|
;; find file functions in split
|
|
|
|
|
(defun spacemacs//display-in-split (buffer alist)
|
|
|
|
|
"Split selected window and display BUFFER in the new window.
|
|
|
|
|
BUFFER and ALIST have the same form as in `display-buffer'. If ALIST contains
|
|
|
|
|
a split-side entry, its value must be usable as the SIDE argument for
|
|
|
|
|
`split-window'."
|
|
|
|
|
(let ((window (split-window nil nil (cdr (assq 'split-side alist)))))
|
|
|
|
|
(window--display-buffer buffer window 'window alist)
|
|
|
|
|
window))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/find-file-vsplit (file)
|
|
|
|
|
"find file in vertical split"
|
|
|
|
|
(interactive "FFind file (vsplit): ")
|
|
|
|
|
(let ((buffer (find-file-noselect file)))
|
|
|
|
|
(pop-to-buffer buffer '(spacemacs//display-in-split (split-side . right)))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/find-file-split (file)
|
2016-09-04 23:54:39 +00:00
|
|
|
|
"find file in horizontal split"
|
2016-05-18 00:08:08 +00:00
|
|
|
|
(interactive "FFind file (split): ")
|
|
|
|
|
(let ((buffer (find-file-noselect file)))
|
|
|
|
|
(pop-to-buffer buffer '(spacemacs//display-in-split (split-side . below)))))
|
|
|
|
|
|
2016-12-10 19:33:20 +00:00
|
|
|
|
(defun spacemacs/switch-to-scratch-buffer (&optional arg)
|
2016-12-26 15:30:57 +00:00
|
|
|
|
"Switch to the `*scratch*' buffer, creating it first if needed.
|
|
|
|
|
if prefix argument ARG is given, switch to it in an other, possibly new window."
|
2016-12-10 19:33:20 +00:00
|
|
|
|
(interactive "P")
|
2016-02-10 19:28:03 +00:00
|
|
|
|
(let ((exists (get-buffer "*scratch*")))
|
2016-12-10 19:33:20 +00:00
|
|
|
|
(if arg
|
|
|
|
|
(switch-to-buffer-other-window (get-buffer-create "*scratch*"))
|
|
|
|
|
(switch-to-buffer (get-buffer-create "*scratch*")))
|
2016-02-10 19:28:03 +00:00
|
|
|
|
(when (and (not exists)
|
|
|
|
|
(not (eq major-mode dotspacemacs-scratch-mode))
|
|
|
|
|
(fboundp dotspacemacs-scratch-mode))
|
|
|
|
|
(funcall dotspacemacs-scratch-mode))))
|
2015-11-09 04:51:29 +00:00
|
|
|
|
|
2016-12-26 15:30:57 +00:00
|
|
|
|
(defun spacemacs/switch-to-messages-buffer (&optional arg)
|
|
|
|
|
"Switch to the `*Messages*' buffer.
|
|
|
|
|
if prefix argument ARG is given, switch to it in an other, possibly new window."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(with-current-buffer (messages-buffer)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(if arg
|
|
|
|
|
(switch-to-buffer-other-window (current-buffer))
|
|
|
|
|
(switch-to-buffer (current-buffer)))))
|
|
|
|
|
|
2015-11-12 10:45:53 +00:00
|
|
|
|
(defun spacemacs/close-compilation-window ()
|
|
|
|
|
"Close the window containing the '*compilation*' buffer."
|
|
|
|
|
(interactive)
|
2016-03-13 16:19:21 +00:00
|
|
|
|
(when compilation-last-buffer
|
|
|
|
|
(delete-windows-on compilation-last-buffer)))
|
2016-06-04 02:15:29 +00:00
|
|
|
|
|
2017-02-05 18:50:50 +00:00
|
|
|
|
|
|
|
|
|
;; Line number
|
|
|
|
|
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(defun spacemacs/no-linum (&rest ignore)
|
2016-06-04 02:15:29 +00:00
|
|
|
|
"Disable linum if current buffer."
|
|
|
|
|
(when (or 'linum-mode global-linum-mode)
|
|
|
|
|
(linum-mode 0)))
|
2016-06-08 09:27:24 +00:00
|
|
|
|
|
2017-02-05 18:50:50 +00:00
|
|
|
|
(defun spacemacs/enable-line-numbers-p ()
|
|
|
|
|
"Return non-nil if line numbers should be enabled for current buffer.
|
|
|
|
|
Decision is based on `dotspacemacs-line-numbers'."
|
|
|
|
|
(and dotspacemacs-line-numbers
|
|
|
|
|
(spacemacs//linum-current-buffer-is-not-special)
|
2017-02-06 04:49:17 +00:00
|
|
|
|
(spacemacs//linum-curent-buffer-is-not-too-big)
|
2017-02-05 18:50:50 +00:00
|
|
|
|
(or (spacemacs//linum-backward-compabitility)
|
2017-03-09 14:30:44 +00:00
|
|
|
|
(spacemacs//linum-enabled-for-current-major-mode))))
|
2017-02-05 18:50:50 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//linum-on (origfunc &rest args)
|
|
|
|
|
"Advice function to improve `linum-on' function."
|
|
|
|
|
(when (spacemacs/enable-line-numbers-p)
|
|
|
|
|
(apply origfunc args)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//linum-update-window-scale-fix (win)
|
2016-10-03 18:06:45 +00:00
|
|
|
|
"Fix linum for scaled text in the window WIN."
|
|
|
|
|
(set-window-margins win
|
|
|
|
|
(ceiling (* (if (boundp 'text-scale-mode-step)
|
|
|
|
|
(expt text-scale-mode-step
|
|
|
|
|
text-scale-mode-amount) 1)
|
|
|
|
|
(if (car (window-margins))
|
|
|
|
|
(car (window-margins)) 1)))))
|
2016-11-04 18:33:40 +00:00
|
|
|
|
|
2017-02-05 18:50:50 +00:00
|
|
|
|
(defun spacemacs//linum-backward-compabitility ()
|
|
|
|
|
"Return non-nil if `dotspacemacs-line-numbers' has an old format and if
|
|
|
|
|
`linum' should be enabled."
|
|
|
|
|
(and dotspacemacs-line-numbers
|
|
|
|
|
(not (listp dotspacemacs-line-numbers))
|
|
|
|
|
(or (eq dotspacemacs-line-numbers t)
|
|
|
|
|
(eq dotspacemacs-line-numbers 'relative))))
|
|
|
|
|
|
2017-02-05 18:10:30 +00:00
|
|
|
|
(defun spacemacs//linum-current-buffer-is-not-special ()
|
|
|
|
|
"Return non-nil if current buffer is not a special buffer."
|
|
|
|
|
(not (string-match-p "\\*.*\\*" (buffer-name))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//linum-curent-buffer-is-not-too-big ()
|
|
|
|
|
"Return non-nil if buffer size is not too big."
|
2017-02-06 13:54:48 +00:00
|
|
|
|
(not (and (listp dotspacemacs-line-numbers)
|
|
|
|
|
(spacemacs/mplist-get dotspacemacs-line-numbers :size-limit-kb)
|
2017-02-05 18:10:30 +00:00
|
|
|
|
(> (buffer-size)
|
|
|
|
|
(* 1000 (car (spacemacs/mplist-get dotspacemacs-line-numbers
|
|
|
|
|
:size-limit-kb)))))))
|
|
|
|
|
|
2017-03-09 14:30:44 +00:00
|
|
|
|
;; mode in :enabled, not in :disabled ==> t
|
|
|
|
|
;; mode not in :enabled, in :disabled ==> nil
|
|
|
|
|
;; mode in :enabled, parent in :disabled ==> t
|
|
|
|
|
;; parent in :enabled, mode in :disabled ==> nil
|
|
|
|
|
;; not in :enabled, not in :disabled, :enabled is empty ==> t
|
|
|
|
|
;; not in :enabled, not in :disabled, :enabled is not empty ==> nil
|
|
|
|
|
;; both :enabled and :disabled are empty ==> t
|
2017-02-05 18:10:30 +00:00
|
|
|
|
(defun spacemacs//linum-enabled-for-current-major-mode ()
|
|
|
|
|
"Return non-nil if line number is enabled for current major-mode."
|
2017-03-09 14:30:44 +00:00
|
|
|
|
(let* ((enabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers
|
|
|
|
|
:enabled-for-modes))
|
|
|
|
|
(disabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers
|
|
|
|
|
:disabled-for-modes))
|
|
|
|
|
(enabled-for-parent (apply #'derived-mode-p enabled-for-modes))
|
|
|
|
|
(disabled-for-parent (apply #'derived-mode-p disabled-for-modes)))
|
|
|
|
|
(or
|
|
|
|
|
;; current mode or a parent is in :enabled-for-modes, and there isn't a
|
|
|
|
|
;; more specific parent (or the mode itself) in :disabled-for-modes
|
|
|
|
|
(and enabled-for-parent
|
|
|
|
|
;; handles the case where current major-mode has a parent both in
|
|
|
|
|
;; :enabled-for-modes and in :disabled-for-modes. Return non-nil if
|
|
|
|
|
;; enabled-for-parent is the more specific parent (IOW doesn't derive
|
|
|
|
|
;; from disabled-for-parent)
|
|
|
|
|
(not (spacemacs/derived-mode-p enabled-for-parent disabled-for-parent)))
|
|
|
|
|
;; current mode (or parent) not explicitly disabled, and :enabled-for-modes
|
|
|
|
|
;; not explicitly specified by user (meaning if it isn't explicitly
|
|
|
|
|
;; disabled then it's enabled)
|
|
|
|
|
(and (null enabled-for-modes) (not disabled-for-parent)))))
|