emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ELPA-diffs] ELPA branch, master, updated. d61a36e0409ee2dfad5f752357175


From: Barry O'Reilly
Subject: [ELPA-diffs] ELPA branch, master, updated. d61a36e0409ee2dfad5f7523571753c648283ddc
Date: Tue, 08 Oct 2013 14:06:36 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "ELPA".

The branch, master has been updated
       via  d61a36e0409ee2dfad5f7523571753c648283ddc (commit)
      from  f53038303beecf3d28c8fab7833726987f91ec16 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d61a36e0409ee2dfad5f7523571753c648283ddc
Author: Barry O'Reilly <address@hidden>
Date:   Tue Oct 8 10:05:40 2013 -0400

    * Makefile: New file to provide 'make check' tests
    * adjust-parens-tests.el: New tests
    (apt-near-bob-test): Test indenting near BOB
    (apt-indent-dedent-test): Test same case described in Commentary
    * adjust-parens.el: Fix bug when near BOB or EOB. Fix compiler
    warning due to using defvarred prefix-arg as lexical var.

diff --git a/packages/adjust-parens/Makefile b/packages/adjust-parens/Makefile
new file mode 100644
index 0000000..30b1e3f
--- /dev/null
+++ b/packages/adjust-parens/Makefile
@@ -0,0 +1,16 @@
+.PHONY: all clean
+
+ELCFILES = $(addsuffix .elc, $(basename $(wildcard *.el)))
+
+all: $(ELCFILES)
+
+%.elc : %.el
+       @echo Compiling $<
+       @emacs --batch -q --no-site-file -L . -f batch-byte-compile $<
+
+clean:
+       @rm -f *.elc
+
+check: $(ELCFILES)
+       @emacs --batch -q --no-site-file -L . -l adjust-parens-tests.el -f 
ert-run-tests-batch-and-exit
+
diff --git a/packages/adjust-parens/adjust-parens-tests.el 
b/packages/adjust-parens/adjust-parens-tests.el
new file mode 100644
index 0000000..5b249c5
--- /dev/null
+++ b/packages/adjust-parens/adjust-parens-tests.el
@@ -0,0 +1,66 @@
+;;; adjust-parens-tests.el --- Tests of adjust-parens package
+
+;; Copyright (C) 2013  Free Software Foundation, Inc.
+
+;; Author: Barry O'Reilly <address@hidden>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'adjust-parens)
+
+(defun apt-check-buffer (text-before-point text-after-point)
+  (should (string= text-before-point
+                   (buffer-substring-no-properties (point-min)
+                                                   (point))))
+  (should (string= text-after-point
+                   (buffer-substring-no-properties (point)
+                                                   (point-max)))))
+
+(ert-deftest apt-near-bob-test ()
+  (with-temp-buffer
+    (emacs-lisp-mode)
+    (insert "(foo)\n")
+    (lisp-indent-adjust-parens)
+    (apt-check-buffer "(foo\n " ")")))
+
+(ert-deftest apt-indent-dedent-test ()
+  (with-temp-buffer
+    (emacs-lisp-mode)
+    (setq indent-tabs-mode nil)
+    (insert ";;\n"
+            "(let ((x 10) (y (some-func 20))))\n"
+            "; Comment")
+    (beginning-of-line)
+    (lisp-indent-adjust-parens)
+    (apt-check-buffer (concat ";;\n"
+                              "(let ((x 10) (y (some-func 20)))\n"
+                              "  ")
+                      "); Comment")
+    (lisp-indent-adjust-parens 3)
+    (apt-check-buffer (concat ";;\n"
+                              "(let ((x 10) (y (some-func 20\n"
+                              "                           ")
+                      ")))); Comment")
+    (lisp-dedent-adjust-parens 2)
+    (apt-check-buffer (concat ";;\n"
+                              "(let ((x 10) (y (some-func 20))\n"
+                              "      ")
+                      ")); Comment")))
+
+;;; adjust-parens-tests.el ends here
diff --git a/packages/adjust-parens/adjust-parens.el 
b/packages/adjust-parens/adjust-parens.el
index 912f7ea..003302d 100644
--- a/packages/adjust-parens/adjust-parens.el
+++ b/packages/adjust-parens/adjust-parens.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2013  Free Software Foundation, Inc.
 
 ;; Author: Barry O'Reilly <address@hidden>
-;; Version: 1.0
+;; Version: 1.1
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -100,7 +100,6 @@
 ;; Future work:
 ;;   - Consider taking a region as input in order to indent a sexp and
 ;;     its siblings in the region. Dedenting would not take a region.
