Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cask
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(source melpa)
(source gnu)

(package "smartparens" "1.11.0"
(package "smartparens" ""
"Automatic insertion, wrapping and paredit-like navigation with user defined pairs.")

(depends-on "cl-lib" "0.3")
Expand Down
7 changes: 4 additions & 3 deletions smartparens-config.el
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,15 @@ ID, ACTION, CONTEXT."
(eval-after-load it '(require 'smartparens-erlang)))
(eval-after-load 'ess '(require 'smartparens-ess))
(eval-after-load 'go-mode '(require 'smartparens-go))
(eval-after-load 'haskell-interactive-mode '(require 'smartparens-haskell))
(eval-after-load 'haskell-mode '(require 'smartparens-haskell))
(--each '(haskell-mode haskell-interactive-mode purescript-mode)
(eval-after-load it '(require 'smartparens-haskell)))
(--each sp--html-modes
(eval-after-load it '(require 'smartparens-html)))
(eval-after-load 'latex '(require 'smartparens-latex))
(eval-after-load 'lua-mode '(require 'smartparens-lua))
(eval-after-load 'lua-ts-mode '(require 'smartparens-lua))
(eval-after-load 'markdown-mode '(require 'smartparens-markdown))
(--each '(markdown-mode markdown-ts-mode)
(eval-after-load it '(require 'smartparens-markdown)))
(--each '(python-mode python-ts-mode python)
(eval-after-load it '(require 'smartparens-python)))
(eval-after-load 'org '(require 'smartparens-org))
Expand Down
8 changes: 8 additions & 0 deletions smartparens-haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ So we ignore that pair when at the end of word."
:skip-match 'sp-haskell-skip-apostrophe)
(sp-local-pair "\\(" nil :actions nil))

(sp-with-modes 'purescript-mode
(sp-local-pair "'" nil
:unless '(sp-point-after-word-p
sp-haskell-strict-ignore-apostrophe-after-word)
:skip-match 'sp-haskell-skip-apostrophe)
(sp-local-pair "\\{" nil :actions nil)
(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)
Expand Down
98 changes: 80 additions & 18 deletions smartparens-latex.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,37 @@
(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.
(defun sp-number-of-backslashes-before-point ()
(let ((p (point)))
(while (and (> p 0) (equal (char-before p) ?\\ ))
(setq p (- p 1)))
(- (point) p)))

(defun sp-evenp (num)
(eq (% num 2) 0))

(defun sp--latex-backslash-skip-match (ms mb _me)
"Skips a match if preceeded by uneven number of backslashes."
(and ms
(save-excursion
(goto-char mb)
(not (sp-evenp (sp-number-of-backslashes-before-point))))))

(defun sp-latex-point-after-backslash (id action context)
"Return t if point follows an uneven number of backslashes (a
double backslash is a newline; we'd like to ignore those), nil
otherwise. This predicate is only tested on \"insert\" action.
ID, ACTION, CONTEXT."
(when (eq action 'insert)
(let ((trigger (sp-get-pair id :trigger)))
(looking-back (concat "\\\\" (regexp-quote (if trigger trigger id))) nil))))
(let* ((trigger (sp-get-pair id :trigger))
(start (- (point) (length (if trigger trigger id)))))
(when (> start 1)
(save-excursion
(goto-char start)
(not (sp-evenp (sp-number-of-backslashes-before-point))))))))

(add-to-list 'sp-navigate-skip-match
'((tex-mode plain-tex-mode latex-mode) . sp--backslash-skip-match))
'((tex-mode plain-tex-mode latex-mode) . sp--latex-backslash-skip-match))

(sp-with-modes '(
tex-mode
Expand All @@ -100,7 +121,8 @@ ID, ACTION, CONTEXT."
:unless '(sp-latex-point-after-backslash sp-in-math-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))
(sp-local-pair "\\[" "\\]"
:unless '(sp-latex-point-after-backslash))

Expand All @@ -117,72 +139,112 @@ ID, ACTION, CONTEXT."
:post-handlers '(sp-latex-skip-double-quote))

;; add the prefix function sticking to {} pair
(sp-local-pair "{" nil :prefix "\\\\\\(\\sw\\|\\s_\\)*")
(sp-local-pair "{" "}"
:prefix "\\\\\\(\\sw\\|\\s_\\)*"
:unless '(sp-latex-point-after-backslash))

;; do not add more space when slurping
(sp-local-pair "{" "}")
(sp-local-pair "(" ")")
(sp-local-pair "[" "]")
(sp-local-pair "\\{" "\\}"
:unless '(sp-latex-point-after-backslash))
(sp-local-pair "[" "]"
:unless '(sp-latex-point-after-backslash))
(sp-local-pair "(" ")"
:unless '(sp-latex-point-after-backslash))
(sp-local-pair "\\(" "\\)"
:unless '(sp-latex-point-after-backslash))

;; 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)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left[" "\\right]"
:trigger "\\l["
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left\\{" "\\right\\}"
:trigger "\\l{"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\left|" "\\right|"
:trigger "\\l|"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\bigl(" "\\bigr)"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\biggl(" "\\biggr)"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Bigl(" "\\Bigr)"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Biggl(" "\\Biggr)"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\bigl[" "\\bigr]"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\biggl[" "\\biggr]"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Bigl[" "\\Bigr]"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Biggl[" "\\Biggr]"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\bigl\\{" "\\bigr\\}"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\biggl\\{" "\\biggr\\}"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Bigl\\{" "\\Bigr\\}"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\Biggl\\{" "\\Biggr\\}"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\lfloor" "\\rfloor"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\lceil" "\\rceil"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\langle" "\\rangle"
:when '(sp-in-math-p)
:unless '(sp-latex-point-after-backslash)
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\lVert" "\\rVert"
:when '(sp-in-math-p)
:trigger "\\lVert"
:post-handlers '(sp-latex-insert-spaces-inside-pair))
:when '(sp-in-math-p)
:trigger "\\lVert"
:post-handlers '(sp-latex-insert-spaces-inside-pair))
(sp-local-pair "\\lvert" "\\rvert"
:when '(sp-in-math-p)
:trigger "\\lvert"
:post-handlers '(sp-latex-insert-spaces-inside-pair))
:when '(sp-in-math-p)
:trigger "\\lvert"
: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}"))
Expand Down
4 changes: 2 additions & 2 deletions smartparens-markdown.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ This predicate is only tested on \"insert\" action."
(goto-char mb)
(save-match-data (looking-at "^\\* "))))

(sp-with-modes '(markdown-mode gfm-mode)
(sp-with-modes '(markdown-mode markdown-ts-mode gfm-mode)
(sp-local-pair "*" "*"
:unless '(sp--gfm-point-after-word-p sp-point-at-bol-p)
:post-handlers '(("[d1]" "SPC"))
:skip-match 'sp--gfm-skip-asterisk)
(sp-local-pair "**" "**")
(sp-local-pair "_" "_" :unless '(sp-point-after-word-p)))

(sp-with-modes 'markdown-mode
(sp-with-modes '(markdown-mode markdown-ts-mode)
(sp-local-pair "```" "```"))

(sp-with-modes 'gfm-mode
Expand Down
1 change: 1 addition & 0 deletions smartparens-pkg.el
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
(define-package "smartparens" "1.11.0" "Automatic insertion, wrapping and paredit-like navigation with user defined pairs."
'((dash "2.13.0")))

1 change: 1 addition & 0 deletions smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ Symbol is defined as a chunk of text recognized by
(defcustom sp-no-reindent-after-kill-modes '(
python-mode
python-ts-mode
purescript-mode
coffee-mode
asm-mode
makefile-gmake-mode
Expand Down