Add: (org-ql-agenda--header-line-format) Move code to new function

This commit is contained in:
Adam Porter 2019-07-25 21:55:49 -05:00
parent b5ccc3294e
commit cc5756d00d

View file

@ -230,25 +230,9 @@ SORT: One or a list of `org-ql' sorting functions, like `date' or
(setq-local org-ql-sort sort) (setq-local org-ql-sort sort)
(setq-local org-ql-narrow narrow) (setq-local org-ql-narrow narrow)
(setq-local org-ql-super-groups super-groups) (setq-local org-ql-super-groups super-groups)
(setq-local header-line-format (org-ql-agenda--header-line-format buffers-files query))
;; TODO: Derive a minor mode and set keymap there. ;; TODO: Derive a minor mode and set keymap there.
(local-set-key "g" #'org-ql-search-refresh) (local-set-key "g" #'org-ql-search-refresh)
(let* ((query-formatted (format "%S" query))
(query-formatted (propertize (org-ql-agenda--font-lock-string 'emacs-lisp-mode query-formatted)
'help-echo query-formatted))
(query-width (length query-formatted))
(available-width (- (window-width)
(length "In: ")
(length "Query: ")
query-width 4))
(buffers-files-formatted (format "%S" buffers-files))
(buffers-files-formatted (propertize (->> buffers-files-formatted
(org-ql-agenda--font-lock-string 'emacs-lisp-mode)
(s-truncate available-width))
'help-echo buffers-files-formatted)))
(setq-local header-line-format (concat (propertize "Query: " 'face 'org-agenda-structure)
query-formatted " "
(propertize "In: " 'face 'org-agenda-structure)
buffers-files-formatted)))
;; Clear buffer, insert entries, etc. ;; Clear buffer, insert entries, etc.
(erase-buffer) (erase-buffer)
(insert entries) (insert entries)
@ -256,6 +240,26 @@ SORT: One or a list of `org-ql' sorting functions, like `date' or
(org-agenda-finalize) (org-agenda-finalize)
(goto-char (point-min))))) (goto-char (point-min)))))
(defun org-ql-agenda--header-line-format (buffers-files query)
"Return header-line-format for BUFFERS-FILES and QUERY."
(let* ((query-formatted (format "%S" query))
(query-formatted (propertize (org-ql-agenda--font-lock-string 'emacs-lisp-mode query-formatted)
'help-echo query-formatted))
(query-width (length query-formatted))
(available-width (- (window-width)
(length "In: ")
(length "Query: ")
query-width 4))
(buffers-files-formatted (format "%S" buffers-files))
(buffers-files-formatted (propertize (->> buffers-files-formatted
(org-ql-agenda--font-lock-string 'emacs-lisp-mode)
(s-truncate available-width))
'help-echo buffers-files-formatted)))
(concat (propertize "Query: " 'face 'org-agenda-structure)
query-formatted " "
(propertize "In: " 'face 'org-agenda-structure)
buffers-files-formatted)))
(defun org-ql-agenda--font-lock-string (mode s) (defun org-ql-agenda--font-lock-string (mode s)
"Return string S font-locked according to MODE." "Return string S font-locked according to MODE."
;; FIXME: Is this the proper way to do this? It works, but I feel like there must be a built-in way... ;; FIXME: Is this the proper way to do this? It works, but I feel like there must be a built-in way...