Add/Fix: org-ql-view-mode, and check when refreshing

Use a derived major mode for org-ql-view buffers, and ensure that mode
is active when calling org-ql-view-refresh, to avoid interfering with
buffers in other modes if the user calls the command by accident.

See
<b87156f2bb>.
Thanks to Alois Janíček (@AloisJanicek) for discovering the bug.

Released as 0.4.3.
This commit is contained in:
Adam Porter 2020-03-14 13:53:46 -05:00
parent 4b1e253ee9
commit ba7d4a2e82
4 changed files with 77 additions and 56 deletions

View file

@ -309,6 +309,8 @@ TYPE may be `ts', `ts-active', `ts-inactive', `clocked', or
If PROMPT is non-nil (interactively, with prefix), prompt to
update search arguments."
(interactive "P")
(unless (eq major-mode 'org-ql-view-mode)
(user-error "Not an Org QL View buffer"))
(let* ((current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
(old-pos (point))
(defaults (list org-ql-view-buffers-files
@ -354,6 +356,10 @@ update search arguments."
;;;; Functions
(define-derived-mode org-ql-view-mode org-agenda-mode "Org QL View"
"Major mode for `org-ql-view' buffers."
(setf buffer-read-only t))
(defun org-ql-view--list-buffer ()
"Return view list buffer."
(with-current-buffer (get-buffer-create "*Org QL View List*")
@ -468,9 +474,8 @@ with human-readable strings."
If NAME is non-nil, return buffer by that name instead of using
default buffer."
(with-current-buffer (get-buffer-create (or name (concat org-ql-view-buffer-name-prefix "*")))
(unless (eq major-mode 'org-agenda-mode)
(org-agenda-mode)
(setf buffer-read-only t))
(unless (eq major-mode 'org-ql-view-mode)
(org-ql-view-mode))
(current-buffer)))
(defun org-ql-view--format-relative-date (difference)