branch: externals/hyperbole commit 00433b6f8e69a5b9f7325fff601171717d221ca7 Author: Mats Lidell <mats.lid...@lidells.se> Commit: GitHub <nore...@github.com>
Update and add kotl-mode tests (#318) --- ChangeLog | 19 ++++++++++ kotl/kfile.el | 3 +- kotl/kotl-mode.el | 55 +++++++++++++++------------- test/kotl-mode-tests.el | 95 +++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 144 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e515def34..3f82ff4421 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2023-04-15 Bob Weiner <r...@gnu.org> + +* kotl/kotl-mode.el (kotl-mode:cell-help): Fix to keep current buffer + as Koutline buffer and only set standard-output to the help buffer. + (kotl-mode:is-p): Update to show buffer that is + not a Koutline. + +* kotl/kfile.el (kfile:create): Fix to handle when 'inhibit-read-only' + is set rather than just testing the 'buffer-read-only' flag. + +2023-04-15 Mats Lidell <ma...@gnu.org> + +* test/kotl-mode-tests.el (kotl-mode-cell-help-displays-help-in-temp-buffer) + (kotl-mode-cell-help-displays-help-from-root) + (kotl-mode-cell-help-displays-help-for-all-cells) + (kotl-mode-kill-tree-and-reopen) + (kotl-mode-kill-tree-on-empty-file-creates-new-cell): kotl-mode test + cases. + 2023-04-09 Bob Weiner <r...@gnu.org> * kotl/kimport.el (kimport:initialize): Change test from 'kview:is-p' diff --git a/kotl/kfile.el b/kotl/kfile.el index be3e435a14..098d1602b1 100644 --- a/kotl/kfile.el +++ b/kotl/kfile.el @@ -110,8 +110,7 @@ File is created with a single empty level 1 kotl cell." (unless (bufferp buffer) (error "(kfile:create): Invalid buffer argument, %s" buffer)) (set-buffer buffer) - (when buffer-read-only - (error "(kfile:create): %s is read-only" buffer)) + (barf-if-buffer-read-only) (widen) (let ((empty-flag (zerop (buffer-size))) diff --git a/kotl/kotl-mode.el b/kotl/kotl-mode.el index 768e2bf26d..e82d58e618 100644 --- a/kotl/kotl-mode.el +++ b/kotl/kotl-mode.el @@ -170,7 +170,7 @@ It provides the following keys: ;; If buffer has not yet been formatted for editing, format it. (let (version) - ;; Koutline file that has been loaded but not yet formatted for editing. + ;; Koutline file that has been loaded but not yet formatted for editing. (if (setq version (kfile:is-p)) ;; Koutline file that has been loaded and formatted for editing. (if (kview:is-p kview) @@ -2987,9 +2987,9 @@ With optional SHOW-FLAG, expand the tree instead." (kotl-mode:hide-tree cell-ref t)) (defun kotl-mode:cell-attributes (all-flag) - "Print attributes of the current kcell to standard output. + "Print attributes of the current kcell to `standard-output'. With prefix arg ALL-FLAG non-nil, print the attributes of all visible -kcells from the current buffer to standard output. +kcells from the current buffer to `standard-output'. See also the documentation for `kotl-mode:cell-help'." (interactive "P") @@ -3027,26 +3027,33 @@ See also the documentation for `kotl-mode:cell-attributes'." (setq cell-ref (kcell-view:label))) ;; Ensure these do not invoke with-output-to-temp-buffer a second time. (let ((temp-buffer-show-hook) - (temp-buffer-show-function)) - (with-help-window (hypb:help-buf-name "Koutliner") - (save-excursion - (if (or (member cell-ref '("0" 0)) - (<= cells-flag 0)) - (progn - (hattr:report (append '(idstamp 0) - (kcell:plist (kview:top-cell kview)))) - (terpri) - (cond ((= cells-flag 1) nil) - ((> cells-flag 1) - (kview:map-tree #'kotl-mode:print-attributes kview t t)) - ;; (<= cells-flag 0) - (t (kotl-mode:cell-attributes t)))) - (cond ((= cells-flag 1) - (kotl-mode:goto-cell cell-ref) - (kotl-mode:print-attributes kview)) - ((> cells-flag 1) - (kotl-mode:goto-cell cell-ref) - (kview:map-tree #'kotl-mode:print-attributes kview nil t)))))))) + (temp-buffer-show-function) + (standard-output (get-buffer-create (hypb:help-buf-name "Koutliner")))) + (with-current-buffer standard-output + (setq buffer-read-only nil) + (erase-buffer)) + (save-excursion + (if (or (member cell-ref '("0" 0)) + (<= cells-flag 0)) + (progn + (hattr:report (append '(idstamp 0) + (kcell:plist (kview:top-cell kview)))) + (terpri) + (cond ((= cells-flag 1) nil) + ((> cells-flag 1) + (kview:map-tree #'kotl-mode:print-attributes kview t t)) + ;; (<= cells-flag 0) + (t (kotl-mode:cell-attributes t)))) + (cond ((= cells-flag 1) + (kotl-mode:goto-cell cell-ref) + (kotl-mode:print-attributes kview)) + ((> cells-flag 1) + (kotl-mode:goto-cell cell-ref) + (kview:map-tree #'kotl-mode:print-attributes kview nil t))))) + (with-current-buffer standard-output + (goto-char (point-min)) + (set-buffer-modified-p nil) + (hkey-help-show standard-output)))) (defun kotl-mode:get-cell-attribute (attribute &optional pos top-cell-flag) "Return ATTRIBUTE's value for the current cell or the cell at optional POS. @@ -3185,7 +3192,7 @@ on when tabs are used for indenting." (if (kview:is-p kview) t (hypb:error - "(kotl-mode:is-p): Command requires a valid Hyperbole koutline"))) + "(kotl-mode:is-p): '%s' is not a valid Hyperbole koutline" (current-buffer)))) (defun kotl-mode:shrink-region () "Shrink region within visible bounds of a single cell. diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index 766d63e2bc..9bf021c92d 100644 --- a/test/kotl-mode-tests.el +++ b/test/kotl-mode-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> ;; ;; Orig-Date: 18-May-21 at 22:14:10 -;; Last-Mod: 18-Apr-22 at 22:40:33 by Mats Lidell +;; Last-Mod: 15-Apr-23 at 00:25:21 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -295,6 +295,7 @@ (progn (find-file kotl-file) (insert "first") + (should (string= (kcell-view:idstamp) "01")) (kotl-mode:add-child) (should (string= (kcell-view:label (point)) "1a")) @@ -302,12 +303,48 @@ (should (string= (kcell-view:label (point)) "1")) (kotl-mode:beginning-of-cell) (should (looking-at-p "first")) + (should (string= (kcell-view:idstamp) "01")) (kotl-mode:kill-tree) (kotl-mode:beginning-of-cell) + (should (string= (kcell-view:idstamp) "04")) (should (looking-at-p "$"))) (delete-file kotl-file)))) +(ert-deftest kotl-mode-kill-tree-and-reopen () + "Remove first cell, reopen file, verify idstamp of first cell." + (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) + (unwind-protect + (progn + (find-file kotl-file) + (insert "first") + (kotl-mode:add-cell) + (insert "second") + (should (string= (kcell-view:idstamp) "02")) + (kotl-mode:beginning-of-buffer) + (kotl-mode:kill-tree) + (should (string= (kcell-view:idstamp) "02")) + (save-buffer) + (kill-buffer) + (find-file kotl-file) + (should (looking-at-p "second")) + (should (string= (kcell-view:idstamp) "02"))) + (delete-file kotl-file)))) + +(ert-deftest kotl-mode-kill-tree-on-empty-file-creates-new-cell () + "Kill tree on empty kotl file creates new cell." + (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) + (unwind-protect + (progn + (find-file kotl-file) + (insert "first") + (should (string= (kcell-view:idstamp) "01")) + (kotl-mode:kill-tree) + (should (string= (kcell-view:idstamp) "02")) + (kotl-mode:kill-tree) + (should (string= (kcell-view:idstamp) "03"))) + (delete-file kotl-file)))) + (ert-deftest kotl-mode-split-cell () "Kotl-mode split cell." (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) @@ -522,7 +559,6 @@ (should (looking-at "2"))) (delete-file kotl-file)))) - (ert-deftest kotl-mode-move-tree-backward () "Should move tree backward." (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) @@ -560,5 +596,60 @@ (should-not (kcell-view:get-attr 'no-fill))) (delete-file kotl-file)))) +(ert-deftest kotl-mode-cell-help-displays-help-in-temp-buffer () + "Verify that kotl-mode:cell-help shows help in a temp buffer." + (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) + (unwind-protect + (progn + (find-file kotl-file) + (insert kotl-file) + (kotl-mode:add-child) + (insert "1a") + (kotl-mode:add-child) + (insert "1a1") + (kotl-mode:beginning-of-buffer) + (kotl-mode:cell-help "1" nil) + (with-current-buffer "*Help: Hyperbole Koutliner*" + (should (looking-at-p (concat "\\W+1\\. " kotl-file))))) + (delete-file kotl-file)))) + +(ert-deftest kotl-mode-cell-help-displays-help-from-root () + "Verify that kotl-mode:cell-help shows help from root cell." + (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) + (unwind-protect + (progn + (find-file kotl-file) + (insert "1") + (kotl-mode:add-child) + (insert kotl-file) + (kotl-mode:add-child) + (insert "1a1") + (kotl-mode:beginning-of-buffer) + (kotl-mode:cell-help "1a" 2) + (with-current-buffer "*Help: Hyperbole Koutliner*" + (should (looking-at-p (concat "\\W+1a\\. " kotl-file))) + (should (= (count-matches "idstamp") 2)))) + (delete-file kotl-file)))) + +(ert-deftest kotl-mode-cell-help-displays-help-for-all-cells () + "Verify that kotl-mode:cell-help shows help for all cells." + (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) + (unwind-protect + (progn + (find-file kotl-file) + (insert kotl-file) + (kotl-mode:add-child) + (insert "1a") + (kotl-mode:add-child) + (insert "1a1") + (kotl-mode:beginning-of-buffer) + (kotl-mode:cell-help "1a" -1) + (with-current-buffer "*Help: Hyperbole Koutliner*" + (should (looking-at-p "\\W+idstamp:\\W+0")) + (should (= (count-matches "idstamp") 4)) + (forward-line 5) + (should (looking-at-p (concat "\\W+1\\. " kotl-file))))) + (delete-file kotl-file)))) + (provide 'kotl-mode-tests) ;;; kotl-mode-tests.el ends here