Fix: \w duplicates & func's with buffers/names with expand/contract
This commit is contained in:
parent
576f9d3512
commit
2d49745425
2 changed files with 46 additions and 16 deletions
|
|
@ -1038,7 +1038,9 @@ current buffer. Otherwise BUFFERS-FILES is returned unchanged."
|
||||||
(let ((contracted-buffers-files
|
(let ((contracted-buffers-files
|
||||||
;; TODO: Test this more exhaustively.
|
;; TODO: Test this more exhaustively.
|
||||||
(pcase buffers-files
|
(pcase buffers-files
|
||||||
((pred functionp) buffers-files)
|
((pred functionp) (pcase buffers-files
|
||||||
|
('org-agenda-files "org-agenda-files")
|
||||||
|
(_ buffers-files)))
|
||||||
((pred listp)
|
((pred listp)
|
||||||
(pcase (expand-files buffers-files)
|
(pcase (expand-files buffers-files)
|
||||||
((pred (seq-set-equal-p (mapcar #'expand-file-name (org-agenda-files))))
|
((pred (seq-set-equal-p (mapcar #'expand-file-name (org-agenda-files))))
|
||||||
|
|
@ -1065,12 +1067,15 @@ current buffer. Otherwise BUFFERS-FILES is returned unchanged."
|
||||||
(cl-typecase contracted-buffers-files
|
(cl-typecase contracted-buffers-files
|
||||||
(function contracted-buffers-files)
|
(function contracted-buffers-files)
|
||||||
(string contracted-buffers-files)
|
(string contracted-buffers-files)
|
||||||
(list (--map
|
(list (--> contracted-buffers-files
|
||||||
|
-flatten -non-nil
|
||||||
|
(--map
|
||||||
(pcase-exhaustive it
|
(pcase-exhaustive it
|
||||||
((pred stringp) it)
|
((pred stringp) it)
|
||||||
((pred bufferp) (or (buffer-file-name it)
|
((pred bufferp) (or (buffer-file-name it)
|
||||||
(buffer-name buffer-file))))
|
(buffer-name buffer-file))))
|
||||||
contracted-buffers-files))
|
it)
|
||||||
|
-uniq))
|
||||||
(t (error (format "Value %s is not a string, a valid function or a list of buffer/strings" contracted-buffers-files)))))))
|
(t (error (format "Value %s is not a string, a valid function or a list of buffer/strings" contracted-buffers-files)))))))
|
||||||
|
|
||||||
(defun org-ql-view--complete-buffers-files ()
|
(defun org-ql-view--complete-buffers-files ()
|
||||||
|
|
|
||||||
|
|
@ -2129,14 +2129,25 @@ with keyword arg NOW in PLIST."
|
||||||
(spy-on 'org-agenda-files :and-return-value temp-filenames)
|
(spy-on 'org-agenda-files :and-return-value temp-filenames)
|
||||||
(expect (org-ql-view--contract-buffers-files 'org-agenda-files) :to-equal "org-agenda-files")
|
(expect (org-ql-view--contract-buffers-files 'org-agenda-files) :to-equal "org-agenda-files")
|
||||||
(expect (org-ql-view--contract-buffers-files #'org-agenda-files) :to-equal "org-agenda-files"))
|
(expect (org-ql-view--contract-buffers-files #'org-agenda-files) :to-equal "org-agenda-files"))
|
||||||
(it "arbitarary list of buffers/files"
|
(it "returns function"
|
||||||
(let ((list-of-strings '("a.org" "b.org"))
|
(let ((quoted-function (lambda nil temp-filenames))
|
||||||
(invalid-type 'a))
|
(unquoted-function '(lambda nil temp-filenames)))
|
||||||
(expect (org-ql-view--contract-buffers-files list-of-strings) :to-equal list-of-strings)
|
(expect (org-ql-view--contract-buffers-files quoted-function) :to-equal quoted-function)
|
||||||
;; Signal error if value is not a buffer, file, or string.
|
(expect (org-ql-view--contract-buffers-files unquoted-function) :to-equal unquoted-function)))
|
||||||
(expect (org-ql-view--contract-buffers-files invalid-type) :to-throw))))
|
(it "with a list of strings"
|
||||||
|
(let ((list-of-strings '("a.org" "b.org")))
|
||||||
|
(expect (org-ql-view--contract-buffers-files list-of-strings) :to-equal list-of-strings)))
|
||||||
|
(describe "invalid values"
|
||||||
|
:var ((list-of-strings-and-functions '("a.org" "b.org" 'org-agenda-files))
|
||||||
|
(invalid-type 'a)
|
||||||
|
(invalid-type-list '(a)))
|
||||||
|
(it "signals error if called with value not a buffer, or string"
|
||||||
|
(expect (org-ql-view--contract-buffers-files list-of-strings-and-functions) :to-throw)
|
||||||
|
(expect (org-ql-view--contract-buffers-files invalid-type) :to-throw)
|
||||||
|
(expect (org-ql-view--contract-buffers-files invalid-type-list) :to-throw))))
|
||||||
|
(describe "handles duplicate values")
|
||||||
(describe "expanding org-ql-view-buffers-files"
|
(describe "expanding org-ql-view-buffers-files"
|
||||||
(it "returns all buffers with `org-mode' as the major-mode"
|
(it "with \"all\" returns all buffers with `org-mode' as the major-mode"
|
||||||
(let ((buffers (list (generate-new-buffer "test.org") (generate-new-buffer "test.other"))))
|
(let ((buffers (list (generate-new-buffer "test.org") (generate-new-buffer "test.other"))))
|
||||||
(with-current-buffer (car buffers)
|
(with-current-buffer (car buffers)
|
||||||
(org-mode))
|
(org-mode))
|
||||||
|
|
@ -2156,6 +2167,8 @@ with keyword arg NOW in PLIST."
|
||||||
(it "returns the current buffer"
|
(it "returns the current buffer"
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(expect (org-ql-view--expand-buffers-files "buffer") :to-equal (list (buffer-name (current-buffer))))))
|
(expect (org-ql-view--expand-buffers-files "buffer") :to-equal (list (buffer-name (current-buffer))))))
|
||||||
|
(it "signals error when called with a function"
|
||||||
|
(expect (org-ql-view--expand-buffers-files '((lambda nil temp-filenames))) :to-throw 'error '("Value (lambda nil temp-filenames) is not a valid buffer/file")))
|
||||||
(it "returns literal value(s)"
|
(it "returns literal value(s)"
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(expect (org-ql-view--expand-buffers-files (current-buffer)) :to-equal (list (buffer-name (current-buffer)))))
|
(expect (org-ql-view--expand-buffers-files (current-buffer)) :to-equal (list (buffer-name (current-buffer)))))
|
||||||
|
|
@ -2163,9 +2176,21 @@ with keyword arg NOW in PLIST."
|
||||||
(expect (org-ql-view--expand-buffers-files test-buffer) :to-equal (list (buffer-name test-buffer))))
|
(expect (org-ql-view--expand-buffers-files test-buffer) :to-equal (list (buffer-name test-buffer))))
|
||||||
(let ((list-of-numbers '(1 2 3))
|
(let ((list-of-numbers '(1 2 3))
|
||||||
(literal-string "random string"))
|
(literal-string "random string"))
|
||||||
;; Signal error if any of the values are not a buffer, file, or string.
|
;; Signal error if any of the values are not a buffer, function, or string.
|
||||||
(expect (org-ql-view--expand-buffers-files list-of-numbers) :to-throw)
|
(expect (org-ql-view--expand-buffers-files list-of-numbers) :to-throw)
|
||||||
(expect (org-ql-view--expand-buffers-files literal-string) :to-equal (list literal-string)))))
|
(expect (org-ql-view--expand-buffers-files literal-string) :to-equal (list literal-string))))
|
||||||
|
(it "contracts to a list without duplicates"
|
||||||
|
(let* ((list-of-strings '("a.org" "b.org"))
|
||||||
|
(duplicate-buffer-and-file (list (find-file-noselect (car temp-filenames))
|
||||||
|
(car temp-filenames)))
|
||||||
|
(org-agenda-files (list (car temp-filenames)))
|
||||||
|
(random-buffer (generate-new-buffer "new-buffer"))
|
||||||
|
(random-buffer-name (buffer-name random-buffer))
|
||||||
|
(duplicate-buffer-and-name (list random-buffer-name random-buffer))
|
||||||
|
(buffer-collection (append org-agenda-files (list random-buffer-name))))
|
||||||
|
(expect (org-ql-view--expand-buffers-files duplicate-buffer-and-file) :to-equal (list (car temp-filenames)))
|
||||||
|
(expect (org-ql-view--expand-buffers-files duplicate-buffer-and-name) :to-equal (list random-buffer-name))
|
||||||
|
(expect (org-ql-view--expand-buffers-files (list "org-agenda-files" random-buffer)) :to-equal buffer-collection))))
|
||||||
(describe "testing `org-ql-view--complete-buffers-files'"
|
(describe "testing `org-ql-view--complete-buffers-files'"
|
||||||
(it "returns `org-agenda-files'"
|
(it "returns `org-agenda-files'"
|
||||||
(let ((org-ql-view-buffers-files temp-filenames))
|
(let ((org-ql-view-buffers-files temp-filenames))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue