From 1688774dddae45b7b77420d01c0eb56d76dd0c95 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Mon, 9 Mar 2020 17:37:17 -0500 Subject: [PATCH] Change: (org-ql-view--header-line-format) Use keyword args --- org-ql-search.el | 6 ++++-- org-ql-view.el | 43 +++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/org-ql-search.el b/org-ql-search.el index 10d3fcf..f84dfed 100644 --- a/org-ql-search.el +++ b/org-ql-search.el @@ -164,7 +164,8 @@ necessary." :sort sort)) (strings (-map #'org-ql-view--format-element results)) (buffer (or buffer (format "%s %s*" org-ql-view-buffer-name-prefix (or title query)))) - (header (org-ql-view--header-line-format buffers-files query title)) + (header (org-ql-view--header-line-format + :buffers-files buffers-files :query query :title title)) ;; Bind variables for `org-ql-view--display' to set. (org-ql-view-buffers-files buffers-files) (org-ql-view-query query) @@ -215,7 +216,8 @@ automatically from the query." ;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than ;; I'm using. Should probably declare it as a minimum Org version after upgrading. ;; (org-agenda--insert-overriding-header (or org-ql-block-header (org-ql-agenda--header-line-format from query))) - (insert (org-add-props (or org-ql-block-header (org-ql-view--header-line-format from query)) + (insert (org-add-props (or org-ql-block-header (org-ql-view--header-line-format + :buffers-files from :query query)) nil 'face 'org-agenda-structure) "\n") ;; Calling `org-agenda-finalize' should be unnecessary, because in a "series" agenda, ;; `org-agenda-multi' is bound non-nil, in which case `org-agenda-finalize' does nothing. diff --git a/org-ql-view.el b/org-ql-view.el index 58cbd61..9ae7e1e 100644 --- a/org-ql-view.el +++ b/org-ql-view.el @@ -433,31 +433,38 @@ subsequent refreshing of the buffer: `org-ql-view-buffers-files', (org-agenda-finalize) (goto-char (point-min)))))) -(defun org-ql-view--header-line-format (buffers-files query &optional title) +(cl-defun org-ql-view--header-line-format (&key buffers-files query title) "Return `header-line-format' for BUFFERS-FILES and QUERY. If TITLE, prepend it to the header." (let* ((title (if title (concat (propertize "View:" 'face 'transient-argument) title " ") "")) - (query-formatted (org-ql-view--format-query query)) - (query-width (length query-formatted)) - (query-propertized (propertize (org-ql-view--font-lock-string 'emacs-lisp-mode query-formatted) - 'help-echo query-formatted)) - (available-width (max 0 (- (window-width) - (length "In: ") - (length "Query: ") - query-width 4))) - (buffers-files-formatted (format "%s" (org-ql-view--contract-buffers-files buffers-files))) - (buffers-files-formatted (propertize (->> buffers-files-formatted - (org-ql-view--font-lock-string 'emacs-lisp-mode) - (s-truncate available-width)) - 'help-echo buffers-files-formatted))) + (query-formatted (when query + (org-ql-view--format-query query))) + (query-width (when query-formatted + (length query-formatted))) + (query-propertized (when query-formatted + (propertize (org-ql-view--font-lock-string 'emacs-lisp-mode query-formatted) + 'help-echo query-formatted))) + (available-width (max 0 (- (window-width) (length "In: ") + (length "Query: ") (or query-width 0) + 4))) + (buffers-files-formatted (when buffers-files + (format "%s" (org-ql-view--contract-buffers-files buffers-files)))) + (buffers-files-formatted (when buffers-files-formatted + (propertize (->> buffers-files-formatted + (org-ql-view--font-lock-string 'emacs-lisp-mode) + (s-truncate available-width)) + 'help-echo buffers-files-formatted)))) (concat title - (propertize "Query:" 'face 'transient-argument) - query-propertized " " - (propertize "In:" 'face 'transient-argument) - buffers-files-formatted))) + (when query (propertize "Query:" 'face 'transient-argument)) + (when query query-propertized) + (when query " ") + (when buffers-files + (propertize "In:" 'face 'transient-argument)) + (when buffers-files-formatted + buffers-files-formatted)))) (defun org-ql-view--format-query (query) "Return QUERY formatted as a string.