diff --git a/README.org b/README.org index 844ba92..35a2ef3 100644 --- a/README.org +++ b/README.org @@ -6,7 +6,7 @@ [[file:images/logo.png]] * About Smart Mode -Currently this project is rewriting for providing smart mode on branch `v3`. +Currently this project is rewriting for providing smart mode on branch `smart`. * Demo [[file:images/demo.gif]] diff --git a/parinfer-ext.el b/parinfer-ext.el index 53ba1b1..62c6d6a 100644 --- a/parinfer-ext.el +++ b/parinfer-ext.el @@ -186,28 +186,29 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." (parinfer-lispy:paren-char-p ca) (parinfer-lispy:paren-char-p cb)))) -(defun parinfer-lispy:parens () - (interactive) - (if (region-active-p) +(defun parinfer-lispy:parens (arg) + (interactive "P") + (if (or (region-active-p) arg) (call-interactively 'lispy-parens) (call-interactively 'self-insert-command))) -(defun parinfer-lispy:brackets () - (interactive) - (if (region-active-p) +(defun parinfer-lispy:brackets (arg) + (interactive "P") + (if (or (region-active-p) arg) (call-interactively 'lispy-brackets) (call-interactively 'self-insert-command))) -(defun parinfer-lispy:braces () - (interactive) - (if (region-active-p) +(defun parinfer-lispy:braces (arg) + (interactive "P") + (if (or (region-active-p) arg) (call-interactively 'lispy-braces) (call-interactively 'self-insert-command))) (defun parinfer-lispy:init () - (if (package-installed-p 'lispy) + (if (fboundp 'lispy-mode) (progn - (require 'lispy) + (mapc (lambda (x) (lispy-define-key parinfer-mode-map (format "%d" x) 'digit-argument)) + (number-sequence 0 9)) (define-key parinfer-mode-map (kbd "(") 'parinfer-lispy:parens) (define-key parinfer-mode-map (kbd "{") 'parinfer-lispy:braces) (define-key parinfer-mode-map (kbd "[") 'parinfer-lispy:brackets) @@ -230,24 +231,27 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." (define-key parinfer-mode-map (kbd "M-m") 'lispy-mark-symbol) (define-key parinfer-mode-map (kbd "b") 'special-lispy-back) (define-key parinfer-mode-map (kbd "f") 'special-lispy-flow) - (define-key parinfer-mode-map (kbd "f") 'special-lispy-flow) (define-key parinfer-mode-map (kbd "e") 'special-lispy-eval) (define-key parinfer-mode-map (kbd "o") 'special-lispy-other-mode) (define-key parinfer-mode-map (kbd "O") 'special-lispy-oneline) (define-key parinfer-mode-map (kbd "M") 'special-lispy-alt-multiline) (define-key parinfer-mode-map (kbd "y") 'special-lispy-occur) + (define-key parinfer-mode-map (kbd "i") 'special-lispy-tab) (define-key parinfer-mode-map (kbd "r") 'special-lispy-raise) (define-key parinfer-mode-map (kbd "C-a") 'lispy-move-beginning-of-line) (define-key parinfer-mode-map (kbd "g") 'special-lispy-goto) (define-key parinfer-mode-map (kbd ">") 'special-lispy-slurp) (define-key parinfer-mode-map (kbd "<") 'special-lispy-barf) (define-key parinfer-mode-map (kbd "n") 'special-lispy-new-copy) - (define-key parinfer-mode-map (kbd "SPC" )'parinfer-lispy:space)) + (define-key parinfer-mode-map (kbd "t") 'special-lispy-teleport) + (define-key parinfer-mode-map (kbd "H") 'special-lispy-ace-symbol-replace) + (define-key parinfer-mode-map (kbd "p") 'special-lispy-paste) + (define-key parinfer-mode-map (kbd "/") 'special-lispy-splice) + (define-key parinfer-mode-map (kbd "SPC") 'parinfer-lispy:space)) (message "Parinfer extension lispy: It seems Lispy is not installed!"))) (parinfer-define-extension lispy "Integration with Lispy." - :mount (require 'eldoc) (eldoc-add-command-completions "lispy-" "parinfer-") @@ -268,12 +272,13 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." "Integration with Evil." :mount (parinfer-strategy-add 'default - 'evil-delete-char) + '(evil-delete-char evil-shift-left evil-shift-right evil-shift-right-line + evil-shift-left-line)) (parinfer-strategy-add 'instantly '(evil-delete evil-change evil-change-line evil-paste-before evil-paste-after evil-delete-line evil-delete-char evil-delete-backward-char evil-substitute evil-change-whole-line evil-force-normal-state evil-normal-state - evil-shift-left evil-shift-right)) + evil-exit-visual-state)) (parinfer-strategy-add 'skip '(evil-previous-line evil-forward-char evil-backward-char evil-next-line evil-forward-word evil-forward-word-begin evil-backward-word-begin @@ -355,7 +360,7 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." (save-excursion (end-of-line) (while (eq (char-before) 32) - (backward-delete-char 1))) + (backward-delete-char 1))) (save-excursion (parinfer--goto-line parinfer-smart-tab:indicator-line) (when (parinfer--empty-line-p) @@ -486,7 +491,7 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." (delete-indentation) (backward-char)) (end-of-line) - (while (eq 32 (char-before)) + (while (eq 32 (char-before)) (backward-delete-char 1)) (-distinct pos-list)))))) @@ -665,7 +670,10 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." (define-key parinfer-mode-map [remap backward-char] 'parinfer-smart-tab:backward-char) (define-key parinfer-region-mode-map [remap parinfer-shift-right] 'parinfer-smart-tab:shift-right) (define-key parinfer-region-mode-map [remap parinfer-shift-left] 'parinfer-smart-tab:shift-left) - + (if (fboundp 'evil-define-key) + (progn (evil-define-key 'insert parinfer-region-mode-map [remap evil-shift-right-line] 'parinfer-smart-tab:shift-right) + (evil-define-key 'insert parinfer-region-mode-map [remap evil-shift-left-line] 'parinfer-smart-tab:shift-left))) + :unmount (remove-hook 'post-command-hook 'parinfer-smart-tab:clean-indicator t) (remove-hook 'pre-command-hook 'parinfer-smart-tab:clean-indicator-pre t)) @@ -757,7 +765,7 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." (forward-sexp) (insert (parinfer-one:get-close-paren key))) (parinfer-one:paren))) - + ((-contains-p parinfer-one:indent-trigger-keys key) (progn (parinfer--invoke-parinfer-when-necessary))) @@ -831,15 +839,7 @@ Use rainbow-delimiters for Paren Mode, and dim-style parens for Indent Mode." :unmount (remove-hook 'post-command-hook 'parinfer-one:invoke-when-necessary-auto t) (remove-hook 'pre-command-hook 'parinfer-one:update-context t)) - + (provide 'parinfer-ext) ;;; parinfer-ext.el ends here - - - - - - - - diff --git a/parinfer.el b/parinfer.el index 79dbd0d..44764cd 100644 --- a/parinfer.el +++ b/parinfer.el @@ -118,8 +118,8 @@ close-parens after it.") (defvar parinfer-strategy '((default - self-insert-command delete-indentation kill-line - comment-dwim kill-word delete-char newline kill-region comment-or-uncomment-region newline-and-indent) + self-insert-command delete-indentation kill-line comment-line + comment-dwim kill-word delete-char newline kill-region comment-or-uncomment-region newline-and-indent) (instantly delete-region newline) (skip)) @@ -858,11 +858,18 @@ If There's no change, switch to Indent Mode." (text (buffer-substring-no-properties (point-min) (point-max))) (result (parinferlib-indent-mode text opts)) (success (plist-get result :success)) + (err (plist-get result :error)) + (error-message (plist-get err :message)) + (error-line-no (plist-get err :line-no)) (changed-lines (plist-get result :changed-lines))) (if (not success) (progn - (message (concat "Parinfer: Pairs unmatched, switch to Paren mode. " - "When pair fixed, You can switch to indent mode.")) + (message (concat "Parinfer: Error%s: \"%s\" - switch to Paren mode. " + "When error fixed, you can switch to indent mode.") + (if (null error-line-no) + "" + (format " on line %d" error-line-no)) + error-message) nil) (if (and changed-lines (not (string= text (plist-get result :text)))) @@ -886,11 +893,18 @@ If there's any change, display a confirm message in minibuffer." (text (buffer-substring-no-properties (point-min) (point-max))) (result (parinferlib-indent-mode text opts)) (success (plist-get result :success)) + (err (plist-get result :error)) + (error-message (plist-get err :message)) + (error-line-no (plist-get err :line-no)) (changed-lines (plist-get result :changed-lines))) (if (not success) (progn - (message (concat "Pairs unmatched, switch to Paren mode. " - "When pair fixed, You can switch to indent mode.")) + (message (concat "Parinfer: Error%s: \"%s\" - switch to Paren mode. " + "When error fixed, you can switch to indent mode.") + (if (null error-line-no) + "" + (format " on line %d" error-line-no)) + error-message) nil) (if (and changed-lines (not (string= text (plist-get result :text)))) @@ -1032,12 +1046,6 @@ invoke parinfer after every semicolon input." (parinfer--invoke-parinfer)))) (call-interactively 'self-insert-command))) -(defun parinfer-delete-indentation () - "Replacement in 'parinfer-mode' for 'delete-indentation' command." - (interactive) - (parinfer-paren-run - (call-interactively 'delete-indentation))) - (defun parinfer-toggle-mode () "Switch parinfer mode between Indent Mode and Paren Mode." (interactive)