Change: (helm-org-ql.el) Headers, requirements
Preparing for it to be a separate package.
This commit is contained in:
parent
c3e23c3072
commit
92d0e27340
1 changed files with 127 additions and 137 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
;; Author: Adam Porter <adam@alphapapa.net>
|
||||
;; URL: https://github.com/alphapapa/org-ql
|
||||
;; Version: 0.6-pre
|
||||
;; Package-Requires: ((emacs "26.1") (dash "2.17.0") (s "1.12.0") (helm-org "1.0") (org-ql "0.6-pre"))
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
|
|
@ -28,35 +30,23 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(eval-and-compile
|
||||
;;;; Requirements
|
||||
|
||||
(require 'org)
|
||||
(require 'org-ql)
|
||||
(require 'org-ql-search)
|
||||
(require 'cl-lib)
|
||||
(require 'org)
|
||||
|
||||
;;;; Compatibility
|
||||
(require 'dash)
|
||||
(require 's)
|
||||
|
||||
;; Declare Helm functions since Helm may not be installed.
|
||||
(declare-function helm "ext:helm")
|
||||
(declare-function helm-run-after-exit "ext:helm")
|
||||
(declare-function helm-window "ext:helm-lib")
|
||||
(declare-function helm-buffer-get "ext:helm-lib")
|
||||
(declare-function helm-make-source "ext:helm-source")
|
||||
(declare-function helm-org-goto-marker "ext:helm-org")
|
||||
(require 'helm)
|
||||
(require 'helm-org)
|
||||
|
||||
;; Silence byte-compiler about variables.
|
||||
(defvar helm-map)
|
||||
(defvar helm-pattern)
|
||||
(defvar helm-input-idle-delay)
|
||||
|
||||
(when (require 'helm nil 'noerror)
|
||||
|
||||
;; Requirements.
|
||||
(require 'helm-org)
|
||||
(require 'org-ql)
|
||||
(require 'org-ql-search)
|
||||
|
||||
;;;; Variables
|
||||
|
||||
(defvar helm-org-ql-map
|
||||
(defvar helm-org-ql-map
|
||||
(let ((map (make-sparse-keymap))
|
||||
(mappings '("C-x C-s" helm-org-ql-save)))
|
||||
(cl-loop for (key fn) on mappings by #'cddr
|
||||
|
|
@ -65,7 +55,7 @@
|
|||
"Keymap for `helm-org-ql' sessions.
|
||||
Based on `helm-map'.")
|
||||
|
||||
(defvar helm-source-org-ql-views
|
||||
(defvar helm-source-org-ql-views
|
||||
(helm-make-source "Org QL Views" 'helm-source-sync
|
||||
:candidates (lambda ()
|
||||
(->> org-ql-views
|
||||
|
|
@ -74,26 +64,26 @@ Based on `helm-map'.")
|
|||
:action (list (cons "Show view" #'org-ql-view)))
|
||||
"Helm source for `org-ql-views'.")
|
||||
|
||||
(with-no-warnings
|
||||
(with-no-warnings
|
||||
;; Silence compiler warning: "‘make-variable-buffer-local’ not called at toplevel"
|
||||
(defvar-local helm-org-ql-buffers-files nil
|
||||
"Used for `helm-org-ql-save'."))
|
||||
|
||||
;;;; Customization
|
||||
|
||||
(defgroup helm-org-ql nil
|
||||
(defgroup helm-org-ql nil
|
||||
"Options for `helm-org-ql'."
|
||||
:group 'org-ql)
|
||||
|
||||
(defcustom helm-org-ql-reverse-paths t
|
||||
(defcustom helm-org-ql-reverse-paths t
|
||||
"Whether to reverse Org outline paths in `helm-org-ql' results."
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom helm-org-ql-input-idle-delay 0.25
|
||||
(defcustom helm-org-ql-input-idle-delay 0.25
|
||||
"Seconds to wait after typing stops before running query."
|
||||
:type 'number)
|
||||
|
||||
(defcustom helm-org-ql-actions
|
||||
(defcustom helm-org-ql-actions
|
||||
(list (cons "Show heading in source buffer" 'helm-org-ql-show-marker)
|
||||
(cons "Show heading in indirect buffer" 'helm-org-ql-show-marker-indirect))
|
||||
"Alist of actions for `helm-org-ql' commands."
|
||||
|
|
@ -103,7 +93,7 @@ Based on `helm-map'.")
|
|||
;;;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(cl-defun helm-org-ql (buffers-files
|
||||
(cl-defun helm-org-ql (buffers-files
|
||||
&key (boolean 'and) (name "helm-org-ql"))
|
||||
"Display results in BUFFERS-FILES for an `org-ql' non-sexp query using Helm.
|
||||
Interactively, search the current buffer. Note that this command
|
||||
|
|
@ -139,19 +129,19 @@ Is transformed into this query:
|
|||
:sources (helm-org-ql-source buffers-files :name name))))
|
||||
|
||||
;;;###autoload
|
||||
(defun helm-org-ql-agenda-files ()
|
||||
(defun helm-org-ql-agenda-files ()
|
||||
"Search agenda files with `helm-org-ql', which see."
|
||||
(interactive)
|
||||
(helm-org-ql (org-agenda-files) :name "Org Agenda Files"))
|
||||
|
||||
;;;###autoload
|
||||
(defun helm-org-ql-org-directory ()
|
||||
(defun helm-org-ql-org-directory ()
|
||||
"Search Org files in `org-directory' with `helm-org-ql'."
|
||||
(interactive)
|
||||
(helm-org-ql (org-ql-search-directories-files)
|
||||
:name "Org Directory Files"))
|
||||
|
||||
(defun helm-org-ql-show-marker (marker)
|
||||
(defun helm-org-ql-show-marker (marker)
|
||||
"Show heading at MARKER."
|
||||
(interactive)
|
||||
;; This function is necessary because `helm-org-goto-marker' calls
|
||||
|
|
@ -162,13 +152,13 @@ Is transformed into this query:
|
|||
(goto-char marker)
|
||||
(org-show-entry))
|
||||
|
||||
(defun helm-org-ql-show-marker-indirect (marker)
|
||||
(defun helm-org-ql-show-marker-indirect (marker)
|
||||
"Show heading at MARKER with `org-tree-to-indirect-buffer'."
|
||||
(interactive)
|
||||
(helm-org-ql-show-marker marker)
|
||||
(org-tree-to-indirect-buffer))
|
||||
|
||||
(defun helm-org-ql-save ()
|
||||
(defun helm-org-ql-save ()
|
||||
"Show `helm-org-ql' search in an `org-ql-search' buffer."
|
||||
(interactive)
|
||||
(let ((buffers-files (with-current-buffer (helm-buffer-get)
|
||||
|
|
@ -177,14 +167,14 @@ Is transformed into this query:
|
|||
(helm-run-after-exit #'org-ql-search buffers-files query)))
|
||||
|
||||
;;;###autoload
|
||||
(defun helm-org-ql-views ()
|
||||
(defun helm-org-ql-views ()
|
||||
"Show an `org-ql' view selected with Helm."
|
||||
(interactive)
|
||||
(helm :sources helm-source-org-ql-views))
|
||||
|
||||
;;;; Functions
|
||||
|
||||
(cl-defun helm-org-ql-source (buffers-files &key (name "helm-org-ql"))
|
||||
(cl-defun helm-org-ql-source (buffers-files &key (name "helm-org-ql"))
|
||||
"Return Helm source named NAME that searches BUFFERS-FILES with `helm-org-ql'."
|
||||
;; Expansion of `helm-build-sync-source' macro.
|
||||
(helm-make-source name 'helm-source-sync
|
||||
|
|
@ -206,7 +196,7 @@ Is transformed into this query:
|
|||
:keymap helm-org-ql-map
|
||||
:action helm-org-ql-actions))
|
||||
|
||||
(defun helm-org-ql--heading (window-width)
|
||||
(defun helm-org-ql--heading (window-width)
|
||||
"Return string for Helm for heading at point.
|
||||
WINDOW-WIDTH should be the width of the Helm window."
|
||||
(font-lock-ensure (point-at-bol) (point-at-eol))
|
||||
|
|
@ -224,7 +214,7 @@ WINDOW-WIDTH should be the width of the Helm window."
|
|||
(path (if helm-org-ql-reverse-paths
|
||||
(concat heading "\\" (s-join "\\" (nreverse path)))
|
||||
(concat (s-join "/" path) "/" heading))))
|
||||
(cons (concat prefix path) (point-marker))))))
|
||||
(cons (concat prefix path) (point-marker)))))
|
||||
|
||||
;;;; Footer
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue