]> code.delx.au - gnu-emacs/commitdiff
* lisp/progmodes/js.el: Prefer advice to cl-letf's sneaky rebinding.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 8 Nov 2012 19:44:52 +0000 (14:44 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 8 Nov 2012 19:44:52 +0000 (14:44 -0500)
(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
lisp/progmodes/js.el

index e820dd5ce7fc79995afb62ebc3c6fced1a1a588c..fc699759d4d887f64d436a290efa9ff42387446f 100644 (file)
@@ -1,3 +1,10 @@
+2012-11-08  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * 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  <julien@danjou.info>
 
        * progmodes/ruby-mode.el (auto-mode-alist): Add Rakefile in
index d954cd53e0a12d6ccca35b24bbdda9a51e096438..33ef76076713363d8283011d8fae9a2aa46aa018 100644 (file)
@@ -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