branch: scratch/smartparens commit 2ee354c4f91eac25e06d02514047b1e176a3cdbd Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Use `advice-add` instead of `defadvice` (#1143) Also remove `smartparens-pkg.el` and dependency on `f`. * .gitignore: Add ELPA-generated files. * smartparens-pkg.el: Delete file, it's auto-generated (better) by MELPA and NonGNU ELPA scripts anyway. * smartparens.el: Add `nadvice` as dependency (maybe we should require Emacs-24.4 instead?). (cua-replace-region, cua-delete-region, delete-backward-char) (haskell-indentation-delete-backward-char, company--insert-candidate) (hippie-expand): Use `advice-add`. * smartparens-python.el (python-indent-dedent-line-backspace): * smartparens-ess.el (sp-backward-kill-symbol):Use `advice-add`. * test/smartparens-crystal-test.el: Don't require `cystal-mode` before we actually load the file. * test/smartparens-ess-test.el (sp-ess-lisp-path): * test/test-helper.el (sp-dir): Remove dependency on `f`. (TeX-update-style): Use `advice-add`. --- .gitignore | 4 ++++ smartparens-ess.el | 5 +++-- smartparens-pkg.el | 2 -- smartparens-python.el | 9 ++++---- smartparens.el | 44 ++++++++++++++++++++++------------------ test/smartparens-crystal-test.el | 2 +- test/smartparens-ess-test.el | 5 ++--- test/test-helper.el | 12 +++++++---- 8 files changed, 47 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 64bc594f5a..a672de391d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ docs/_build .eask .cask .elsa + +# ELPA-generated files +/smartparens-pkg.el +/smartparens-autoloads.el diff --git a/smartparens-ess.el b/smartparens-ess.el index 9d5de2c4a1..b3f1ff0659 100644 --- a/smartparens-ess.el +++ b/smartparens-ess.el @@ -53,12 +53,13 @@ (list mode 'regexp (rx (zero-or-more (or word (syntax symbol))))))) -(defadvice sp-backward-kill-symbol (around sp-ess-backward-kill-symbol activate) +(advice-add 'sp-backward-kill-symbol :around #'sp--ess-backward-kill-symbol) +(defun sp--ess-backward-kill-symbol (orig-fun &rest args) "#821 For the purpose of killing words and symbols, we remove the prefix resolution because it is not necessary. We want to treat function prefix as word or symbol to be deleted." (let ((sp-sexp-prefix nil)) - ad-do-it)) + (apply orig-fun args))) ;; slurping follows Google's R style guide ;; see https://google.github.io/styleguide/Rguide.xml diff --git a/smartparens-pkg.el b/smartparens-pkg.el deleted file mode 100644 index b7fc2409b9..0000000000 --- a/smartparens-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -(define-package "smartparens" "1.11.0" "Automatic insertion, wrapping and paredit-like navigation with user defined pairs." - '((dash "2.13.0"))) diff --git a/smartparens-python.el b/smartparens-python.el index 2c342b1336..6dc397a5b3 100644 --- a/smartparens-python.el +++ b/smartparens-python.el @@ -119,15 +119,16 @@ newly formed pair (which was a single-quote \"...\" pair)." (goto-char :beg) (insert (make-string 2 (aref id 0))))))))) -(defadvice python-indent-dedent-line-backspace - (around sp-backward-delete-char-advice activate) +(advice-add 'python-indent-dedent-line-backspace + :around #'sp--backward-delete-char-advice) +(defun sp--backward-delete-char-advice (orig-fun &rest args) "Fix indend." (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)) + (apply orig-fun args)) + (apply orig-fun args))) (provide 'smartparens-python) ;;; smartparens-python.el ends here diff --git a/smartparens.el b/smartparens.el index 9cdc8dfbdf..c7b0d89776 100644 --- a/smartparens.el +++ b/smartparens.el @@ -6,7 +6,7 @@ ;; Maintainer: Matus Goljer <matus.gol...@gmail.com> ;; Created: 17 Nov 2012 ;; Version: 1.11.0 -;; Package-Requires: ((dash "2.13.0")) +;; Package-Requires: ((dash "2.13.0") (nadvice "0.3")) ;; Keywords: abbrev convenience editing ;; URL: https://github.com/Fuco1/smartparens @@ -1589,13 +1589,15 @@ This check is added to the special hook ;; TODO: this function was removed from Emacs, we should get rid of ;; the advice in time. -(defadvice cua-replace-region (around fix-sp-wrap activate) +(advice-add 'cua-replace-region :around #'sp--fix-wrap) +(defun sp--fix-wrap (orig-fun &rest args) "Fix `sp-wrap' in `cua-selection-mode'." (if (and smartparens-mode (sp-wrap--can-wrap-p)) (cua--fallback) - ad-do-it)) + (apply orig-fun args))) -(defadvice cua-delete-region (around fix-sp-delete-region activate) +(advice-add 'cua-delete-region :around #'sp--fix-delete-region) +(defun sp--fix-delete-region (orig-fun &rest args) "If `smartparens-strict-mode' is enabled, perform a region check before deleting." (if (and smartparens-mode smartparens-strict-mode) @@ -1603,12 +1605,12 @@ check before deleting." (unless (or current-prefix-arg (sp-region-ok-p (region-beginning) (region-end))) (user-error (sp-message :unbalanced-region :return))) - ad-do-it) - ad-do-it)) + (apply orig-fun args)) + (apply orig-fun args))) -(cl-eval-when (compile eval load) +(eval-and-compile (defun sp--get-substitute (struct list) "Only ever call this from sp-get! This function does the replacement of all the keywords with actual calls to sp-get." @@ -9954,25 +9956,27 @@ has been created." ;; global initialization -(defadvice delete-backward-char (before sp-delete-pair-advice activate) +(advice-add 'delete-backward-char :before #'sp--delete-pair-advice) +(advice-add 'haskell-indentation-delete-backward-char :before #'sp--delete-pair-advice) +(defun sp--delete-pair-advice (n &rest _) (save-match-data - (sp-delete-pair (ad-get-arg 0)))) -(defadvice haskell-indentation-delete-backward-char (before sp-delete-pair-advice activate) - (save-match-data - (sp-delete-pair (ad-get-arg 0)))) + (sp-delete-pair n))) (sp--set-base-key-bindings) (sp--update-override-key-bindings) -(defadvice company--insert-candidate (after sp-company--insert-candidate activate) +(advice-add 'company--insert-candidate :around #'sp--company--insert-candidate) +(defun sp--company--insert-candidate (orig-fun &rest args) "If `smartparens-mode' is active, we check if the completed string has a pair definition. If so, we insert the closing pair." - (when (and ad-return-value - smartparens-mode - (not (sp-get-enclosing-sexp))) - (sp-insert-pair)) - ad-return-value) - -(defadvice hippie-expand (after sp-auto-complete-advice activate) + (let ((return-value (apply orig-fun args))) + (when (and return-value + smartparens-mode + (not (sp-get-enclosing-sexp))) + (sp-insert-pair)) + return-value)) + +(advice-add 'hippie-expand :after #'sp--auto-complete-advice) +(defun sp--auto-complete-advice (&rest _) (when (and smartparens-mode (not (sp-get-enclosing-sexp))) (sp-insert-pair))) diff --git a/test/smartparens-crystal-test.el b/test/smartparens-crystal-test.el index 8690c539f7..bc8ad35a76 100644 --- a/test/smartparens-crystal-test.el +++ b/test/smartparens-crystal-test.el @@ -1,4 +1,4 @@ -(require 'crystal-mode) +(if t (require 'crystal-mode)) ;Don't require during compilation. (require 'smartparens-crystal) (defun sp-crystal-eq-ignore-indent (a b) diff --git a/test/smartparens-ess-test.el b/test/smartparens-ess-test.el index 207a408801..a734b1d362 100644 --- a/test/smartparens-ess-test.el +++ b/test/smartparens-ess-test.el @@ -1,10 +1,9 @@ (require 'smartparens-ess) -(require 'f) - ;; ESS load helpers (defvar sp-ess-lisp-path - (f-join (f-dirname (locate-library "ess-autoloads")) "lisp")) + (expand-file-name "lisp/" (file-name-directory + (locate-library "ess-autoloads")))) (add-to-list 'load-path sp-ess-lisp-path) diff --git a/test/test-helper.el b/test/test-helper.el index 2a568a6202..c78dac8ef1 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -16,10 +16,14 @@ ;; (undercover "smartparens*.el")) (require 'dash) -(require 'f) (require 'cl-lib) -(let ((sp-dir (f-parent (f-dirname (f-this-file))))) +(let ((sp-dir (expand-file-name "../" (file-name-directory + (if (fboundp 'macroexp-file-name) + (macroexp-file-name) + (require 'f) + (declare-function f-this-file "f") + (f-this-file)))))) (add-to-list 'load-path sp-dir)) (require 'smartparens-config) ;; preload latex-mode settings @@ -203,8 +207,8 @@ BINDING is a list (kbd command)." ,@forms)) ;; put advice on `TeX-update-style' to silence its output -(defadvice TeX-update-style (around fix-output-spam activate) - (shut-up ad-do-it)) +(advice-add 'TeX-update-style :around #'sp--shut-up) +(defun sp--shut-up (fun &rest args) (shut-up (apply fun args))) (defmacro sp-ert-deftest (name &rest forms) "Generate `ert-deftest' declarations out of FORMS.