-;;   - Write tests
 
 (require 'cl)
 
@@ -109,6 +108,8 @@
 return the position of the last sexp that had depth REL-DEPTH relative
 to FROM-POS. Returns nil if REL-DEPTH is not reached.
 
+May change point.
+
 Examples:
   Region:   a (b c (d)) e (f g (h i)) j
 
@@ -119,29 +120,41 @@ Examples:
   Returns:  position of (h i)
 
 This function assumes FROM-POS is not in a string or comment."
-  (save-excursion
-    (goto-char from-pos)
-    (let (the-last-pos
-          (parse-state '(0 nil nil nil nil nil nil nil nil)))
-      (while (< (point) to-pos)
-        (setq parse-state
-              (parse-partial-sexp (point)
-                                  to-pos
-                                  nil
-                                  t ; Stop before sexp
-                                  parse-state))
-        (and (not (eq (point) to-pos))
-             (eq (car parse-state) rel-depth)
-             (setq the-last-pos (point)))
-        ;; The previous parse may not advance. To advance and maintain
-        ;; correctness of depth, we parse over the next char.
+  (goto-char from-pos)
+  (let (the-last-pos
+        (parse-state '(0 nil nil nil nil nil nil nil nil)))
+    (while (< (point) to-pos)
+      (setq parse-state
+            (parse-partial-sexp (point)
+                                to-pos
+                                nil
+                                t ; Stop before sexp
+                                parse-state))
+      (and (not (eq (point) to-pos))
+           (eq (car parse-state) rel-depth)
+           (setq the-last-pos (point)))
+      ;; The previous parse may not advance. To advance and maintain
+      ;; correctness of depth, we parse over the next char.
+      (when (< (point) to-pos)
         (setq parse-state
               (parse-partial-sexp (point)
                                   (1+ (point))
                                   nil
                                   nil
-                                  parse-state)))
-      the-last-pos)))
+                                  parse-state))))
+    the-last-pos))
+
+
+(defun adjust-parens-check-prior-sexp ()
+  "Returns true if there is a full sexp before point, else false.
+
+May change point."
+  (let ((pos1 (progn (backward-sexp)
+                      (point)))
+        (pos2 (progn (forward-sexp)
+                     (backward-sexp)
+                     (point))))
+    (>= pos1 pos2)))
 
 (defun adjust-close-paren-for-indent ()
   "Adjust a close parentheses of a sexp so as
@@ -157,9 +170,11 @@ scan-error to propogate up."
     (let ((deleted-paren-pos
            (save-excursion
              (beginning-of-line)
-             (backward-sexp)
              ;; Account for edge case when point has no sexp before it
-             (if (bobp)
+             ;;
+             ;; This is primarily to avoid funny behavior when there
+             ;; is no sexp between bob and point.
+             (if (not (adjust-parens-check-prior-sexp))
                  nil
                ;; If the sexp at point is a list,
                ;; delete its closing paren
@@ -170,10 +185,11 @@ scan-error to propogate up."
                  (point))))))
       (when deleted-paren-pos
         (let ((sexp-to-close
-               (last-sexp-with-relative-depth (point)
-                                              (progn (end-of-line)
-                                                     (point))
-                                              0)))
+               (save-excursion
+                 (last-sexp-with-relative-depth (point)
+                                                (progn (end-of-line)
+                                                       (point))
+                                                0))))
           (when sexp-to-close
             (goto-char sexp-to-close)
             (forward-sexp))
@@ -227,11 +243,11 @@ scan-error to propogate up."
       (and (not (use-region-p))
            (<= orig-pos (point))))))
 
-(defun adjust-parens-and-indent (adjust-function prefix-arg)
+(defun adjust-parens-and-indent (adjust-function parg)
   "Adjust close parens and indent the region over which the parens
 moved."
   (let ((region-of-change (list (point) (point))))
-    (cl-loop for i from 1 to (or prefix-arg 1)
+    (cl-loop for i from 1 to (or parg 1)
              with finished = nil
              while (not finished)
              do
@@ -251,7 +267,7 @@ moved."
     (apply 'indent-region region-of-change))
   (back-to-indentation))
 
-(defun lisp-indent-adjust-parens (&optional prefix-arg)
+(defun lisp-indent-adjust-parens (&optional parg)
   "Indent Lisp code to the next level while adjusting sexp balanced
 expressions to be consistent.
 
@@ -260,10 +276,10 @@ potentially calls the latter."
   (interactive "P")
   (if (adjust-parens-p)
       (adjust-parens-and-indent 'adjust-close-paren-for-indent
-                                prefix-arg)
-    (indent-for-tab-command prefix-arg)))
+                                parg)
+    (indent-for-tab-command parg)))
 
-(defun lisp-dedent-adjust-parens (&optional prefix-arg)
+(defun lisp-dedent-adjust-parens (&optional parg)
   "Dedent Lisp code to the previous level while adjusting sexp
 balanced expressions to be consistent.
 
@@ -271,7 +287,7 @@ Binding to <backtab> (ie Shift-Tab) is a sensible choice."
   (interactive "P")
   (when (adjust-parens-p)
     (adjust-parens-and-indent 'adjust-close-paren-for-dedent
-                              prefix-arg)))
+                              parg)))
 
 (add-hook 'emacs-lisp-mode-hook
           (lambda ()

-----------------------------------------------------------------------

Summary of changes:
 packages/adjust-parens/Makefile               |   16 +++++
 packages/adjust-parens/adjust-parens-tests.el |   66 ++++++++++++++++++++
 packages/adjust-parens/adjust-parens.el       |   82 +++++++++++++++----------
 3 files changed, 131 insertions(+), 33 deletions(-)
 create mode 100644 packages/adjust-parens/Makefile
 create mode 100644 packages/adjust-parens/adjust-parens-tests.el


hooks/post-receive
-- 
ELPA



reply via email to

[Prev in Thread] Current Thread [Next in Thread]