mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-30 04:10:54 -08:00
Use lexical-binding in makesum.el and add tests
* lisp/makesum.el: Use lexical-binding. (make-command-summary): Replace `if..progn' with `when'. (double-column): Add docstring and apply trivial simplifications. * test/lisp/makesum-tests.el: New file with tests for makesum.el.
This commit is contained in:
parent
7f3b0d1c00
commit
49cdbb4a35
2 changed files with 78 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
|||
;;; makesum.el --- generate key binding summary for Emacs
|
||||
;;; makesum.el --- generate key binding summary for Emacs -*- lexical-binding:t -*-
|
||||
|
||||
;; Copyright (C) 1985, 2001-2019 Free Software Foundation, Inc.
|
||||
|
||||
|
|
@ -59,15 +59,14 @@ Previous contents of that buffer are killed first."
|
|||
(while (search-forward "C-i" nil t)
|
||||
(replace-match "TAB"))
|
||||
(goto-char (point-min))
|
||||
(if (re-search-forward "^Local Bindings:" nil t)
|
||||
(progn
|
||||
(forward-char -1)
|
||||
(insert " for " (format-mode-line cur-mode) " Mode")
|
||||
(while (search-forward "??\n" nil t)
|
||||
(delete-region (point)
|
||||
(progn
|
||||
(forward-line -1)
|
||||
(point))))))
|
||||
(when (re-search-forward "^Local Bindings:" nil t)
|
||||
(forward-char -1)
|
||||
(insert " for " (format-mode-line cur-mode) " Mode")
|
||||
(while (search-forward "??\n" nil t)
|
||||
(delete-region (point)
|
||||
(progn
|
||||
(forward-line -1)
|
||||
(point)))))
|
||||
(goto-char (point-min))
|
||||
(insert "Emacs command summary, " (substring (current-time-string) 0 10)
|
||||
".\n")
|
||||
|
|
@ -84,28 +83,25 @@ Previous contents of that buffer are killed first."
|
|||
(message "Making command summary...done"))
|
||||
|
||||
(defun double-column (start end)
|
||||
"Reformat buffer contents from START to END into two columns."
|
||||
(interactive "r")
|
||||
(let (half line lines nlines
|
||||
(let (half lines
|
||||
(nlines (count-lines start end))
|
||||
(from-end (- (point-max) end)))
|
||||
(setq nlines (count-lines start end))
|
||||
(if (<= nlines 1)
|
||||
nil
|
||||
(when (> nlines 1)
|
||||
(setq half (/ (1+ nlines) 2))
|
||||
(goto-char start)
|
||||
(save-excursion
|
||||
(forward-line half)
|
||||
(while (< half nlines)
|
||||
(setq half (1+ half))
|
||||
(setq line (buffer-substring (point) (line-end-position)))
|
||||
(setq lines (cons line lines))
|
||||
(dotimes (_ (- nlines half))
|
||||
(push (buffer-substring (point) (line-end-position))
|
||||
lines)
|
||||
(delete-region (point) (progn (forward-line 1) (point)))))
|
||||
(setq lines (nreverse lines))
|
||||
(while lines
|
||||
(end-of-line)
|
||||
(dolist (line (nreverse lines))
|
||||
(end-of-line)
|
||||
(indent-to 41)
|
||||
(insert (car lines))
|
||||
(forward-line 1)
|
||||
(setq lines (cdr lines))))
|
||||
(insert line)
|
||||
(forward-line 1)))
|
||||
(goto-char (- (point-max) from-end))))
|
||||
|
||||
(provide 'makesum)
|
||||
|
|
|
|||
58
test/lisp/makesum-tests.el
Normal file
58
test/lisp/makesum-tests.el
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
;;; makesum-tests.el --- Tests for makesum.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Simen Heggestøyl <simenheg@gmail.com>
|
||||
;; Keywords:
|
||||
|
||||
;; 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 'makesum)
|
||||
|
||||
(ert-deftest makesum-tests-double-column-even-lines ()
|
||||
(with-temp-buffer
|
||||
(insert "a\nb\nc\nd\ne\nf")
|
||||
(double-column (point-min) (point-max))
|
||||
(should (string-match-p "a[ \t]+d\nb[ \t]+e\nc[ \t]+f" (buffer-string)))))
|
||||
|
||||
(ert-deftest makesum-tests-double-column-odd-lines ()
|
||||
(with-temp-buffer
|
||||
(insert "a\nb\nc\nd\ne")
|
||||
(double-column (point-min) (point-max))
|
||||
(should (string-match-p "a[ \t]+d\nb[ \t]+e\nc" (buffer-string)))))
|
||||
|
||||
(ert-deftest makesum-tests-double-column-noop ()
|
||||
(with-temp-buffer
|
||||
(insert "foo")
|
||||
(let ((prev-buffer-string (buffer-string)))
|
||||
(double-column (point-min) (point-max))
|
||||
(should (equal prev-buffer-string (buffer-string))))))
|
||||
|
||||
(ert-deftest makesum-tests-double-column-partial ()
|
||||
(with-temp-buffer
|
||||
(insert "a\nb\nc\nd\ne\nf")
|
||||
(double-column 3 10)
|
||||
(should (string-match-p "a\nb[ \t]+d\nc[ \t]+e\nf" (buffer-string)))))
|
||||
|
||||
(provide 'makesum-tests)
|
||||
;;; makesum-tests.el ends here
|
||||
Loading…
Add table
Add a link
Reference in a new issue