2015-01-14 04:12:56 +00:00
|
|
|
;;; funcs.el --- Spacemacs Layer functions File
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2014-11-08 00:24:10 +00:00
|
|
|
;; add emacs binary helper functions
|
2014-11-14 17:16:02 +00:00
|
|
|
(defun emacsbin-path()
|
|
|
|
(interactive)
|
|
|
|
(concat exec-directory (if (system-is-mswindows) "bin/") "emacs"))
|
|
|
|
|
|
|
|
(defun emacs()
|
|
|
|
(interactive)
|
|
|
|
(call-process (emacsbin-path) nil 0 nil)
|
2014-11-08 00:24:10 +00:00
|
|
|
(message "Started 'emacs' - it will be ready soon ..."))
|
|
|
|
|
2014-11-14 17:16:02 +00:00
|
|
|
(defun emacs-debug-init()
|
|
|
|
(interactive)
|
|
|
|
(call-process (emacsbin-path) nil 0 nil "--debug-init")
|
2014-11-08 00:24:10 +00:00
|
|
|
(message "Started 'emacs --debug-init' - it will be ready soon ..."))
|
|
|
|
|
|
|
|
(defun emacs-reload()
|
|
|
|
(interactive)
|
2014-11-14 17:16:02 +00:00
|
|
|
(load-file user-init-file)
|
2014-11-08 00:24:10 +00:00
|
|
|
(message ".emacs reloaded successfully"))
|
|
|
|
|
|
|
|
(defun emacs-Q() (interactive)
|
2014-11-14 17:16:02 +00:00
|
|
|
(call-process (emacsbin-path) nil 0 nil "-Q")
|
2014-11-08 00:24:10 +00:00
|
|
|
(message "Started 'emacs -Q' - it will be ready soon ..."))
|
|
|
|
|
2014-04-14 02:53:29 +00:00
|
|
|
;; from https://github.com/cofi/dotfiles/blob/master/emacs.d/config/cofi-util.el#L38
|
|
|
|
(defun add-to-hooks (fun hooks)
|
|
|
|
"Add function to hooks"
|
|
|
|
(dolist (hook hooks)
|
|
|
|
(add-hook hook fun)))
|
|
|
|
(defun add-all-to-hook (hook &rest funs)
|
|
|
|
"Add functions to hook."
|
|
|
|
(add-to-hook hook funs))
|
|
|
|
(defun add-to-hook (hook funs)
|
|
|
|
"Add list of functions to hook."
|
|
|
|
(dolist (fun funs)
|
|
|
|
(add-hook hook fun)))
|
|
|
|
|
2014-11-06 05:05:30 +00:00
|
|
|
(defun echo (msg &rest args)
|
|
|
|
"Display MSG in echo-area without logging it in *Messages* buffer."
|
|
|
|
(interactive)
|
|
|
|
(let ((message-log-max nil))
|
|
|
|
(apply 'message msg args)))
|
|
|
|
|
2014-08-11 21:53:02 +00:00
|
|
|
(defun system-is-mac ()
|
|
|
|
(string-equal system-type "darwin"))
|
|
|
|
(defun system-is-linux ()
|
|
|
|
(string-equal system-type "gnu/linux"))
|
2014-11-14 17:16:02 +00:00
|
|
|
(defun system-is-mswindows ()
|
|
|
|
(string-equal system-type "windows-nt"))
|
2014-08-11 21:53:02 +00:00
|
|
|
|
2014-12-01 02:05:39 +00:00
|
|
|
(defvar spacemacs/prefix-command-string "group:"
|
|
|
|
"Prefix string for prefix commands.")
|
|
|
|
|
|
|
|
(defun spacemacs/declare-prefix (prefix name)
|
|
|
|
"Declare a prefix PREFIX. PREFIX is a string describing
|
|
|
|
a key sequence. NAME is a symbol name used as the prefix command."
|
|
|
|
(let ((command (intern (concat spacemacs/prefix-command-string name))))
|
2015-03-02 04:52:07 +00:00
|
|
|
;; define the prefix command only if it does not already exist
|
|
|
|
(unless (lookup-key evil-leader--default-map prefix)
|
|
|
|
(define-prefix-command command)
|
|
|
|
(evil-leader/set-key prefix command))))
|
2014-12-01 02:05:39 +00:00
|
|
|
|
2014-12-09 03:53:47 +00:00
|
|
|
;; Waiting to fix the issue with guide-key before reactivating/updating this
|
|
|
|
;; function
|
|
|
|
;; (defun spacemacs/declare-prefix-for-mode (mode prefix name)
|
|
|
|
;; "Declare a prefix PREFIX. MODE is the mode in which this prefix command should
|
|
|
|
;; be added. PREFIX is a string describing a key sequence. NAME is a symbol name
|
|
|
|
;; used as the prefix command."
|
|
|
|
;; (let ((command (intern (concat spacemacs/prefix-command-string name))))
|
|
|
|
;; (define-prefix-command command)
|
|
|
|
;; (evil-leader/set-key-for-mode mode prefix command)))
|
2014-12-07 17:57:09 +00:00
|
|
|
|
2014-12-19 04:04:23 +00:00
|
|
|
(defun spacemacs/activate-major-mode-leader ()
|
|
|
|
"Bind major mode key map to `dotspacemacs-major-mode-leader-key'."
|
|
|
|
(setq mode-map (cdr (assoc major-mode evil-leader--mode-maps)))
|
|
|
|
(when mode-map
|
|
|
|
(setq major-mode-map (lookup-key mode-map (kbd "m")))
|
2015-03-19 09:12:46 +00:00
|
|
|
(mapc (lambda (s)
|
|
|
|
(eval `(define-key
|
|
|
|
,(intern (format "evil-%S-state-local-map" s))
|
|
|
|
,(kbd dotspacemacs-major-mode-leader-key)
|
|
|
|
major-mode-map)))
|
|
|
|
'(normal motion))
|
|
|
|
(mapc (lambda (s)
|
|
|
|
(eval `(define-key
|
|
|
|
,(intern (format "evil-%S-state-local-map" s))
|
|
|
|
,(kbd dotspacemacs-major-mode-emacs-leader-key)
|
|
|
|
major-mode-map)))
|
|
|
|
'(emacs insert normal motion visual))))
|
2014-12-19 04:04:23 +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 ()
|
|
|
|
"Push a mark at current location and go to the beginnign of the line."
|
|
|
|
(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))
|
|
|
|
|
2013-04-18 21:21:31 +00:00
|
|
|
;; insert one or several line below without changing current evil state
|
|
|
|
(defun evil-insert-line-below (count)
|
|
|
|
"Insert one of several lines below the current point's line without changing
|
|
|
|
the current state and point position."
|
|
|
|
(interactive "p")
|
|
|
|
(save-excursion
|
|
|
|
(evil-save-state (evil-open-below count))))
|
|
|
|
|
|
|
|
;; insert one or several line above without changing current evil state
|
|
|
|
(defun evil-insert-line-above (count)
|
|
|
|
"Insert one of several lines above the current point's line without changing
|
|
|
|
the current state and point position."
|
|
|
|
(interactive "p")
|
|
|
|
(save-excursion
|
|
|
|
(evil-save-state (evil-open-above count))))
|
|
|
|
|
2014-11-17 02:30:48 +00:00
|
|
|
(defun evil-goto-next-line-and-indent (&optional count)
|
|
|
|
(interactive "p")
|
|
|
|
(let ((counter (or count 1)))
|
|
|
|
(while (> counter 0)
|
|
|
|
(join-line 1)
|
|
|
|
(sp-newline)
|
|
|
|
(setq counter (1- counter)))))
|
|
|
|
|
2015-03-26 16:26:09 +00:00
|
|
|
;; from Prelude
|
|
|
|
(defvar spacemacs-indent-sensitive-modes
|
|
|
|
'(coffee-mode
|
|
|
|
python-mode
|
|
|
|
slim-mode
|
|
|
|
haml-mode
|
|
|
|
yaml-mode
|
|
|
|
makefile-mode
|
|
|
|
makefile-gmake-mode
|
|
|
|
makefile-imake-mode
|
|
|
|
makefile-bsdmake-mode)
|
|
|
|
"Modes for which auto-indenting is suppressed.")
|
|
|
|
(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))))
|
|
|
|
|
2015-03-26 05:48:16 +00:00
|
|
|
;; linum gutter helpers
|
|
|
|
(defvar *linum-mdown-line* nil
|
|
|
|
"Define persistent variable for linum selection")
|
|
|
|
|
|
|
|
(defun spacemacs/line-at-click ()
|
|
|
|
"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 *linum-mdown-line*"
|
|
|
|
(interactive "e")
|
|
|
|
(mouse-select-window event)
|
|
|
|
(goto-line (spacemacs/line-at-click))
|
|
|
|
(set-mark (point))
|
|
|
|
(setq *linum-mdown-line*
|
|
|
|
(line-number-at-pos)))
|
|
|
|
|
|
|
|
(defun spacemacs/mu-select-linum ()
|
|
|
|
"Select code block between point and *linum-mdown-line*"
|
|
|
|
(interactive)
|
|
|
|
(when *linum-mdown-line*
|
|
|
|
(let (mu-line)
|
|
|
|
(setq mu-line (spacemacs/line-at-click))
|
|
|
|
(goto-line (max *linum-mdown-line* mu-line))
|
|
|
|
(set-mark (line-end-position))
|
|
|
|
(goto-line (min *linum-mdown-line* mu-line))
|
|
|
|
(setq *linum-mdown*
|
|
|
|
nil))))
|
|
|
|
|
|
|
|
(defun spacemacs/select-current-block ()
|
|
|
|
"Select the current block of text between blank lines."
|
|
|
|
(interactive)
|
|
|
|
(let (p1 p2)
|
|
|
|
(progn
|
|
|
|
(if (re-search-backward "\n[ \t]*\n" nil "move")
|
|
|
|
(progn (re-search-forward "\n[ \t]*\n")
|
|
|
|
(setq p1 (point)))
|
|
|
|
(setq p1 (point)))
|
|
|
|
(if (re-search-forward "\n[ \t]*\n" nil "move")
|
|
|
|
(progn (re-search-backward "\n[ \t]*\n")
|
|
|
|
(setq p2 (point)))
|
|
|
|
(setq p2 (point))))
|
|
|
|
(set-mark p1)))
|
|
|
|
|
2015-03-26 05:42:58 +00:00
|
|
|
;; eval lisp helpers
|
|
|
|
(defun spacemacs/eval-region ()
|
|
|
|
(interactive)
|
|
|
|
(eval-region (region-beginning) (region-end))
|
|
|
|
(evil-normal-state))
|
|
|
|
|
|
|
|
;; idea from http://www.reddit.com/r/emacs/comments/312ge1/i_created_this_function_because_i_was_tired_of/
|
|
|
|
(defun spacemacs/eval-current-form ()
|
|
|
|
"Looks for the current def* or set* command then evaluates, unlike `eval-defun', does not go to topmost function"
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(search-backward-regexp "(def\\|(set")
|
|
|
|
(forward-list)
|
|
|
|
(call-interactively 'eval-last-sexp)))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
|
|
|
(defun eval-and-replace ()
|
|
|
|
"Replace the preceding sexp with its value."
|
|
|
|
(interactive)
|
|
|
|
(backward-kill-sexp)
|
|
|
|
(condition-case nil
|
|
|
|
(prin1 (eval (read (current-kill 0)))
|
|
|
|
(current-buffer))
|
|
|
|
(error (message "Invalid expression")
|
|
|
|
(insert (current-kill 0)))))
|
|
|
|
|
2012-12-20 21:51:11 +00:00
|
|
|
;; from https://gist.github.com/3402786
|
2014-05-01 01:41:26 +00:00
|
|
|
(defun toggle-maximize-buffer ()
|
|
|
|
"Maximize buffer"
|
2012-12-20 21:51:11 +00:00
|
|
|
(interactive)
|
|
|
|
(if (= 1 (length (window-list)))
|
2014-05-01 02:52:42 +00:00
|
|
|
(jump-to-register '_)
|
2012-12-20 21:51:11 +00:00
|
|
|
(progn
|
|
|
|
(set-register '_ (list (current-window-configuration)))
|
|
|
|
(delete-other-windows))))
|
|
|
|
|
2014-05-01 01:41:26 +00:00
|
|
|
(defun toggle-maximize-centered-buffer ()
|
|
|
|
"Maximize buffer and center it on the screen"
|
|
|
|
(interactive)
|
|
|
|
(if (= 1 (length (window-list)))
|
|
|
|
(progn (bzg-big-fringe-mode 0)
|
|
|
|
(jump-to-register '_))
|
|
|
|
(progn
|
|
|
|
(set-register '_ (list (current-window-configuration)))
|
|
|
|
(delete-other-windows)
|
|
|
|
(bzg-big-fringe-mode 1))))
|
|
|
|
|
2014-12-27 18:15:18 +00:00
|
|
|
(defun toggle-transparency ()
|
|
|
|
"Toggle between transparent or opaque display."
|
|
|
|
(interactive)
|
|
|
|
;; Define alpha if it's nil
|
|
|
|
(if (eq (frame-parameter (selected-frame) 'alpha) nil)
|
|
|
|
(set-frame-parameter (selected-frame) 'alpha '(100 100)))
|
|
|
|
;; Do the actual toggle
|
|
|
|
(if (/= (cadr (frame-parameter (selected-frame) 'alpha)) 100)
|
|
|
|
(set-frame-parameter (selected-frame) 'alpha '(100 100))
|
|
|
|
(set-frame-parameter (selected-frame) 'alpha
|
|
|
|
(list dotspacemacs-active-transparency
|
|
|
|
dotspacemacs-inactive-transparency))))
|
|
|
|
|
2014-05-01 02:53:40 +00:00
|
|
|
(defun toggle-triple-double-column-mode ()
|
|
|
|
" Toggle between triple columns and double columns mode quickly. "
|
|
|
|
(interactive)
|
|
|
|
(if (= 3 (length (window-list)))
|
|
|
|
(progn (delete-window (window-next-sibling))
|
|
|
|
(golden-ratio-mode 1))
|
|
|
|
(let ((num-windows (length (window-list))))
|
|
|
|
(progn
|
|
|
|
(golden-ratio-mode 0)
|
|
|
|
(dotimes (i (max 0 (- num-windows 3)))
|
|
|
|
(delete-window (window-next-sibling)))
|
|
|
|
(dotimes (i (- 3 (length (window-list))))
|
|
|
|
(progn (split-window-right)
|
|
|
|
(balance-windows)))))))
|
|
|
|
|
|
|
|
(defun layout-triple-columns ()
|
|
|
|
" Set the layout to triple columns. "
|
|
|
|
(interactive)
|
|
|
|
(golden-ratio-mode 0)
|
|
|
|
(delete-other-windows)
|
|
|
|
(dotimes (i 2) (split-window-right))
|
|
|
|
(balance-windows))
|
|
|
|
|
|
|
|
(defun layout-double-columns ()
|
|
|
|
" Set the layout to double columns. "
|
|
|
|
(interactive)
|
|
|
|
(golden-ratio-mode 1)
|
|
|
|
(delete-other-windows)
|
|
|
|
(split-window-right))
|
|
|
|
|
2013-11-15 13:03:14 +00:00
|
|
|
;; from magnars modified by ffevotte for dedicated windows support
|
2013-02-03 20:58:25 +00:00
|
|
|
(defun rotate-windows (count)
|
|
|
|
"Rotate your windows.
|
|
|
|
Dedicated windows are left untouched. Giving a negative prefix
|
2013-02-20 19:06:31 +00:00
|
|
|
argument takes the kindows rotate backwards."
|
2013-02-03 20:58:25 +00:00
|
|
|
(interactive "p")
|
|
|
|
(let* ((non-dedicated-windows (remove-if 'window-dedicated-p (window-list)))
|
|
|
|
(num-windows (length non-dedicated-windows))
|
|
|
|
(i 0)
|
|
|
|
(step (+ num-windows count)))
|
|
|
|
(cond ((not (> num-windows 1))
|
|
|
|
(message "You can't rotate a single window!"))
|
|
|
|
(t
|
|
|
|
(dotimes (counter (- num-windows 1))
|
|
|
|
(let* ((next-i (% (+ step i) num-windows))
|
|
|
|
|
|
|
|
(w1 (elt non-dedicated-windows i))
|
|
|
|
(w2 (elt non-dedicated-windows next-i))
|
|
|
|
|
|
|
|
(b1 (window-buffer w1))
|
|
|
|
(b2 (window-buffer w2))
|
|
|
|
|
|
|
|
(s1 (window-start w1))
|
|
|
|
(s2 (window-start w2)))
|
|
|
|
(set-window-buffer w1 b2)
|
|
|
|
(set-window-buffer w2 b1)
|
|
|
|
(set-window-start w1 s2)
|
|
|
|
(set-window-start w2 s1)
|
|
|
|
(setq i next-i)))))))
|
2012-12-18 05:48:12 +00:00
|
|
|
|
2013-02-20 19:06:31 +00:00
|
|
|
(defun rotate-windows-backward (count)
|
2013-02-19 23:12:10 +00:00
|
|
|
"Rotate your windows backward."
|
2013-02-20 19:06:31 +00:00
|
|
|
(interactive "p")
|
|
|
|
(rotate-windows (* -1 count)))
|
2013-02-19 23:12:10 +00:00
|
|
|
|
2015-03-26 05:15:16 +00:00
|
|
|
(defun spacemacs/next-real-buffer ()
|
2015-03-30 03:31:39 +00:00
|
|
|
"Swtich to the next buffer and avoid special buffers."
|
2015-03-26 05:15:16 +00:00
|
|
|
(interactive)
|
|
|
|
(switch-to-next-buffer)
|
|
|
|
(let ((i 0))
|
|
|
|
(while (and (< i 100) (string-equal "*" (substring (buffer-name) 0 1)))
|
|
|
|
(1+ i)
|
|
|
|
(switch-to-next-buffer))))
|
|
|
|
|
|
|
|
(defun spacemacs/prev-real-buffer ()
|
2015-03-30 03:31:39 +00:00
|
|
|
"Swtich to the previous buffer and avoid special buffers."
|
2015-03-26 05:15:16 +00:00
|
|
|
(interactive)
|
|
|
|
(switch-to-prev-buffer)
|
|
|
|
(let ((i 0))
|
|
|
|
(while (and (< i 100) (string-equal "*" (substring (buffer-name) 0 1)))
|
|
|
|
(1+ i)
|
|
|
|
(switch-to-prev-buffer))))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun rename-current-buffer-file ()
|
|
|
|
"Renames current buffer and file it is visiting."
|
|
|
|
(interactive)
|
|
|
|
(let ((name (buffer-name))
|
|
|
|
(filename (buffer-file-name)))
|
|
|
|
(if (not (and filename (file-exists-p filename)))
|
|
|
|
(error "Buffer '%s' is not visiting a file!" name)
|
|
|
|
(let ((new-name (read-file-name "New name: " filename)))
|
|
|
|
(cond ((get-buffer new-name)
|
|
|
|
(error "A buffer named '%s' already exists!" new-name))
|
|
|
|
(t
|
|
|
|
(rename-file filename new-name 1)
|
|
|
|
(rename-buffer new-name)
|
|
|
|
(set-visited-file-name new-name)
|
|
|
|
(set-buffer-modified-p nil)
|
|
|
|
(message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun delete-current-buffer-file ()
|
|
|
|
"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)
|
|
|
|
(message "File '%s' successfully removed" filename)))))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun find-or-create-file-at-point ()
|
|
|
|
"Guesses what parts of the buffer under point is a file name and opens it."
|
|
|
|
(interactive)
|
|
|
|
(find-file (file-name-at-point)))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun find-or-create-file-at-point-other-window ()
|
|
|
|
"Guesses what parts of the buffer under point is a file name and opens it."
|
|
|
|
(interactive)
|
|
|
|
(find-file-other-window (file-name-at-point)))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun file-name-at-point ()
|
|
|
|
(save-excursion
|
|
|
|
(let* ((file-name-regexp "[./a-zA-Z0-9\-_~]")
|
|
|
|
(start (progn
|
|
|
|
(while (looking-back file-name-regexp)
|
|
|
|
(forward-char -1))
|
|
|
|
(point)))
|
|
|
|
(end (progn
|
|
|
|
(while (looking-at file-name-regexp)
|
|
|
|
(forward-char 1))
|
|
|
|
(point))))
|
|
|
|
(buffer-substring start end))))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun touch-buffer-file ()
|
|
|
|
(interactive)
|
|
|
|
(insert " ")
|
|
|
|
(backward-delete-char 1)
|
|
|
|
(save-buffer))
|
|
|
|
|
2012-12-30 17:18:08 +00:00
|
|
|
;; from magnars
|
2012-12-29 20:39:39 +00:00
|
|
|
(defun sudo-edit (&optional arg)
|
|
|
|
(interactive "p")
|
|
|
|
(if (or arg (not buffer-file-name))
|
|
|
|
(find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
|
|
|
|
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
|
|
|
|
|
2013-01-02 22:08:45 +00:00
|
|
|
;; found at http://emacswiki.org/emacs/KillingBuffers
|
|
|
|
(defun kill-other-buffers ()
|
|
|
|
"Kill all other buffers."
|
|
|
|
(interactive)
|
2013-01-03 20:34:42 +00:00
|
|
|
(let (name (buffer-name))
|
|
|
|
(when (yes-or-no-p (format "Killing all buffers except \"%s\" ? " buffer-file-name))
|
|
|
|
(mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
|
|
|
|
(message "Buffers deleted!"))))
|
2013-01-02 22:08:45 +00:00
|
|
|
|
2013-01-07 21:59:36 +00:00
|
|
|
;; evenly split windows horizontally
|
|
|
|
(defun evenly-split-window-right ()
|
2013-01-08 16:09:21 +00:00
|
|
|
"Evenly split frame horizontally."
|
2013-01-07 21:59:36 +00:00
|
|
|
(interactive)
|
|
|
|
(split-window-right)
|
|
|
|
(balance-windows))
|
|
|
|
;; evenly split windows vertically
|
|
|
|
(defun evenly-split-window-below ()
|
2013-01-08 16:09:21 +00:00
|
|
|
"Evenly split frame vertically."
|
2013-01-07 21:59:36 +00:00
|
|
|
(interactive)
|
|
|
|
(split-window-below)
|
|
|
|
(balance-windows))
|
|
|
|
|
2013-01-08 16:09:21 +00:00
|
|
|
;; from http://dfan.org/blog/2009/02/19/emacs-dedicated-windows/
|
|
|
|
(defun toggle-current-window-dedication ()
|
|
|
|
"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/
|
2014-12-07 04:42:26 +00:00
|
|
|
(defun show-and-copy-buffer-filename ()
|
2013-11-15 13:03:14 +00:00
|
|
|
"Show the full path to the current file in the minibuffer."
|
|
|
|
(interactive)
|
|
|
|
(let ((file-name (buffer-file-name)))
|
|
|
|
(if file-name
|
|
|
|
(progn
|
|
|
|
(message file-name)
|
|
|
|
(kill-new file-name))
|
|
|
|
(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/
|
|
|
|
(defun 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
|
|
|
|
2014-11-10 05:38:58 +00:00
|
|
|
(defun find-dotfile ()
|
|
|
|
"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
|
|
|
|
2014-11-07 04:56:36 +00:00
|
|
|
(defun find-spacemacs-file ()
|
|
|
|
(interactive)
|
|
|
|
"Edit the `file' in the spacemacs base directory, in the current window."
|
|
|
|
(ido-find-file-in-dir spacemacs-directory))
|
|
|
|
|
|
|
|
(defun find-contrib-file ()
|
|
|
|
(interactive)
|
|
|
|
"Edit the `file' in the spacemacs base directory, in the current window."
|
2014-12-25 19:45:27 +00:00
|
|
|
(ido-find-file-in-dir configuration-layer-contrib-directory))
|
2014-11-07 04:56:36 +00:00
|
|
|
|
2013-11-20 05:30:23 +00:00
|
|
|
;; 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.")
|
2014-04-11 17:32:23 +00:00
|
|
|
(unless (or (string-match "Grep finished" (buffer-string))
|
2014-07-23 03:22:59 +00:00
|
|
|
(string-match "Ag finished" (buffer-string))
|
|
|
|
(string-match "nosetests" (buffer-name)))
|
2013-11-20 05:30:23 +00:00
|
|
|
|
2014-04-11 17:32:23 +00:00
|
|
|
;;no errors, make the compilation window go away in 0.5 seconds
|
|
|
|
(delete-windows-on buf)
|
|
|
|
(message "compilation ok.")))))
|
2013-11-20 05:30:23 +00:00
|
|
|
|
2014-11-14 17:25:44 +00:00
|
|
|
;; from https://gist.github.com/timcharper/493269
|
|
|
|
(defun split-window-vertically-and-switch ()
|
|
|
|
(interactive)
|
|
|
|
(split-window-vertically)
|
|
|
|
(other-window 1))
|
|
|
|
|
|
|
|
(defun split-window-horizontally-and-switch ()
|
|
|
|
(interactive)
|
|
|
|
(split-window-horizontally)
|
|
|
|
(other-window 1))
|
|
|
|
|
|
|
|
(defun ido-invoke-in-other-window ()
|
|
|
|
"signals ido mode to switch to (or create) another window after exiting"
|
|
|
|
(interactive)
|
|
|
|
(setq ido-exit-minibuffer-target-window 'other)
|
|
|
|
(ido-exit-minibuffer))
|
|
|
|
|
|
|
|
(defun ido-invoke-in-horizontal-split ()
|
|
|
|
"signals ido mode to split horizontally and switch after exiting"
|
|
|
|
(interactive)
|
|
|
|
(setq ido-exit-minibuffer-target-window 'horizontal)
|
|
|
|
(ido-exit-minibuffer))
|
|
|
|
|
|
|
|
(defun ido-invoke-in-vertical-split ()
|
|
|
|
"signals ido mode to split vertically and switch after exiting"
|
|
|
|
(interactive)
|
|
|
|
(setq ido-exit-minibuffer-target-window 'vertical)
|
|
|
|
(ido-exit-minibuffer))
|
|
|
|
|
|
|
|
(defun ido-invoke-in-new-frame ()
|
|
|
|
"signals ido mode to create a new frame after exiting"
|
|
|
|
(interactive)
|
|
|
|
(setq ido-exit-minibuffer-target-window 'frame)
|
|
|
|
(ido-exit-minibuffer))
|
|
|
|
|
|
|
|
(defadvice ido-read-internal (around ido-read-internal-with-minibuffer-other-window activate)
|
|
|
|
(let* (ido-exit-minibuffer-target-window
|
|
|
|
(this-buffer (current-buffer))
|
|
|
|
(result ad-do-it))
|
|
|
|
(cond
|
|
|
|
((equal ido-exit-minibuffer-target-window 'other)
|
|
|
|
(if (= 1 (count-windows))
|
|
|
|
(split-window-horizontally-and-switch)
|
|
|
|
(other-window 1)))
|
|
|
|
((equal ido-exit-minibuffer-target-window 'horizontal)
|
|
|
|
(split-window-horizontally-and-switch))
|
|
|
|
|
|
|
|
((equal ido-exit-minibuffer-target-window 'vertical)
|
|
|
|
(split-window-vertically-and-switch))
|
|
|
|
((equal ido-exit-minibuffer-target-window 'frame)
|
|
|
|
(make-frame)))
|
|
|
|
(switch-to-buffer this-buffer) ;; why? Some ido commands, such as textmate.el's textmate-goto-symbol don't switch the current buffer
|
|
|
|
result))
|
|
|
|
|
2013-11-25 05:18:28 +00:00
|
|
|
(defun set-google-translate-languages (source target)
|
|
|
|
"Set source language for google translate.
|
|
|
|
For instance pass En as source for english."
|
|
|
|
(interactive "sEnter source language (ie. En): \nsEnter target language (ie. En): "
|
|
|
|
source target)
|
|
|
|
(message (format "Set google translate source language to %s and target to %s"
|
|
|
|
source target))
|
|
|
|
(setq google-translate-default-source-language source)
|
|
|
|
(setq google-translate-default-target-language target))
|
|
|
|
|
2013-12-03 13:53:29 +00:00
|
|
|
;; from http://www.emacswiki.org/emacs/WordCount
|
|
|
|
(defun count-words-analysis (start end)
|
|
|
|
"Count how many times each word is used in the region.
|
|
|
|
Punctuation is ignored."
|
|
|
|
(interactive "r")
|
|
|
|
(let (words)
|
|
|
|
(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))))))
|
|
|
|
(when (interactive-p)
|
|
|
|
(message "%S" words))
|
|
|
|
words))
|
|
|
|
|
2014-12-18 05:12:04 +00:00
|
|
|
(defun set-attributes-from-alist (face attr)
|
|
|
|
"Apply an alist of attributes in the form ((:PROP . VALUE)) to face."
|
|
|
|
(while (car attr)
|
|
|
|
(set-face-attribute face nil (caar attr) (cdar attr))
|
|
|
|
(setq attr (cdr attr))))
|
|
|
|
|
2014-01-07 14:40:20 +00:00
|
|
|
(defun new-empty-buffer ()
|
|
|
|
"Create a new buffer called untitled(<n>)"
|
|
|
|
(interactive)
|
|
|
|
(let ((newbuf (generate-new-buffer-name "untitled")))
|
|
|
|
(switch-to-buffer newbuf)))
|
|
|
|
|
2015-03-26 05:11:37 +00:00
|
|
|
(defun spacemacs/home ()
|
|
|
|
"Go to home Spacemacs buffer"
|
|
|
|
(interactive)
|
|
|
|
(switch-to-buffer "*spacemacs*")
|
|
|
|
)
|
|
|
|
|
2014-03-06 16:24:09 +00:00
|
|
|
;; from https://github.com/gempesaw/dotemacs/blob/emacs/dg-defun.el
|
|
|
|
(defun kill-matching-buffers-rudely (regexp &optional internal-too)
|
|
|
|
"Kill buffers whose name matches the specified REGEXP. This
|
|
|
|
function, unlike the built-in `kill-matching-buffers` does so
|
|
|
|
WITHOUT ASKING. The optional second argument indicates whether to
|
|
|
|
kill internal buffers too."
|
|
|
|
(interactive "sKill buffers matching this regular expression: \nP")
|
|
|
|
(dolist (buffer (buffer-list))
|
|
|
|
(let ((name (buffer-name buffer)))
|
|
|
|
(when (and name (not (string-equal name ""))
|
|
|
|
(or internal-too (/= (aref name 0) ?\s))
|
|
|
|
(string-match regexp name))
|
|
|
|
(kill-buffer buffer)))))
|
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.")
|
|
|
|
|
2015-03-26 06:05:40 +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)
|
|
|
|
(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)
|
2015-01-29 16:19:55 +00:00
|
|
|
(server-kill-buffer)
|
2014-12-12 22:59:49 +00:00
|
|
|
(make-frame-invisible nil 1))
|
|
|
|
|
2014-05-01 01:41:26 +00:00
|
|
|
;; A small minor mode to use a big fringe
|
|
|
|
;; from http://bzg.fr/emacs-strip-tease.html
|
|
|
|
(defvar bzg-big-fringe-mode nil)
|
|
|
|
(define-minor-mode bzg-big-fringe-mode
|
|
|
|
"Minor mode to use big fringe in the current buffer."
|
|
|
|
:init-value nil
|
|
|
|
:global t
|
|
|
|
:variable bzg-big-fringe-mode
|
|
|
|
:group 'editing-basics
|
|
|
|
(if (not bzg-big-fringe-mode)
|
|
|
|
(set-fringe-style nil)
|
|
|
|
(set-fringe-mode
|
|
|
|
(/ (- (frame-pixel-width)
|
|
|
|
(* 100 (frame-char-width)))
|
|
|
|
2))))
|
|
|
|
|
|
|
|
(defun fill-char-to-column (char column)
|
|
|
|
" Fill the line with CHAR up to the given COLUMN"
|
|
|
|
(interactive "cFill with char: \nnUp to column: "
|
|
|
|
char column)
|
2014-11-17 02:30:48 +00:00
|
|
|
|
2014-05-01 01:41:26 +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
|
|
|
|
(toggle-frame-fullscreen-non-native)
|
|
|
|
(toggle-frame-fullscreen)))
|
|
|
|
|
2014-07-11 03:31:02 +00:00
|
|
|
(defun 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
|
2014-07-11 04:14:30 +00:00
|
|
|
(when (not (frame-parameter nil 'fullscreen)) 'fullscreen)))
|
|
|
|
))
|
2014-09-28 21:56:12 +00:00
|
|
|
|
2015-01-12 17:22:17 +00:00
|
|
|
(defun toggle-frame-fullscreen-non-native ()
|
|
|
|
"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)))))
|
|
|
|
|
2014-12-23 21:39:57 +00:00
|
|
|
(defmacro spacemacs|diminish (mode unicode &optional ascii)
|
|
|
|
"Diminish MODE name in mode line to UNICODE or ASCII depending on the value
|
|
|
|
`dotspacemacs-mode-line-unicode-symbols'.
|
|
|
|
|
|
|
|
If ASCII si not provided then UNICODE is used instead."
|
|
|
|
(let ((dim (if dotspacemacs-mode-line-unicode-symbols
|
|
|
|
unicode
|
|
|
|
(if ascii ascii unicode))))
|
|
|
|
`(eval-after-load 'diminish '(diminish ',mode ,dim))))
|
2014-09-30 02:25:08 +00:00
|
|
|
|
2014-12-04 03:39:18 +00:00
|
|
|
(defmacro spacemacs|hide-lighter (mode)
|
2014-09-30 02:25:08 +00:00
|
|
|
"Diminish MODE name in mode line to LIGHTER."
|
|
|
|
`(eval-after-load 'diminish '(diminish ',mode)))
|
2014-11-17 12:15:18 +00:00
|
|
|
|
|
|
|
(defun disable-electric-indent-mode ()
|
|
|
|
(if (fboundp 'electric-indent-local-mode)
|
|
|
|
;; for 24.4
|
|
|
|
(electric-indent-local-mode -1)
|
|
|
|
;; for 24.3
|
|
|
|
(add-hook 'electric-indent-functions
|
|
|
|
(lambda () 'no-indent) nil 'local)))
|
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
|
|
|
|
|
|
|
(defun spacemacs/ert-run-tests-buffer ()
|
|
|
|
"Run all the tests in the current buffer."
|
|
|
|
(interactive)
|
|
|
|
(save-buffer)
|
|
|
|
(load-file (buffer-file-name))
|
|
|
|
(ert t))
|
2014-11-24 04:10:04 +00:00
|
|
|
|
2014-12-19 19:03:19 +00:00
|
|
|
(defun spacemacs/alternate-buffer ()
|
2014-11-24 04:10:04 +00:00
|
|
|
"Switch back and forth between current and last buffer."
|
|
|
|
(interactive)
|
|
|
|
(switch-to-buffer (other-buffer (current-buffer) t)))
|
2014-11-26 19:57:01 +00:00
|
|
|
|
|
|
|
(defun spacemacs/highlight-TODO-words ()
|
|
|
|
"Highlight keywords for "
|
|
|
|
(interactive)
|
|
|
|
(font-lock-add-keywords
|
|
|
|
nil '(("\\<\\(\\(FIX\\(ME\\)?\\|TODO\\|OPTIMIZE\\|HACK\\|REFACTOR\\):\\)"
|
|
|
|
1 font-lock-warning-face t))))
|
2015-01-03 10:17:32 +00:00
|
|
|
|
|
|
|
(defun current-line ()
|
|
|
|
"Return the line at point as a string."
|
|
|
|
(buffer-substring (line-beginning-position) (line-end-position)))
|
2015-01-12 04:00:13 +00:00
|
|
|
|
2015-01-10 15:13:09 +00:00
|
|
|
(defun spacemacs/open-in-external-app ()
|
|
|
|
"Open current file in external application."
|
|
|
|
(interactive)
|
2015-02-06 04:20:14 +00:00
|
|
|
(let ((file-path (if (eq major-mode 'dired-mode)
|
|
|
|
(dired-get-file-for-visit)
|
|
|
|
(buffer-file-name))))
|
2015-01-10 15:13:09 +00:00
|
|
|
(cond
|
2015-04-18 17:07:49 +00:00
|
|
|
((system-is-mswindows) (w32-shell-execute "open" (replace-regexp-in-string "/" "\\\\" file-path)))
|
2015-01-10 15:13:09 +00:00
|
|
|
((system-is-mac) (shell-command (format "open \"%s\"" file-path)))
|
|
|
|
((system-is-linux) (let ((process-connection-type nil))
|
2015-03-26 05:42:58 +00:00
|
|
|
(start-process "" nil "xdg-open" file-path))))))
|
2015-02-10 00:44:52 +00:00
|
|
|
|
2015-02-10 23:03:06 +00:00
|
|
|
(defun spacemacs/next-error (&optional n reset)
|
|
|
|
"Dispatch to flycheck or standard emacs error."
|
|
|
|
(interactive "P")
|
|
|
|
(if (and (boundp 'flycheck-mode)
|
|
|
|
(symbol-value flycheck-mode))
|
|
|
|
(call-interactively 'flycheck-next-error)
|
|
|
|
(call-interactively 'next-error)))
|
|
|
|
|
|
|
|
(defun spacemacs/previous-error (&optional n reset)
|
|
|
|
"Dispatch to flycheck or standard emacs error."
|
|
|
|
(interactive "P")
|
|
|
|
(if (and (boundp 'flycheck-mode)
|
|
|
|
(symbol-value flycheck-mode))
|
|
|
|
(call-interactively 'flycheck-previous-error)
|
|
|
|
(call-interactively 'previous-error)))
|
2015-02-14 22:59:47 +00:00
|
|
|
|
|
|
|
(defun switch-to-minibuffer-window ()
|
|
|
|
"switch to minibuffer window (if active)"
|
|
|
|
(interactive)
|
|
|
|
(when (active-minibuffer-window)
|
|
|
|
(select-window (active-minibuffer-window))))
|
2015-02-14 04:07:38 +00:00
|
|
|
|
|
|
|
(defun comint-clear-buffer ()
|
|
|
|
(interactive)
|
|
|
|
(let ((comint-buffer-maximum-size 0))
|
|
|
|
(comint-truncate-buffer)))
|
2015-04-08 22:33:27 +00:00
|
|
|
|
|
|
|
;; http://stackoverflow.com/a/10216338/4869
|
|
|
|
(defun copy-whole-buffer-to-clipboard ()
|
|
|
|
"Copy entire buffer to clipboard"
|
|
|
|
(interactive)
|
|
|
|
(clipboard-kill-ring-save (point-min) (point-max)))
|
|
|
|
|
|
|
|
|
|
|
|
(defun copy-clipboard-to-whole-buffer ()
|
|
|
|
"Copy clipboard and replace buffer"
|
|
|
|
(interactive)
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
(clipboard-yank)
|
|
|
|
(deactivate-mark))
|