Install the smartparens package

This commit is contained in:
Gergely Polonkai 2016-10-10 14:47:04 +02:00
parent af1781dcc6
commit bba965611e
16 changed files with 10196 additions and 0 deletions

View File

@ -0,0 +1,198 @@
;;; smartparens-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "smartparens" "smartparens.el" (22523 34125
;;;;;; 532790 226000))
;;; Generated autoloads from smartparens.el
(autoload 'sp-cheat-sheet "smartparens" "\
Generate a cheat sheet of all the smartparens interactive functions.
Without a prefix argument, print only the short documentation and examples.
With non-nil prefix argument, show the full documentation for each function.
You can follow the links to the function or variable help page.
To get back to the full list, use \\[help-go-back].
You can use `beginning-of-defun' and `end-of-defun' to jump to
the previous/next entry.
Examples are fontified using the `font-lock-string-face' for
better orientation.
\(fn &optional ARG)" t nil)
(defvar smartparens-mode-map (make-sparse-keymap) "\
Keymap used for `smartparens-mode'.")
(autoload 'sp-use-paredit-bindings "smartparens" "\
Initiate `smartparens-mode-map' with paredit-compatible bindings for
corresponding functions provided by smartparens. See variable
`sp-paredit-bindings'.
\(fn)" t nil)
(autoload 'sp-use-smartparens-bindings "smartparens" "\
Initiate `smartparens-mode-map' with smartparens bindings for navigation functions.
See variable `sp-smartparens-bindings'.
\(fn)" t nil)
(autoload 'smartparens-mode "smartparens" "\
Toggle smartparens mode.
You can enable pre-set bindings by customizing
`sp-base-key-bindings' variable. The current content of
`smartparens-mode-map' is:
\\{smartparens-mode-map}
\(fn &optional ARG)" t nil)
(autoload 'smartparens-strict-mode "smartparens" "\
Toggle the strict smartparens mode.
When strict mode is active, `delete-char', `kill-word' and their
backward variants will skip over the pair delimiters in order to
keep the structure always valid (the same way as `paredit-mode'
does). This is accomplished by remapping them to
`sp-delete-char' and `sp-kill-word'. There is also function
`sp-kill-symbol' that deletes symbols instead of words, otherwise
working exactly the same (it is not bound to any key by default).
When strict mode is active, this is indicated with \"/s\"
after the smartparens indicator in the mode list.
\(fn &optional ARG)" t nil)
(defvar smartparens-global-strict-mode nil "\
Non-nil if Smartparens-Global-Strict mode is enabled.
See the `smartparens-global-strict-mode' command
for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `smartparens-global-strict-mode'.")
(custom-autoload 'smartparens-global-strict-mode "smartparens" nil)
(autoload 'smartparens-global-strict-mode "smartparens" "\
Toggle Smartparens-Strict mode in all buffers.
With prefix ARG, enable Smartparens-Global-Strict mode if ARG is positive;
otherwise, disable it. If called from Lisp, enable the mode if
ARG is omitted or nil.
Smartparens-Strict mode is enabled in all buffers where
`turn-on-smartparens-strict-mode' would do it.
See `smartparens-strict-mode' for more information on Smartparens-Strict mode.
\(fn &optional ARG)" t nil)
(autoload 'turn-on-smartparens-strict-mode "smartparens" "\
Turn on `smartparens-strict-mode'.
\(fn)" t nil)
(defvar smartparens-global-mode nil "\
Non-nil if Smartparens-Global mode is enabled.
See the `smartparens-global-mode' command
for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `smartparens-global-mode'.")
(custom-autoload 'smartparens-global-mode "smartparens" nil)
(autoload 'smartparens-global-mode "smartparens" "\
Toggle Smartparens mode in all buffers.
With prefix ARG, enable Smartparens-Global mode if ARG is positive;
otherwise, disable it. If called from Lisp, enable the mode if
ARG is omitted or nil.
Smartparens mode is enabled in all buffers where
`turn-on-smartparens-mode' would do it.
See `smartparens-mode' for more information on Smartparens mode.
\(fn &optional ARG)" t nil)
(autoload 'turn-on-smartparens-mode "smartparens" "\
Turn on `smartparens-mode'.
This function is used to turn on `smartparens-global-mode'.
By default `smartparens-global-mode' ignores buffers with
`mode-class' set to special, but only if they are also not comint
buffers.
Additionally, buffers on `sp-ignore-modes-list' are ignored.
You can still turn on smartparens in these mode manually (or
in mode's startup-hook etc.) by calling `smartparens-mode'.
\(fn)" t nil)
(autoload 'turn-off-smartparens-mode "smartparens" "\
Turn off `smartparens-mode'.
\(fn)" t nil)
(autoload 'show-smartparens-mode "smartparens" "\
Toggle visualization of matching pairs. When enabled, any
matching pair is highlighted after `sp-show-pair-delay' seconds
of Emacs idle time if the point is immediately in front or after
a pair. This mode works similarly to `show-paren-mode', but
support custom pairs.
\(fn &optional ARG)" t nil)
(defvar show-smartparens-global-mode nil "\
Non-nil if Show-Smartparens-Global mode is enabled.
See the `show-smartparens-global-mode' command
for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `show-smartparens-global-mode'.")
(custom-autoload 'show-smartparens-global-mode "smartparens" nil)
(autoload 'show-smartparens-global-mode "smartparens" "\
Toggle Show-Smartparens mode in all buffers.
With prefix ARG, enable Show-Smartparens-Global mode if ARG is positive;
otherwise, disable it. If called from Lisp, enable the mode if
ARG is omitted or nil.
Show-Smartparens mode is enabled in all buffers where
`turn-on-show-smartparens-mode' would do it.
See `show-smartparens-mode' for more information on Show-Smartparens mode.
\(fn &optional ARG)" t nil)
(autoload 'turn-on-show-smartparens-mode "smartparens" "\
Turn on `show-smartparens-mode'.
\(fn)" t nil)
(autoload 'turn-off-show-smartparens-mode "smartparens" "\
Turn off `show-smartparens-mode'.
\(fn)" t nil)
;;;***
;;;### (autoloads nil nil ("smartparens-clojure.el" "smartparens-config.el"
;;;;;; "smartparens-ess.el" "smartparens-haskell.el" "smartparens-html.el"
;;;;;; "smartparens-latex.el" "smartparens-lua.el" "smartparens-pkg.el"
;;;;;; "smartparens-python.el" "smartparens-racket.el" "smartparens-ruby.el"
;;;;;; "smartparens-rust.el" "smartparens-scala.el") (22523 34125
;;;;;; 564790 380000))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; smartparens-autoloads.el ends here

View File

@ -0,0 +1,49 @@
;;; smartparens-clojure.el --- Additional configuration for Clojure mode.
;;
;; Author: Vitalie Spinu <spinuvit@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 14 July 2016
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;;
;; This file is not part of GNU Emacs.
;;
;;; License:
;;
;; This file is part of Smartparens.
;;
;; Smartparens 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.
;;
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; This file provides some additional configuration for Clojure mode. To use
;; it, simply add:
;;
;; (require 'smartparens-clojure)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;;
;;; Code:
(require 'smartparens)
(defvar sp-clojure-prefix "\\(?:[@`'#~,_?^]+\\)"
"Prefix used in `sp-sepx-prefix' for clojure modes.")
(dolist (mode '(clojure-mode clojurescript-mode clojurec-mode cider-repl-mode))
(add-to-list 'sp-sexp-prefix `(,mode regexp ,sp-clojure-prefix)))
(provide 'smartparens-clojure)
;;; smartparens-clojure.el ends here

View File

@ -0,0 +1,117 @@
;;; smartparens-config.el --- Default configuration for smartparens package
;; Copyright (C) 2013-2016 Matus Goljer
;; Author: Matus Goljer <matus.goljer@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 30 Jan 2013
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This is a default configuration for smartparens package. If you
;; wish to set up everything by yourself, you can instead require
;; smartparens directly.
;; However, some configuration is always loaded by default, most
;; notably the built-in list of supported pairs. If you want to erase
;; this list, simply use (setq sp-pairs nil) and then add your own
;; pairs.
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(defun sp-lisp-invalid-hyperlink-p (_1 action _2)
(when (eq action 'navigate)
;; Ignore errors due to us being at the start or end of the
;; buffer.
(ignore-errors
(or (and (looking-at "\\sw\\|\\s_")
(save-excursion
(backward-char 2)
(looking-at "\\sw\\|\\s_")))
(and (save-excursion
(backward-char 1)
(looking-at "\\sw\\|\\s_"))
(save-excursion
(forward-char 1)
(looking-at "\\sw\\|\\s_")))))))
;; emacs is lisp hacking enviroment, so we set up some most common
;; lisp modes too
(sp-with-modes sp-lisp-modes
;; disable ', it's the quote character!
(sp-local-pair "'" nil :actions nil)
;; also only use the pseudo-quote inside strings where it serve as
;; hyperlink.
(sp-local-pair "`" "'"
:when '(sp-in-string-p
sp-in-comment-p)
:unless '(sp-lisp-invalid-hyperlink-p)
:skip-match (lambda (ms mb me)
(cond
((equal ms "'")
(or (sp-lisp-invalid-hyperlink-p "`" 'navigate '_)
(not (sp-point-in-string-or-comment))))
(t (not (sp-point-in-string-or-comment)))))))
;; <rant>Unfortunately emacs devs in their glorious wisdom decided to
;; make @ no longer have prefix syntax, it is now a symbol... because
;; apparently its use in symbols is so frequent. Anyway, since we
;; can't really change that, let's use a regexp based solution</rant>
(add-to-list 'sp-sexp-prefix (list 'emacs-lisp-mode 'regexp "\\(?:['`]*,@?\\|[',`]\\)"))
;; TODO: this should only be active in docstring, otherwise we want
;; the regexp completion \\{\\}. To handle this feature, we must
;; allow multiple pairs on same opening (therefore, the unique ID must
;; become the opening and closing pair)
(sp-local-pair 'emacs-lisp-mode "\\\\{" "}" :when '(sp-in-docstring-p))
;; NOTE: Normally, `sp-local-pair' accepts list of modes (or a single
;; mode) as a first argument. The macro `sp-with-modes' adds this
;; automatically. If you want to call sp-local-pair outside this
;; macro, you MUST supply the major mode argument.
(--each sp--html-modes
(eval-after-load (symbol-name it) '(require 'smartparens-html)))
(eval-after-load "latex" '(require 'smartparens-latex))
(eval-after-load "tex-mode" '(require 'smartparens-latex))
(eval-after-load "lua-mode" '(require 'smartparens-lua))
(eval-after-load "ruby-mode" '(require 'smartparens-ruby))
(eval-after-load "enh-ruby-mode" '(require 'smartparens-ruby))
(eval-after-load "rust-mode" '(require 'smartparens-rust))
(eval-after-load "haskell-mode" '(require 'smartparens-haskell))
(eval-after-load "haskell-interactive-mode" '(require 'smartparens-haskell))
(--each '("python-mode" "python")
(eval-after-load it '(require 'smartparens-python)))
(eval-after-load "scala-mode" '(require 'smartparens-scala))
(eval-after-load "racket-mode" '(require 'smartparens-racket))
(eval-after-load "ess" '(require 'smartparens-ess))
(provide 'smartparens-config)
;;; smartparens-config.el ends here

View File

@ -0,0 +1,207 @@
;;; smartparens-ess.el --- Smartparens Extension for Emacs Speaks Statistics
;; Copyright (c) 2015-2016 Bernhard Pröll
;; Author: Bernhard Pröll
;; Maintainer: Bernhard Pröll
;; URL: https://github.com/Fuco1/smartparens
;; Created: 2015-02-26
;; Version: 0.2
;; Keywords: abbrev convenience editing
;; This file is NOT part of GNU Emacs.
;; 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/>.
;;; Code:
(require 'smartparens)
(require 'rx)
;; avoid traveling commas when slurping
;; (|a, b), c ---> (|a, b, c)
(dolist (mode '(ess-mode inferior-ess-mode))
(add-to-list 'sp-sexp-suffix (list mode 'regexp "")))
;; `sp-sexp-prefix' for ESS
(add-to-list 'sp-sexp-prefix
(list 'ess-mode 'regexp
(rx (zero-or-more (or word (syntax symbol))))))
;; slurping follows Google's R style guide
;; see https://google.github.io/styleguide/Rguide.xml
(defun sp-ess-pre-handler (id action context)
"Remove spaces before opening parenthesis in a function call.
Remove redundant space around commas."
(when (equal action 'slurp-forward)
(let ((sxp (sp-get-thing 'back)))
(save-excursion
(goto-char (sp-get sxp :beg-prf))
;; (|) x ---> (x)
(when (looking-back (rx (syntax open-parenthesis)
(one-or-more space)))
(cycle-spacing 0 nil 'single-shot))
(cond
;; (|)if(cond) ---> (|if (cond))
((member (sp-get sxp :prefix) '("if" "for" "while"))
(goto-char (sp-get sxp :beg))
(cycle-spacing 1 nil 'single-shot))
;; (|)v [,2] <- if(x > 1) ---> (v[,2] <- if (x > 1))
((and
(member (sp-get sxp :op) '("[" "("))
(equal (sp-get sxp :prefix) "")
(looking-back
(rx (and (not-char "%" ",")
(not (syntax close-parenthesis)))
(one-or-more space)))
(not (member
(save-excursion
(sp-backward-sexp)
(thing-at-point 'word 'noprop))
'("if" "for" "while"))))
(cycle-spacing 0 nil 'single-shot))
;; (|)a , b, c ---> (|a, b, c)
((looking-back
(rx (zero-or-more space) "," (zero-or-more space))
(line-beginning-position) 'greedy)
(replace-match ", "))))))
(when (equal action 'slurp-backward)
(let ((sxp (sp-get-thing)))
(save-excursion
(goto-char (sp-get sxp :end))
;; x (|) ---> (x)
(when (looking-at (rx (one-or-more space)
(syntax close-parenthesis)))
(cycle-spacing 0 nil 'single-shot))
;; if(cond){} (|) ---> (if (cond) {}|)
(cond ((member (sp-get sxp :prefix) '("if" "for" "while"))
(goto-char (sp-get sxp :beg))
(cycle-spacing 1 nil 'single-shot))
;; for style reasons there should be a space before curly
;; brackets and binary operators
((and (member (sp-get sxp :op) '("{" "%"))
(not (looking-at (rx (syntax close-parenthesis)))))
(cycle-spacing 1 nil 'single-shot))
;; v[2](|) ---> (v[2]|)
((and
(not (member (thing-at-point 'word 'noprop)
'("if" "for" "while")))
(looking-at
(rx (and (zero-or-more space)
(not-char "{")
(or (syntax close-parenthesis)
(char "(")
(char "["))))))
(cycle-spacing 0 nil 'single-shot))
;; 1 , 2 (|) ---> (1, 2)
((looking-at
(rx (zero-or-more space) "," (zero-or-more space)))
(replace-match ", ")))))))
;; function(x) {|} ---> function(x) {\n|\n}
;; ##' \tabular{rrr}{|} --->
;; ##' \tabular{rrr}{
;; ##' |
;; ##' }
(defun sp-ess-open-sexp-indent (&rest _ignored)
"Open new brace or bracket with indentation."
(if (and (fboundp 'ess-roxy-entry-p) (ess-roxy-entry-p))
(progn
(save-excursion (ess-roxy-indent-on-newline))
(when (looking-back ess-roxy-str nil)
(cycle-spacing 3 nil t)))
(newline)
(indent-according-to-mode)
(forward-line -1)
(indent-according-to-mode)))
(defun sp-ess-roxy-str-p (id action context)
(when (and (boundp 'ess-roxy-re) (eq action 'insert))
(sp--looking-back-p ess-roxy-re)))
(sp-with-modes 'ess-mode
(sp-local-pair "{" nil
:pre-handlers '(sp-ess-pre-handler)
;; the more reasonable C-j interferes with default binding for
;; `ess-eval-line'
:post-handlers '((sp-ess-open-sexp-indent "M-j")))
(sp-local-pair "(" nil
:pre-handlers '(sp-ess-pre-handler)
:post-handlers '((sp-ess-open-sexp-indent "M-j")))
(sp-local-pair "[" nil
:pre-handlers '(sp-ess-pre-handler)
:post-handlers '((sp-ess-open-sexp-indent "M-j")))
(sp-local-pair "'" nil
:unless '(sp-ess-roxy-str-p)))
;;; roxygen2 markup
;; see https://cran.r-project.org/web/packages/roxygen2/vignettes/formatting.html
(sp-with-modes 'ess-mode
(sp-local-pair "\\strong{" "}"
:when '(sp-in-comment-p)
:trigger "\\strong")
(sp-local-pair "\\emph{" "}"
:when '(sp-in-comment-p)
:trigger "\\emph")
(sp-local-pair "\\code{" "}"
:when '(sp-in-comment-p)
:trigger "\\code")
(sp-local-pair "\\url{" "}"
:when '(sp-in-comment-p)
:trigger "\\url")
(sp-local-pair "\\link{" "}"
:when '(sp-in-comment-p)
:trigger "\\link")
(sp-local-pair "\\href{" "}"
:when '(sp-in-comment-p)
:trigger "\\href"
:suffix "{[^}]*}")
(sp-local-pair "\\email{" "}"
:when '(sp-in-comment-p)
:trigger "\\email")
(sp-local-pair "\\pkg{" "}"
:when '(sp-in-comment-p)
:trigger "\\pkg")
(sp-local-pair "\\item{" "}"
:when '(sp-in-comment-p)
:post-handlers '((sp-ess-open-sexp-indent "M-j"))
:trigger "\\item{")
(sp-local-pair "\\enumerate{" "}"
:when '(sp-in-comment-p)
:post-handlers '((sp-ess-open-sexp-indent "M-j"))
:trigger "\\enumerate")
(sp-local-pair "\\itemize{" "}"
:when '(sp-in-comment-p)
:post-handlers '((sp-ess-open-sexp-indent "M-j"))
:trigger "\\itemize")
(sp-local-pair "\\describe{" "}"
:when '(sp-in-comment-p)
:post-handlers '((sp-ess-open-sexp-indent "M-j"))
:trigger "\\describe")
(sp-local-pair "\\eqn{" "}"
:when '(sp-in-comment-p)
:trigger "\\eqn")
(sp-local-pair "\\deqn{" "}"
:when '(sp-in-comment-p)
:trigger "\\deqn")
(sp-local-pair "\\tabular{" "}"
:when '(sp-in-comment-p)
:trigger "\\tabular"
:post-handlers '((sp-ess-open-sexp-indent "M-j"))
:suffix "{[^}]*}"))
(provide 'smartparens-ess)
;;; smartparens-ess ends here

View File

@ -0,0 +1,86 @@
;;; smartparens-haskell.el --- Additional configuration for Haskell based modes.
;; Copyright (C) 2015 Michael Xavier
;; Author: Michael Xavier <michael@michaelxavier.net>
;; Maintainer: Michael Xavier <michael@michaelxavier.net>
;; Created: 29 Apr 2016
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Haskell based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-haskell)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(sp-with-modes '(haskell-mode haskell-interactive-mode)
(sp-local-pair "{-#" "#-}")
(sp-local-pair "'" nil :unless '(sp-point-after-word-p))
(sp-local-pair "\\(" nil :actions nil))
(defun sp--inferior-haskell-mode-backward-bound-fn ()
"Limit the backward search to the prompt if point is on prompt."
(-when-let (limit (cond ((bound-and-true-p comint-last-prompt)
(marker-position (cdr comint-last-prompt)))
((bound-and-true-p comint-last-prompt-overlay)
(overlay-end comint-last-prompt-overlay))
(t nil)))
(and (> (point) limit) limit)))
(defun sp--inferior-haskell-mode-forward-bound-fn ()
"Limit the forward search to exclude the prompt if point is before prompt."
(-when-let (limit (cond ((bound-and-true-p comint-last-prompt)
(marker-position (car comint-last-prompt)))
((bound-and-true-p comint-last-prompt-overlay)
(overlay-start comint-last-prompt-overlay))
(t nil)))
(and (< (point) limit) limit)))
(defun sp--setup-inferior-haskell-mode-search-bounds ()
"Setup the search bound.
If the point is after the last prompt, limit the backward search
only for the propmt.
If the point is before the last prompt, limit the forward search up until the prompt start."
(setq sp-forward-bound-fn 'sp--inferior-haskell-mode-forward-bound-fn)
(setq sp-backward-bound-fn 'sp--inferior-haskell-mode-backward-bound-fn))
(add-hook 'inferior-haskell-mode-hook 'sp--setup-inferior-haskell-mode-search-bounds)
(provide 'smartparens-haskell)
;;; smartparens-haskell.el ends here

View File

@ -0,0 +1,172 @@
;;; smartparens-html.el --- Additional configuration for HTML based modes.
;; Copyright (C) 2013-2014 Matus Goljer
;; Author: Matus Goljer <matus.goljer@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 14 Sep 2013
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for HTML based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-html)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;; It is advised that you add `html-mode' to the list
;; `sp-navigate-consider-stringlike-sexp'. This will tell smartparens
;; to treat the "" delimited strings as sexps, and enable you to use
;; all the sexp-based commands on them (such as `sp-down-sexp',
;; `sp-up-sexp' etc.)
;; This file provides these interactive functions:
;; `sp-html-next-tag' - Recommended binding: C-c C-f
;; `sp-html-previous-tag' - Recommended binding: C-c C-b
;;
;; (These two bindings are used for navigation by tags forward or
;; backward, but `sp-forward-sexp' already does that.)
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(defun sp-html-next-tag (arg)
"Move point to the beginning of next SGML tag.
With ARG positive N > 1, move N tags forward.
With ARG raw prefix argument \\[universal-argument] move out of
the current tag and to the beginning of enclosing tag.
Note: this function is based on `sp-beginning-of-sexp' but
specialized to only work with SGML tags and to always move
forward."
(interactive "P")
(let ((sp-prefix-tag-object t))
(if (sp--raw-argument-p arg)
(sp-beginning-of-sexp arg)
(sp-beginning-of-sexp (1+ (prefix-numeric-value arg))))))
(defun sp-html-previous-tag (arg)
"Move point to the beginning of previous SGML tag.
With ARG positive N > 1, move N tags backward.
With ARG raw prefix argument \\[universal-argument] move out of
the current tag and to the beginning of enclosing tag.
Note: this function is based on `sp-beginning-of-sexp' but
specialized to only work with SGML tags and to always move
backward."
(interactive "P")
(let ((sp-prefix-tag-object t))
(if (sp--raw-argument-p arg)
(sp-beginning-of-sexp arg)
(sp-beginning-of-sexp (1- (- (prefix-numeric-value arg)))))))
(defun sp-html-post-handler (&optional id action context)
(cl-case action
(slurp-forward
(save-excursion
(let ((sp-prefix-pair-object t))
(sp-backward-sexp))
(-when-let (enc (sp-get-enclosing-sexp))
(sp-get enc
(goto-char :beg-in)
(when (looking-at-p "[ \t]*$")
(goto-char :end-in)
(save-excursion
(sp-backward-sexp)
(forward-line -1)
(when (sp-point-in-blank-line)
(delete-region (line-beginning-position) (1+ (line-end-position)))))
(newline-and-indent))))))
(slurp-backward
(save-excursion
(-when-let (enc (sp-get-enclosing-sexp))
(sp-get enc
(goto-char :end-in)
(when (sp--looking-back-p "^[ \t]*")
(save-excursion
(goto-char :beg-in)
(newline-and-indent)
(sp-forward-sexp)
(forward-line)
(when (sp-point-in-blank-line)
(delete-region (line-beginning-position) (1+ (line-end-position))))))))))
(barf-forward
(save-excursion
(let ((sp-prefix-pair-object t))
(sp-backward-sexp))
(-when-let (enc (sp-get-enclosing-sexp))
(sp-get enc
(goto-char :beg-in)
(when (looking-at-p "[ \t]*$")
(goto-char :end-in)
(newline-and-indent)))))
(save-excursion
(sp-forward-sexp)
(forward-line)
(when (sp-point-in-blank-line)
(delete-region (line-beginning-position) (1+ (line-end-position))))))
(barf-backward
(save-excursion
(-when-let (enc (sp-get-enclosing-sexp))
(sp-get enc
(goto-char :end-in)
(when (sp--looking-back-p "^[ \t]*")
(goto-char :beg-in)
(newline-and-indent)
(sp-backward-up-sexp)
(sp-backward-sexp)
(forward-line -1)
(when (sp-point-in-blank-line)
(delete-region (line-beginning-position) (1+ (line-end-position)))))))))
(beginning-of-sexp
(when (looking-at-p "[ \t]*$")
(sp-next-sexp)))
(end-of-sexp
(when (sp--looking-back-p "^[ \t]*" nil t)
(sp-previous-sexp)))))
(sp-with-modes sp--html-modes
(sp-local-pair "<" ">")
(sp-local-tag "<" "<_>" "</_>" :transform 'sp-match-sgml-tags :post-handlers '(sp-html-post-handler)))
(--each sp--html-modes
(add-to-list 'sp-navigate-consider-sgml-tags it))
(provide 'smartparens-html)
;;; smartparens-html.el ends here

View File

@ -0,0 +1,170 @@
;;; smartparens-latex.el --- Additional configuration for (La)TeX based modes.
;; Copyright (C) 2013-2016 Matus Goljer
;; Author: Matus Goljer <matus.goljer@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 14 Feb 2013
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for (La)TeX based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-latex)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;; It is advised that you add `latex-mode' to the list
;; `sp-navigate-consider-stringlike-sexp'. This will tell
;; smartparens to treat the $$ math blocks as sexps, and enable you
;; to use all the sexp-based commands on them (such as
;; `sp-down-sexp', `sp-up-sexp' etc.)
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(defun sp-latex-insert-spaces-inside-pair (id action context)
(when (eq action 'insert)
(insert " ")
(backward-char 1))
(when (and (eq action 'wrap)
(save-excursion
(goto-char (sp-get sp-last-wrapped-region :beg-in))
(not (sp--looking-back-p "[[{(]"))))
(save-excursion
(goto-char (sp-get sp-last-wrapped-region :end-in))
(insert " ")
(goto-char (sp-get sp-last-wrapped-region :beg-in))
(insert " "))))
(defun sp-latex-skip-match-apostrophe (ms mb me)
(when (equal ms "'")
(save-excursion
(goto-char me)
(looking-at-p "\\sw"))))
(defun sp-latex-skip-double-quote (_1 action _2)
(when (eq action 'insert)
(when (looking-at-p "''''")
(delete-char -2)
(delete-char 2)
(forward-char 2))))
(defun sp-latex-point-after-backslash (id action context)
"Return t if point follows a backslash, nil otherwise.
This predicate is only tested on \"insert\" action."
(when (eq action 'insert)
(let ((trigger (sp-get-pair id :trigger)))
(looking-back (concat "\\\\" (regexp-quote (if trigger trigger id)))))))
(defun sp-latex-point-before-word-p (id action context)
"Return t if point is before a word while in navigate action."
(when (eq action 'navigate)
(looking-at-p "\\sw")))
(add-to-list 'sp-navigate-skip-match
'((tex-mode plain-tex-mode latex-mode) . sp--backslash-skip-match))
(sp-with-modes '(
tex-mode
plain-tex-mode
latex-mode
)
(sp-local-pair "`" "'"
:actions '(:rem autoskip)
:skip-match 'sp-latex-skip-match-apostrophe
:unless '(sp-latex-point-after-backslash
sp-latex-point-before-word-p))
;; math modes, yay. The :actions are provided automatically if
;; these pairs do not have global definitions.
(sp-local-pair "$" "$")
(sp-local-pair "\\[" "\\]" :unless '(sp-latex-point-after-backslash))
;; disable useless pairs. Maybe also remove " ' and \"?
(sp-local-pair "/*" nil :actions nil)
(sp-local-pair "\\\\(" nil :actions nil)
(sp-local-pair "'" nil :actions nil)
(sp-local-pair "\\\"" nil :actions nil)
;; quote should insert ``'' instead of double quotes. If we ever
;; need to insert ", C-q is our friend.
(sp-local-pair "``" "''"
:trigger "\""
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-skip-double-quote))
;; add the prefix function sticking to {} pair
(sp-local-pair "{" nil :prefix "\\\\\\(\\sw\\|\\s_\\)*")
;; pairs for big brackets. Needs more research on what pairs are
;; useful to add here. Post suggestions if you know some.
(sp-local-pair "\\left(" "\\right)"
:trigger "\\l("
:when '(sp-in-math-p)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left[" "\\right]"
:trigger "\\l["
:when '(sp-in-math-p)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left\\{" "\\right\\}"
:trigger "\\l{"
:when '(sp-in-math-p)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left|" "\\right|"
:trigger "\\l|"
:when '(sp-in-math-p)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\bigl(" "\\bigr)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\biggl(" "\\biggr)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Bigl(" "\\Bigr)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Biggl(" "\\Biggr)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\bigl[" "\\bigr]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\biggl[" "\\biggr]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Bigl[" "\\Bigr]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Biggl[" "\\Biggr]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\bigl\\{" "\\bigr\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\biggl\\{" "\\biggr\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Bigl\\{" "\\Bigr\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Biggl\\{" "\\Biggr\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\lfloor" "\\rfloor" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\lceil" "\\rceil" :post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\langle" "\\rangle" :post-handlers '(sp-latex-insert-spaces-inside-pair))
;; some common wrappings
(sp-local-tag "\"" "``" "''" :actions '(wrap))
(sp-local-tag "\\b" "\\begin{_}" "\\end{_}")
(sp-local-tag "bi" "\\begin{itemize}" "\\end{itemize}")
(sp-local-tag "be" "\\begin{enumerate}" "\\end{enumerate}"))
(provide 'smartparens-latex)
;;; smartparens-latex.el ends here

View File

@ -0,0 +1,89 @@
;;; smartparens-lua.el --- Additional configuration for Lua based modes.
;; Copyright (C) 2013-2014 Matus Goljer
;; Author: Matus Goljer <matus.goljer@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 3 August 2013
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Lua based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-lua)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;;
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;;
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(defun sp-lua-post-keyword-insert (id action _context)
(cond
((eq action 'insert)
(cond
((member id '("while" "for"))
(insert " do")
(save-excursion (newline-and-indent))
(backward-char 3))
((equal id "if")
(insert " then")
(save-excursion (newline-and-indent))
(backward-char 5))
((equal id "function")
(save-excursion (newline-and-indent))
(insert " "))))))
;; all the pairs are expanded only if followed by "SPC" event. This
;; will reduce false positives like 'dIFficult' to trigger.
(sp-with-modes '(lua-mode)
(sp-local-pair "if" "end"
:when '(("SPC"))
:unless '(sp-in-comment-p)
:post-handlers '(sp-lua-post-keyword-insert))
(sp-local-pair "function" "end"
:when '(("SPC"))
:unless '(sp-in-comment-p)
:post-handlers '(sp-lua-post-keyword-insert))
(sp-local-pair "for" "end"
:when '(("SPC"))
:unless '(sp-in-comment-p)
:post-handlers '(sp-lua-post-keyword-insert))
(sp-local-pair "while" "end"
:when '(("SPC"))
:unless '(sp-in-comment-p)
:post-handlers '(sp-lua-post-keyword-insert))
)
(provide 'smartparens-lua)
;;; smartparens-lua.el ends here

View File

@ -0,0 +1,6 @@
(define-package "smartparens" "20161009.858" "Automatic insertion, wrapping and paredit-like navigation with user defined pairs."
'((dash "2.12.1")
(cl-lib "0.3")))
;; Local Variables:
;; no-byte-compile: t
;; End:

View File

@ -0,0 +1,84 @@
;;; smartparens-python.el --- Additional configuration for Python based modes.
;; Copyright (C) 2015-2016 Matus Goljer
;; Author: Matus Goljer <matus.goljer@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 8 February 2015
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Python based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-python)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;;
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;;
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
;; Python has no sexp suffices. This fixes slurping
;; (|sys).path.append---the dot should not travel with the closing
;; paren
(--each '(python-mode inferior-python-mode)
(add-to-list 'sp-sexp-suffix (list it 'regexp "")))
(sp-with-modes 'python-mode
(sp-local-pair "'" "'" :unless '(sp-in-comment-p sp-in-string-quotes-p))
(sp-local-pair "\"\"\"" "\"\"\"")
(sp-local-pair "(" nil :pre-handlers '(sp-python-pre-slurp-handler))
(sp-local-pair "[" nil :pre-handlers '(sp-python-pre-slurp-handler)))
(defun sp-python-pre-slurp-handler (id action context)
(when (eq action 'slurp-forward)
;; If there was no space before, we shouldn't add on.
;; ok = enclosing, next-thing one being slurped into
;; (variables let-bound in `sp-forward-slurp-sexp').
(save-excursion
(when (and (= (sp-get ok :end) (sp-get next-thing :beg))
(equal (sp-get ok :op) (sp-get next-thing :op)))
(goto-char (sp-get ok :end))
(when (looking-back " ")
(delete-char -1))))))
(defadvice python-indent-dedent-line-backspace
(around sp-backward-delete-char-advice activate)
(if smartparens-strict-mode
(cl-letf (((symbol-function 'delete-backward-char)
(lambda (arg &optional killp)
(sp-backward-delete-char arg))))
ad-do-it)
ad-do-it))
(provide 'smartparens-python)
;;; smartparens-python.el ends here

View File

@ -0,0 +1,55 @@
;;; smartparens-racket.el --- Additional configuration for Racket based modes.
;; Copyright (C) 2015 Vikraman Choudhury
;; Author: Vikraman Choudhury <git@vikraman.org>
;; Maintainer: Vikraman Choudhury <git@vikraman.org>
;; Created: 26 Oct 2015
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Racket based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-racket)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;;
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;;
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(sp-with-modes '(racket-mode racket-repl-mode)
(sp-local-pair "`" nil :actions nil)
(sp-local-pair "#|" "|#"))
(provide 'smartparens-racket)
;;; smartparens-racket.el ends here

View File

@ -0,0 +1,374 @@
;;; smartparens-ruby.el --- Additional configuration for Ruby based modes.
;; Copyright (C) 2013-2014 Jean-Louis Giordano
;; Author: Jean-Louis Giordano <jean-louis@jawaninja.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Created: 16 June 2013
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Ruby based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-ruby)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;;
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(defun sp-ruby-forward-sexp ()
(interactive)
(if (boundp 'enh-ruby-forward-sexp)
(enh-ruby-forward-sexp)
(ruby-forward-sexp)))
(defun sp-ruby-backward-sexp ()
(interactive)
(if (boundp 'enh-ruby-backward-sexp)
(enh-ruby-backward-sexp)
(ruby-backward-sexp)))
(defun sp-ruby-maybe-one-space ()
(while (looking-back " ") (backward-char))
(when (or (looking-at-p " ")
(looking-at-p "}")
(looking-back "{"))
(save-excursion (just-one-space)))
(when (and (not (looking-back "^.?"))
(save-excursion
(backward-char 2)
(or (looking-at-p ".[^:] [.([,;]")
(looking-at-p ".. ::")
(looking-at-p ".[.@$] ")
(looking-at-p ":: "))))
(delete-char 1)))
(defun sp-ruby-delete-indentation (&optional arg)
"Better way of joining ruby lines"
(delete-indentation arg)
(sp-ruby-maybe-one-space))
(defun sp-ruby-block-post-handler (id action context)
"Handler for ruby block-like inserts"
(when (equal action 'insert)
(save-excursion
(newline)
(indent-according-to-mode))
(indent-according-to-mode))
(sp-ruby-post-handler id action context))
(defun sp-ruby-def-post-handler (id action context)
"Handler for ruby def-like inserts"
(when (equal action 'insert)
(save-excursion
(insert "x")
(newline)
(indent-according-to-mode))
(delete-char 1))
(sp-ruby-post-handler id action context))
(defun sp-ruby-post-handler (id action context)
(when (equal action 'barf-backward)
(sp-ruby-delete-indentation 1)
(indent-according-to-mode)
(save-excursion
(sp-backward-sexp) ; move to begining of current sexp
(sp-backward-sexp arg)
(sp-ruby-maybe-one-space)))
(when (equal action 'barf-forward)
(sp-get enc
(let ((beg-line (line-number-at-pos :beg-in))
(end-line (line-number-at-pos :end-in)))
(sp-forward-sexp arg)
(sp-ruby-maybe-one-space)
(when (not (= (line-number-at-pos) beg-line))
(sp-ruby-delete-indentation -1))
(indent-according-to-mode)))))
(defun sp-ruby-pre-handler (id action context)
"Handler for ruby slurp and barf"
(sp-get enc
(let ((beg-line (line-number-at-pos :beg-in))
(end-line (line-number-at-pos :end-in)))
(when (equal action 'slurp-backward)
(save-excursion
(sp-forward-sexp)
(when (looking-at-p ";") (forward-char))
(sp-ruby-maybe-one-space)
(when (not (= (line-number-at-pos) end-line))
(sp-ruby-delete-indentation -1)))
(while (thing-at-point-looking-at "\\.[ \n]*")
(sp-backward-sexp))
(when (looking-back "[@$:&?!]")
(backward-char)
(when (looking-back "[@&:]")
(backward-char)))
(just-one-space)
(save-excursion
(if (= (line-number-at-pos) end-line)
(insert " ")
(newline))))
(when (equal action 'barf-backward)
;; Barf whole method chains
(while (thing-at-point-looking-at "[.([:][ \n]*")
(sp-forward-sexp))
(if (looking-at-p " *$")
(newline)
(save-excursion (newline))))
(when (equal action 'slurp-forward)
(save-excursion
(sp-backward-sexp)
(when (looking-back "\.") (backward-char))
(sp-ruby-maybe-one-space)
(when (not (= (line-number-at-pos) beg-line))
(if (thing-at-point-looking-at "\\.[ \n]*")
(progn
(forward-symbol -1)
(sp-ruby-delete-indentation -1))
(sp-ruby-delete-indentation))))
(while (looking-at-p "::") (sp-forward-symbol))
(when (looking-at-p "[?!;]") (forward-char))
(if (= (line-number-at-pos) beg-line)
(insert " ")
(newline)))
(when (equal action 'barf-forward)
(when (looking-back "\\.") (backward-char))
(while (looking-back "::") (sp-backward-symbol))
(if (= (line-number-at-pos) end-line)
(insert " ")
(if (looking-back "^ *")
(save-excursion (newline))
(newline)))))))
(defun sp-ruby-inline-p (id)
(save-excursion
(when (looking-back id)
(backward-word))
(when (not (or (looking-back "^ *")
(looking-back "= *")))
(or (save-excursion
(forward-symbol -1)
(forward-symbol 1)
(looking-at-p (concat " *" id)))
(save-excursion
;; This does not seem to make emacs snapshot happy
(ignore-errors
(sp-ruby-backward-sexp)
(sp-ruby-forward-sexp)
(looking-at-p (concat "[^ ]* *" id))))))))
(defun sp-ruby-method-p (id)
(save-excursion
(when (looking-back id)
(backward-word))
(and (looking-at-p id)
(or
;; fix for def_foo
(looking-at-p (concat id "[_?!:]"))
;; fix for foo_def
(looking-back "[_:@$.]")
;; fix for def for; end
(looking-back "def \\|class \\|module ")
;; Check if multiline method call
;; But beware of comments!
(and (looking-back "\\.[ \n]*")
(not (save-excursion
(search-backward ".")
(sp-point-in-comment))))))))
(defun sp-ruby-skip-inline-match-p (ms mb me)
(or (sp-ruby-method-p ms)
(sp-ruby-inline-p ms)))
(defun sp-ruby-skip-method-p (ms mb me)
(sp-ruby-method-p ms))
(defun sp-ruby-in-string-or-word-p (id action context)
(or (sp-in-string-p id action context)
(and (looking-back id)
(not (looking-back (sp--strict-regexp-quote id))))
(sp-ruby-method-p id)))
(defun sp-ruby-in-string-word-or-inline-p (id action context)
(or (sp-ruby-in-string-or-word-p id action context)
(and (looking-back id)
(sp-ruby-inline-p id))))
(defun sp-ruby-pre-pipe-handler (id action context)
(when (equal action 'insert)
(save-excursion
(just-one-space))
(save-excursion
(search-backward id)
(just-one-space))))
(defun sp-ruby-should-insert-pipe-close (id action _ctx)
"Test whether to insert the closing pipe for a lambda-binding pipe pair."
(if (eq action 'insert)
(thing-at-point-looking-at
(rx-to-string `(and (or "do" "{") (* space) ,id)))
t))
(defun sp--ruby-skip-match (ms me mb)
(when (string= ms "end")
(or (sp-in-string-p ms me mb)
(sp-ruby-method-p "end"))))
(add-to-list 'sp-navigate-skip-match
'((ruby-mode enh-ruby-mode motion-mode) . sp--ruby-skip-match))
(dolist (mode '(ruby-mode motion-mode))
(add-to-list 'sp-sexp-suffix `(,mode syntax "")))
(sp-with-modes '(ruby-mode enh-ruby-mode motion-mode)
(sp-local-pair "do" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-block-post-handler)
:skip-match 'sp-ruby-skip-method-p
:suffix "")
(sp-local-pair "{" "}"
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-post-handler)
:suffix "")
(sp-local-pair "begin" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-block-post-handler)
:skip-match 'sp-ruby-skip-method-p
:suffix "")
(sp-local-pair "def" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-method-p
:suffix "")
(sp-local-pair "class" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-method-p
:suffix "")
(sp-local-pair "module" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-method-p
:suffix "")
(sp-local-pair "case" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-method-p
:suffix "")
(sp-local-pair "for" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-or-word-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-inline-match-p)
(sp-local-pair "if" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-word-or-inline-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-inline-match-p
:suffix "")
(sp-local-pair "unless" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-word-or-inline-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-inline-match-p
:suffix "")
(sp-local-pair "while" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-word-or-inline-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-inline-match-p
:suffix "")
(sp-local-pair "until" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:unless '(sp-ruby-in-string-word-or-inline-p sp-in-comment-p)
:actions '(insert navigate)
:pre-handlers '(sp-ruby-pre-handler)
:post-handlers '(sp-ruby-def-post-handler)
:skip-match 'sp-ruby-skip-inline-match-p
:suffix "")
(sp-local-pair "|" "|"
:when '(sp-ruby-should-insert-pipe-close)
:pre-handlers '(sp-ruby-pre-pipe-handler)
:suffix ""))
(dolist (mode '(ruby-mode motion-mode))
(add-to-list 'sp-navigate-consider-stringlike-sexp mode))
(provide 'smartparens-ruby)
;;; smartparens-ruby.el ends here

View File

@ -0,0 +1,96 @@
;;; smartparens-rust.el --- Additional configuration for Haskell based modes.
;; Copyright (C) 2015 Wilfred Hughes
;; Created: 3 November 2015
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Rust. To use
;; it, simply add:
;;
;; (require 'smartparens-config)
;;
;; alternatively, you can explicitly load these preferences:
;;
;; (require 'smartparens-rust)
;;
;; in your configuration.
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
(defun sp-in-rust-lifetime-context (&rest args)
"Return t if point is in a Rust context where ' represents a lifetime.
If we return nil, ' should be used for character literals."
(or
(condition-case nil
;; If point is just after a &', it's probably a &'foo.
(save-excursion
(backward-char 2)
(looking-at "&"))
;; If we're at the beginning of the buffer, just carry on.
(beginning-of-buffer))
;; If point is inside < > it's probably a parameterised function.
(let ((paren-pos (nth 1 (syntax-ppss))))
(and paren-pos
(save-excursion
(goto-char paren-pos)
(looking-at "<"))))))
(defun sp-rust-filter-angle-brackets (id action context)
"Return t if we should allow the ACTION in the current CONTEXT
for angle brackets."
(cond
;; Disallow in format string after any character, since < is used to specify
;; alignment
((and (eq context 'string)
(looking-back (rx (seq alphanumeric "<")))) nil)
;; Disallow when inserting in code in two situations: 1) when '<' is used for
;; the comparison operators '<' and '<=', and 2) when writing a left shift
;; '<<'. In both cases, we assume the user will use a space before the
;; opening bracket '<'.
((and (eq context 'code)
(eq action 'insert)
(looking-back (rx (or (seq space "<")
(seq space "<<"))))) nil)
;; Otherwise, allow all actions
(t)))
(sp-with-modes '(rust-mode)
(sp-local-pair "'" "'" :unless '(sp-in-comment-p sp-in-string-quotes-p sp-in-rust-lifetime-context) :post-handlers'(:rem sp-escape-quotes-after-insert))
(sp-local-pair "<" ">" :when '(sp-rust-filter-angle-brackets)))
;; Rust has no sexp suffices. This fixes slurping
;; (|foo).bar -> (foo.bar)
(add-to-list 'sp-sexp-suffix (list #'rust-mode 'regexp ""))
(provide 'smartparens-rust)
;;; smartparens-rust.el ends here

View File

@ -0,0 +1,57 @@
;;; smartparens-scala.el --- Additional configuration for Scala based modes.
;; Copyright (C) 2015 Greg Nwosu
;; Author: Greg Nwosu <greg.nwosu@gmail.com>
;; Maintainer: Greg Nwosu <greg.nwosu@gmail.com>
;; Created: 8 July 2015
;; Keywords: abbrev convenience editing
;; URL: https://github.com/Fuco1/smartparens
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of Smartparens.
;; Smartparens 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.
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides some additional configuration for Scala based
;; modes. To use it, simply add:
;;
;; (require 'smartparens-scala)
;;
;; into your configuration. You can use this in conjunction with the
;; default config or your own configuration.
;;
;; If you have good ideas about what should be added please file an
;; issue on the github tracker.
;;
;; For more info, see github readme at
;; https://github.com/Fuco1/smartparens
;;; Code:
(require 'smartparens)
;; Scala has no sexp suffices. This fixes slurping
;; import scala.mutable{|} ListBuffer, Set ---the comma should not travel with the closing
;; paren
(--each '(scala-mode inferior-scala-mode)
(add-to-list 'sp-sexp-suffix (list it 'regexp "")))
(provide 'smartparens-scala)
;;; smartparens-scala.el ends here

File diff suppressed because it is too large Load Diff

11
init.el
View File

@ -114,6 +114,11 @@
(require 'zone)
(require 'magithub)
(require 'origami)
(use-package smartparens-config
:ensure smartparens
:config
(progn
(show-smartparens-global-mode t)))
;; Load my own functions
(load "gnu-c-header.el")
@ -211,6 +216,12 @@
(c-add-style "PERSONAL" my-c-style)
(setq c-offset-alist '((member-init-intro . ++)))
;; smartparen stuff
(add-hook 'prog-mode-hook
'turn-on-smartparens-strict-mode)
(add-hook 'markdown-mode-hook
'turn-on-smartparens-strict-mode)
;; Custom key bindings
(global-set-key (kbd "C-x _") 'maximize-window)
;; Some terminals dont interpret Alt-Up/Down as M-<up/down>.