Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latex fixes #1151

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
55 changes: 11 additions & 44 deletions smartparens-latex.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,6 @@
(goto-char (sp-get sp-last-wrapped-region :beg-in))
(insert " "))))

(defun sp-latex-skip-match-apostrophe (ms _mb me)
"MS, MB, ME."
(when (equal ms "'")
(save-excursion
(goto-char me)
(looking-at-p "\\sw"))))

(defun sp-latex-skip-double-quote (_id action _context)
"ID, ACTION, CONTEXT."
(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.
Expand All @@ -88,43 +73,31 @@ ID, ACTION, CONTEXT."
(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
LaTeX-mode
)
(sp-local-pair "`" "'"
:actions '(:rem autoskip)
:skip-match 'sp-latex-skip-match-apostrophe
:unless '(sp-latex-point-after-backslash sp-in-math-p))
;; math modes, yay. The :actions are provided automatically if
(sp-with-modes '(tex-mode plain-tex-mode latex-mode LaTeX-mode)
;; Disable pairs that interfere with AucTeX.
(sp-local-pair "`" nil :actions nil)
(sp-local-pair "\"" nil :actions nil)

;; 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.
;; Disable useless pairs.
(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 sp-in-math-p)
:post-handlers '(sp-latex-skip-double-quote))

;; add the prefix function sticking to {} pair
;; Add the prefix function sticking to {} pair.
(sp-local-pair "{" nil :prefix "\\\\\\(\\sw\\|\\s_\\)*")

;; do not add more space when slurping
;; Do not add more space when slurping.
(sp-local-pair "{" "}")
(sp-local-pair "(" ")")
(sp-local-pair "[" "]")

;; pairs for big brackets. Needs more research on what pairs are
;; 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("
Expand Down Expand Up @@ -179,13 +152,7 @@ ID, ACTION, CONTEXT."
(sp-local-pair "\\lvert" "\\rvert"
: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}"))
:post-handlers '(sp-latex-insert-spaces-inside-pair)))

(provide 'smartparens-latex)

Expand Down