diff options
author | Eduardo Julian | 2020-11-17 20:23:53 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-11-17 20:23:53 -0400 |
commit | d89d837de3475b75587a4293e094d755d2cd4626 (patch) | |
tree | 0975a487d987cfe855c4f6e87f05478346913a16 /lux-mode | |
parent | 2e5852abb1ac0ae5abdd8709238aca447f62520e (diff) |
Made the syntax of ^template more consistent.
Diffstat (limited to 'lux-mode')
-rw-r--r-- | lux-mode/lux-mode.el | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index 65aa29b33..4d1e9bbc6 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -151,13 +151,91 @@ ENDP and DELIM." t)) t)) +(defun lux-enable-paredit-backslash () + "Getting paredit to work with backslashes (\)" + (advice-add 'paredit-backslash :around + (lambda (self &rest inputs) + (if (derived-mode-p 'lux-mode) + (insert ?\\) + (apply self inputs)))) + (advice-add 'paredit-in-string-escape-p :around + (lambda (self &rest inputs) + (if (derived-mode-p 'lux-mode) + nil + (apply self inputs)))) + (advice-add 'paredit-unescape-string :around + (lambda (self &rest inputs) + (if (derived-mode-p 'lux-mode) + nil + (apply self inputs)))) + ;; This codes originates from Paredit, but I had to modify it so it stops messing with backslashes (\). + (advice-add 'paredit-forward-delete-in-string :around + (lambda (self &rest inputs) + (if (derived-mode-p 'lux-mode) + (let ((start+end (paredit-string-start+end-points))) + (cond ((not (eq (point) (cdr start+end))) + (delete-char +1)) + ((eq (1- (point)) (car start+end)) + (delete-char -1) + (delete-char +1)))) + (apply self inputs)))) + (advice-add 'paredit-forward-delete :around + (lambda (self &optional argument) + (if (derived-mode-p 'lux-mode) + (progn + (interactive "P") + (cond ((or (consp argument) (eobp)) + (delete-char +1)) + ((integerp argument) + (if (< argument 0) + (paredit-backward-delete argument) + (while (> argument 0) + (paredit-forward-delete) + (setq argument (- argument 1))))) + ((paredit-in-string-p) + (paredit-forward-delete-in-string)) + ((paredit-in-comment-p) + (paredit-forward-delete-in-comment)) + ((let ((syn (char-syntax (char-after)))) + (or (eq syn ?\( ) + (eq syn ?\" ))) + (if (save-excursion + (paredit-handle-sexp-errors (progn (forward-sexp) t) + nil)) + (forward-char) + (message "Deleting spurious opening delimiter.") + (delete-char +1))) + ((and (not (paredit-in-char-p (1- (point)))) + (eq (char-syntax (char-after)) ?\) ) + (eq (char-before) (matching-paren (char-after)))) + (delete-char -1) ; Empty list -- delete both + (delete-char +1)) ; delimiters. + ((eq ?\; (char-after)) + (paredit-forward-delete-comment-start)) + ((eq (char-syntax (char-after)) ?\) ) + (if (paredit-handle-sexp-errors + (save-excursion (forward-char) (backward-sexp) t) + nil) + (message "End of list!") + (progn + (message "Deleting spurious closing delimiter.") + (delete-char +1)))) + ;; Just delete a single character, if it's not a closing + ;; delimiter. (The character literal case is already handled + ;; by now.) + (t (delete-char +1)))) + (funcall self argument)))) + ) + (defun lux-paredit-setup () "Make \"paredit-mode\" play nice with `lux-mode'." (when (>= paredit-version 21) (define-key lux-mode-map "{" #'paredit-open-curly) (define-key lux-mode-map "}" #'paredit-close-curly) (add-to-list 'paredit-space-for-delimiter-predicates - #'lux-space-for-delimiter-p))) + #'lux-space-for-delimiter-p) + (lux-enable-paredit-backslash) + )) (defun lux-mode-variables () "Set up initial buffer-local variables for Lux mode." |