From: Stefan Kangas <stefan@marxist.se>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] Unit tests and lexical-binding for delim-col.el
Date: Wed, 8 May 2019 22:24:33 +0200 [thread overview]
Message-ID: <CADwFkmn_d=Umyvvqrqn=fRi2RDvj7UFNPjca9iQsstbwUQt=iw@mail.gmail.com> (raw)
In-Reply-To: <CADwFkmmGMxHsE=+_06YQR0D8HgKv=zrEud-Tb_phcnrjQgp=3g@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 260 bytes --]
I just got back the confirmation for the copyright assignment. If there
are no
more outstanding issues, I think this is ready to be merged.
I've attached the patch (again) with a better commit message and proper
thanks
given to Basil.
Thanks,
Stefan Kangas
[-- Attachment #1.2: Type: text/html, Size: 482 bytes --]
[-- Attachment #2: 0001-Use-lexical-binding-in-delim-col.el-and-add-tests-4.patch --]
[-- Type: text/x-patch, Size: 14578 bytes --]
From c2080636251d67205aef1a144c83408083638547 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Sun, 5 May 2019 15:48:57 +0200
Subject: [PATCH] Use lexical-binding in delim-col.el, and add tests
Thanks to Basil L. Contovounesios for additional cleanups.
* lisp/delim-col.el: Use lexical-binding
* test/lisp/delim-col-tests.el (delim-col-tests-delimit-colummns-before-after)
(delim-col-tests-delimit-columns)
(delim-col-tests-delimit-columns-format/nil)
(delim-col-tests-delimit-columns-format/padding)
(delim-col-tests-delimit-columns-format/separator)
(delim-col-tests-delimit-columns-separator)
(delim-col-tests-delimit-columns-str-before-after)
(delim-col-tests-delimit-columns-str-separator)
(delim-col-tests-delimit-rectangle): New unit tests.
---
lisp/delim-col.el | 60 +++++++-------
test/lisp/delim-col-tests.el | 181 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 209 insertions(+), 32 deletions(-)
create mode 100644 test/lisp/delim-col-tests.el
diff --git a/lisp/delim-col.el b/lisp/delim-col.el
index a968b32052..3c48972b74 100644
--- a/lisp/delim-col.el
+++ b/lisp/delim-col.el
@@ -1,4 +1,4 @@
-;;; delim-col.el --- prettify all columns in a region or rectangle
+;;; delim-col.el --- prettify all columns in a region or rectangle -*- lexical-binding: t; -*-
;; Copyright (C) 1999-2019 Free Software Foundation, Inc.
@@ -91,9 +91,9 @@
;; aaa [ <bbb>, <cccc> ] dddd
;; aa [ <bb> , <ccccccc> ] ddd
;;
-;; Note that `delimit-columns-region' operates over all text region
-;; selected, extending the region start to the beginning of line and the
-;; region end to the end of line. While `delimit-columns-rectangle'
+;; Note that `delimit-columns-region' operates over the entire selected
+;; text region, extending the region start to the beginning of line and
+;; the region end to the end of line. While `delimit-columns-rectangle'
;; operates over the text rectangle selected which rectangle diagonal is
;; given by the region start and end.
;;
@@ -117,6 +117,7 @@
;;; Code:
+(require 'rect)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User Options:
@@ -213,10 +214,11 @@ delimit-columns-start
The following relation must hold:
0 <= delimit-columns-start <= delimit-columns-end
-The column number start from 0 and it's relative to the beginning of selected
-region. So if you selected a text region, the first column (column 0) is
-located at beginning of line. If you selected a text rectangle, the first
-column (column 0) is located at left corner."
+The column number starts at 0 and is relative to the beginning of
+the selected region. So if you select a text region, the first
+column (column 0) is located at the beginning of line. If you
+select a text rectangle, the first column (column 0) is located
+at the left corner."
:type '(integer :tag "Column Start")
:group 'columns)
@@ -228,10 +230,11 @@ delimit-columns-end
The following relation must hold:
0 <= delimit-columns-start <= delimit-columns-end
-The column number start from 0 and it's relative to the beginning of selected
-region. So if you selected a text region, the first column (column 0) is
-located at beginning of line. If you selected a text rectangle, the first
-column (column 0) is located at left corner."
+The column number starts at 0 and is relative to the beginning of
+the selected region. So if you select a text region, the first
+column (column 0) is located at the beginning of line. If you
+select a text rectangle, the first column (column 0) is located
+at the left corner."
:type '(integer :tag "Column End")
:group 'columns)
@@ -247,20 +250,20 @@ delimit-columns-limit
;;;###autoload
(defun delimit-columns-customize ()
- "Customization of `columns' group."
+ "Customize the `columns' group."
(interactive)
(customize-group 'columns))
-(defmacro delimit-columns-str (str)
- `(if (stringp ,str) ,str ""))
+(defun delimit-columns-str (str)
+ (if (stringp str) str ""))
;;;###autoload
(defun delimit-columns-region (start end)
"Prettify all columns in a text region.
-START and END delimits the text region."
+START and END delimit the text region."
(interactive "*r")
(let ((delimit-columns-str-before
(delimit-columns-str delimit-columns-str-before))
@@ -273,8 +276,7 @@ delimit-columns-region
(delimit-columns-after
(delimit-columns-str delimit-columns-after))
(delimit-columns-start
- (if (and (integerp delimit-columns-start)
- (>= delimit-columns-start 0))
+ (if (natnump delimit-columns-start)
delimit-columns-start
0))
(delimit-columns-end
@@ -309,14 +311,11 @@ delimit-columns-region
(set-marker the-end nil)))))
-(require 'rect)
-
-
;;;###autoload
(defun delimit-columns-rectangle (start end)
"Prettify all columns in a text rectangle.
-START and END delimits the corners of text rectangle."
+START and END delimit the corners of the text rectangle."
(interactive "*r")
(let ((delimit-columns-str-before
(delimit-columns-str delimit-columns-str-before))
@@ -329,8 +328,7 @@ delimit-columns-rectangle
(delimit-columns-after
(delimit-columns-str delimit-columns-after))
(delimit-columns-start
- (if (and (integerp delimit-columns-start)
- (>= delimit-columns-start 0))
+ (if (natnump delimit-columns-start)
delimit-columns-start
0))
(delimit-columns-end
@@ -344,11 +342,11 @@ delimit-columns-rectangle
;; get maximum length for each column
(and delimit-columns-format
(save-excursion
- (operate-on-rectangle 'delimit-columns-rectangle-max
+ (operate-on-rectangle #'delimit-columns-rectangle-max
start the-end nil)))
;; prettify columns
(save-excursion
- (operate-on-rectangle 'delimit-columns-rectangle-line
+ (operate-on-rectangle #'delimit-columns-rectangle-line
start the-end nil))
;; nullify markers
(set-marker delimit-columns-limit nil)
@@ -359,7 +357,7 @@ delimit-columns-rectangle
;; Internal Variables and Functions:
-(defun delimit-columns-rectangle-max (startpos &optional _ignore1 _ignore2)
+(defun delimit-columns-rectangle-max (startpos &optional _begextra _endextra)
(set-marker delimit-columns-limit (point))
(goto-char startpos)
(let ((ncol 1)
@@ -392,7 +390,7 @@ delimit-columns-rectangle-max
(setq values (cdr values)))))
-(defun delimit-columns-rectangle-line (startpos &optional _ignore1 _ignore2)
+(defun delimit-columns-rectangle-line (startpos &optional _begextra _endextra)
(let ((len (length delimit-columns-max))
(ncol 0)
origin)
@@ -442,8 +440,7 @@ delimit-columns-rectangle-line
((eq delimit-columns-format 'padding)
(insert spaces delimit-columns-after delimit-columns-str-after))
(t
- (insert delimit-columns-after spaces delimit-columns-str-after))
- ))
+ (insert delimit-columns-after spaces delimit-columns-str-after))))
(goto-char (max (point) delimit-columns-limit))))
@@ -466,8 +463,7 @@ delimit-columns-format
(insert delimit-columns-after
delimit-columns-str-separator
spaces
- delimit-columns-before))
- ))
+ delimit-columns-before))))
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/test/lisp/delim-col-tests.el b/test/lisp/delim-col-tests.el
new file mode 100644
index 0000000000..f2a0377b07
--- /dev/null
+++ b/test/lisp/delim-col-tests.el
@@ -0,0 +1,181 @@
+;;; delim-col-tests.el --- Tests for delim-col.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Stefan Kangas <stefankangas@gmail.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'delim-col)
+
+(ert-deftest delim-col-tests-delimit-columns ()
+ (with-temp-buffer
+ (insert "a b c\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string) "a, b, c\n")))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aaaa bb ccc ddddd\n"
+ "aaa bbb cccc dddd\n"
+ "aa bb ccccccc ddd\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string)
+ (concat "a, b, c, d \n"
+ "aaaa, bb, ccc, ddddd\n"
+ "aaa, bbb, cccc, dddd \n"
+ "aa, bb, ccccccc, ddd \n")))))
+
+(ert-deftest delim-col-tests-delimit-rectangle ()
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aaaa bb ccc ddddd\n"
+ "aaa bbb cccc dddd\n"
+ "aa bb ccccccc ddd\n")
+ (delimit-columns-rectangle 3 58) ; from first b to last c
+ (should (equal (buffer-string)
+ (concat "a b, c d\n"
+ "aaaa bb, ccc ddddd\n"
+ "aaa bbb, cccc dddd\n"
+ "aa bb, ccccccc ddd\n")))))
+
+(ert-deftest delim-col-tests-delimit-columns-str-separator ()
+ (let ((delimit-columns-str-separator ":"))
+ (with-temp-buffer
+ (insert "a b\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string) "a:b\n")))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aa bb cc dd\n")
+ (delimit-columns-rectangle 3 16) ; from first b to last c
+ (should (equal (buffer-string)
+ (concat "a b: c d\n"
+ "aa bb:cc dd\n"))))))
+
+(ert-deftest delim-col-tests-delimit-columns-str-before-after ()
+ (let ((delimit-columns-str-before "[ ")
+ (delimit-columns-str-after " ]"))
+ (with-temp-buffer
+ (insert "a b c\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string) "[ a, b, c ]\n")))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aaaa bb ccc ddddd\n"
+ "aaa bbb cccc dddd\n"
+ "aa bb ccccccc ddd\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string)
+ (concat "[ a, b, c, d ]\n"
+ "[ aaaa, bb, ccc, ddddd ]\n"
+ "[ aaa, bbb, cccc, dddd ]\n"
+ "[ aa, bb, ccccccc, ddd ]\n"))))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aaaa bb ccc ddddd\n"
+ "aaa bbb cccc dddd\n"
+ "aa bb ccccccc ddd\n")
+ (delimit-columns-rectangle 3 58) ; from first b to last c
+ (should (equal (buffer-string)
+ (concat "a [ b, c ] d\n"
+ "aaaa [ bb, ccc ] ddddd\n"
+ "aaa [ bbb, cccc ] dddd\n"
+ "aa [ bb, ccccccc ] ddd\n"))))))
+
+(ert-deftest delim-col-tests-delimit-colummns-before-after ()
+ (let ((delimit-columns-before "<")
+ (delimit-columns-after ">"))
+ (with-temp-buffer
+ (insert "a b\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string) "<a>, <b>\n")))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aa bb cc dd\n")
+ (delimit-columns-rectangle 3 17)
+ (should (equal (buffer-string)
+ (concat "a <b>, <c> d\n"
+ "aa <bb>, <cc> dd\n"))))))
+
+(ert-deftest delim-col-tests-delimit-columns-separator ()
+ (let ((delimit-columns-separator ","))
+ (with-temp-buffer
+ (insert "a,b,c\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string) "a, b, c\n")))))
+
+(ert-deftest delim-col-tests-delimit-columns-format/nil ()
+ (let ((delimit-columns-format nil))
+ (with-temp-buffer
+ (insert "a b\n"
+ "aa bb\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string)
+ (concat "a, b\n"
+ "aa, bb\n"))))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aa bb cc dd\n")
+ (delimit-columns-rectangle 3 17) ; from first b to last c
+ (should (equal (buffer-string)
+ (concat "a b, c d\n"
+ "aa bb, cc dd\n"))))))
+
+(ert-deftest delim-col-tests-delimit-columns-format/separator ()
+ (let ((delimit-columns-format 'separator)
+ (delimit-columns-before "<")
+ (delimit-columns-after ">"))
+ (with-temp-buffer
+ (insert "a b\n"
+ "aa bb\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string)
+ (concat "<a> , <b> \n"
+ "<aa>, <bb>\n"))))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aa bb cc dd\n")
+ (delimit-columns-rectangle 3 17) ; from first b to last c
+ (should (equal (buffer-string)
+ (concat "a <b> , <c> d\n"
+ "aa <bb>, <cc> dd\n"))))))
+
+(ert-deftest delim-col-tests-delimit-columns-format/padding ()
+ (let ((delimit-columns-format 'padding)
+ (delimit-columns-before "<")
+ (delimit-columns-after ">"))
+ (with-temp-buffer
+ (insert "a b\n"
+ "aa bb\n")
+ (delimit-columns-region (point-min) (point-max))
+ (should (equal (buffer-string)
+ (concat "<a >, <b >\n"
+ "<aa>, <bb>\n"))))
+ (with-temp-buffer
+ (insert "a b c d\n"
+ "aa bb cc dd\n")
+ (delimit-columns-rectangle 3 17) ; from first b to last c
+ (should (equal (buffer-string)
+ (concat "a <b >, <c > d\n"
+ "aa <bb>, <cc> dd\n"))))))
+
+(provide 'delim-col-tests)
+;;; delim-col-tests.el ends here
--
2.11.0
next prev parent reply other threads:[~2019-05-08 20:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-07 20:56 [PATCH] Unit tests and lexical-binding for delim-col.el Stefan Kangas
2019-05-07 22:44 ` Basil L. Contovounesios
2019-05-07 23:03 ` Noam Postavsky
2019-05-08 7:36 ` Stefan Kangas
2019-05-08 12:00 ` Basil L. Contovounesios
2019-05-08 17:20 ` Stefan Kangas
2019-05-08 20:24 ` Stefan Kangas [this message]
2019-05-09 13:39 ` Basil L. Contovounesios
2019-05-09 14:38 ` Stefan Monnier
2019-05-11 10:46 ` Stefan Kangas
2019-05-20 14:40 ` Basil L. Contovounesios
2019-05-30 18:20 ` Stefan Kangas
2019-06-30 23:40 ` bug#36453: [PATCH] Delegate to rectangle version in delim-col when appropriate Stefan Kangas
2019-07-08 22:52 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADwFkmn_d=Umyvvqrqn=fRi2RDvj7UFNPjca9iQsstbwUQt=iw@mail.gmail.com' \
--to=stefan@marxist.se \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.