2016-08-26 01:19:21 +00:00
|
|
|
|
;;; funcs.el --- Emacs Lisp functions File
|
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2016-08-26 01:19:21 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
;;
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
;;
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2016-08-26 01:19:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-09 12:03:15 +00:00
|
|
|
|
;; Idea from http://www.reddit.com/r/emacs/comments/312ge1/i_created_this_function_because_i_was_tired_of/
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(defun spacemacs/eval-current-form ()
|
2017-05-09 12:03:15 +00:00
|
|
|
|
"Find and evaluate the current def* or set* command.
|
|
|
|
|
Unlike `eval-defun', this does not go to topmost function."
|
2016-10-09 16:57:46 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(search-backward-regexp "(def\\|(set")
|
|
|
|
|
(forward-list)
|
|
|
|
|
(call-interactively 'eval-last-sexp)))
|
|
|
|
|
|
2016-08-26 01:19:21 +00:00
|
|
|
|
(defun spacemacs/nav-find-elisp-thing-at-point-other-window ()
|
|
|
|
|
"Find thing under point and go to it another window."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((symb (variable-at-point)))
|
|
|
|
|
(if (and symb
|
|
|
|
|
(not (equal symb 0))
|
|
|
|
|
(not (fboundp symb)))
|
|
|
|
|
(find-variable-other-window symb)
|
|
|
|
|
(find-function-at-point))))
|
2016-12-24 16:56:24 +00:00
|
|
|
|
|
2017-02-11 21:31:56 +00:00
|
|
|
|
|
|
|
|
|
;; edebug
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/edebug-instrument-defun-on ()
|
|
|
|
|
"Toggle on instrumentalisation for the function under `defun'."
|
|
|
|
|
(interactive)
|
|
|
|
|
(eval-defun 'edebugit))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/edebug-instrument-defun-off ()
|
2017-03-13 05:24:46 +00:00
|
|
|
|
"Toggle off instrumentalisation for the function under `defun'."
|
2017-02-11 21:31:56 +00:00
|
|
|
|
(interactive)
|
2017-03-13 05:24:46 +00:00
|
|
|
|
(eval-defun nil))
|
2017-02-11 21:31:56 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/elisp-toggle-debug-expr-and-eval-func ()
|
|
|
|
|
"Insert or remove debug expression, evaluate function and save buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((trace "(debug)")
|
|
|
|
|
(line (thing-at-point 'line)))
|
|
|
|
|
(if (and line (string-match trace line))
|
|
|
|
|
(kill-whole-line)
|
|
|
|
|
(progn
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(insert trace)
|
|
|
|
|
(newline-and-indent))))
|
|
|
|
|
(eval-defun nil)
|
|
|
|
|
(save-buffer))
|
|
|
|
|
|
2017-02-12 17:50:07 +00:00
|
|
|
|
(defun spacemacs//edebug-mode (&rest args)
|
|
|
|
|
"Additional processing when `edebug-mode' is activated or deactivated."
|
2021-01-23 01:20:00 +00:00
|
|
|
|
(let ((evilified? (or (eq 'vim dotspacemacs-editing-style)
|
|
|
|
|
(and (eq 'hybrid dotspacemacs-editing-style)
|
|
|
|
|
hybrid-style-enable-evilified-state))))
|
2017-02-12 17:50:07 +00:00
|
|
|
|
(if (not edebug-mode)
|
|
|
|
|
;; disable edebug-mode
|
2021-02-18 20:16:15 +00:00
|
|
|
|
(when evilified? (evil-evilified-state-exit))
|
2017-02-12 17:50:07 +00:00
|
|
|
|
;; enable edebug-mode
|
2021-01-23 01:20:00 +00:00
|
|
|
|
(when evilified? (evil-evilified-state))
|
2017-02-12 17:50:07 +00:00
|
|
|
|
(when (and (fboundp 'golden-ratio-mode)
|
|
|
|
|
golden-ratio-mode)
|
|
|
|
|
(golden-ratio)))))
|
2017-02-11 21:31:56 +00:00
|
|
|
|
|
2016-12-24 16:56:24 +00:00
|
|
|
|
|
|
|
|
|
;; smartparens integration
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/eval-current-form-sp (&optional arg)
|
|
|
|
|
"Call `eval-last-sexp' after moving out of one level of
|
|
|
|
|
parentheses. Will exit any strings and/or comments first.
|
|
|
|
|
An optional ARG can be used which is passed to `sp-up-sexp' to move out of more
|
|
|
|
|
than one sexp.
|
|
|
|
|
Requires smartparens because all movement is done using `sp-up-sexp'."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(let ((evil-move-beyond-eol t))
|
|
|
|
|
;; evil-move-beyond-eol disables the evil advices around eval-last-sexp
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((max 10))
|
|
|
|
|
(while (and (> max 0)
|
|
|
|
|
(sp-point-in-string-or-comment))
|
|
|
|
|
(decf max)
|
|
|
|
|
(sp-up-sexp)))
|
|
|
|
|
(sp-up-sexp arg)
|
|
|
|
|
(call-interactively 'eval-last-sexp))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/eval-current-symbol-sp ()
|
|
|
|
|
"Call `eval-last-sexp' on the symbol around point.
|
|
|
|
|
Requires smartparens because all movement is done using `sp-forward-symbol'."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((evil-move-beyond-eol t))
|
|
|
|
|
;; evil-move-beyond-eol disables the evil advices around eval-last-sexp
|
|
|
|
|
(save-excursion
|
|
|
|
|
(sp-forward-symbol)
|
|
|
|
|
(call-interactively 'eval-last-sexp))))
|
2018-06-01 06:59:57 +00:00
|
|
|
|
|
2021-02-11 15:20:48 +00:00
|
|
|
|
(defun spacemacs/eval-current-form-to-comment-sp (&optional arg)
|
|
|
|
|
"Same as `spacemacs/eval-current-form-sp' but inserts output as a comment."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(let ((evil-move-beyond-eol t))
|
|
|
|
|
;; evil-move-beyond-eol disables the evil advices around eval-last-sexp
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((max 10))
|
|
|
|
|
(while (and (> max 0)
|
|
|
|
|
(sp-point-in-string-or-comment))
|
|
|
|
|
(decf max)
|
|
|
|
|
(sp-up-sexp)))
|
|
|
|
|
(sp-up-sexp arg)
|
|
|
|
|
(let ((ret-val (format ";; %S" (call-interactively 'eval-last-sexp))))
|
|
|
|
|
(goto-char (point-at-eol))
|
|
|
|
|
(open-line 1)
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(insert ret-val)))))
|
|
|
|
|
|
2018-06-01 06:59:57 +00:00
|
|
|
|
|
|
|
|
|
;; elisp comment text-object definition
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//define-elisp-comment-text-object ()
|
|
|
|
|
"Define a text object and a surround pair for elisp comments.
|
|
|
|
|
Intended for use in mode hooks."
|
|
|
|
|
(spacemacs|define-text-object ";" "elisp-comment" ";; " ""))
|