From be883b34f2c2c15681c1aec28aae0811807c64d3 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 8 Nov 2012 14:44:52 -0500 Subject: [PATCH] * lisp/progmodes/js.el: Prefer advice to cl-letf's sneaky rebinding. (c-forward-sws, c-backward-sws, c-beginning-of-macro): Advise. (js--filling-paragraph): New var. (js-c-fill-paragraph): Bind it instead of letf-ing the functions. --- lisp/ChangeLog | 7 +++++++ lisp/progmodes/js.el | 35 ++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e820dd5ce7f..fc699759d4d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-11-08 Stefan Monnier + + * progmodes/js.el (js--filling-paragraph): New var. + (c-forward-sws, c-backward-sws, c-beginning-of-macro): Advise. + (js-c-fill-paragraph): Prefer advice to cl-letf so the rebinding is + less sneaky. + 2012-11-08 Julien Danjou * progmodes/ruby-mode.el (auto-mode-alist): Add Rakefile in diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index d954cd53e0a..33ef7607671 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1823,22 +1823,31 @@ nil." ;;; Filling +(defvar js--filling-paragraph nil) + +;; FIXME: Such redefinitions are bad style. We should try and use some other +;; way to get the same result. +(defadvice c-forward-sws (around js-fill-paragraph activate) + (if js--filling-paragraph + (setq ad-return-value (js--forward-syntactic-ws (ad-get-arg 0))) + ad-do-it)) + +(defadvice c-backward-sws (around js-fill-paragraph activate) + (if js--filling-paragraph + (setq ad-return-value (js--backward-syntactic-ws (ad-get-arg 0))) + ad-do-it)) + +(defadvice c-beginning-of-macro (around js-fill-paragraph activate) + (if js--filling-paragraph + (setq ad-return-value (js--beginning-of-macro (ad-get-arg 0))) + ad-do-it)) + (defun js-c-fill-paragraph (&optional justify) "Fill the paragraph with `c-fill-paragraph'." (interactive "*P") - ;; FIXME: Such redefinitions are bad style. We should try and use some other - ;; way to get the same result. - (cl-letf (((symbol-function 'c-forward-sws) - (lambda (&optional limit) - (js--forward-syntactic-ws limit))) - ((symbol-function 'c-backward-sws) - (lambda (&optional limit) - (js--backward-syntactic-ws limit))) - ((symbol-function 'c-beginning-of-macro) - (lambda (&optional limit) - (js--beginning-of-macro limit)))) - (let ((fill-paragraph-function 'c-fill-paragraph)) - (c-fill-paragraph justify)))) + (let ((js--filling-paragraph t) + (fill-paragraph-function 'c-fill-paragraph)) + (c-fill-paragraph justify))) ;;; Type database and Imenu -- 2.11.4.GIT