Skip to content

Commit

Permalink
make some things project aware
Browse files Browse the repository at this point in the history
  • Loading branch information
jkitchin committed Jun 25, 2024
1 parent ba0abc0 commit aa96425
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
26 changes: 19 additions & 7 deletions org-db-fulltext.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ This does not use the arguments pased in update functions."
QUERY should be in fts5 syntax. We use MATCH for the select.
https://www.sqlite.org/fts5.html"
(or
(ivy-more-chars)
(ivy-more-chars)
(let ((org-db-ft (sqlite-open (expand-file-name org-db-fulltext org-db-root)))
(statement (format "select snippet(fulltext, 1, '', '', '', 8), filename
from fulltext where contents match '%s'" query)))
from fulltext where contents match '%s'%s"
query
(if org-db-project-p
(format " and filename match '\"^%s\"'" (projectile-project-root))
""))))

(prog1
(cl-loop for (snippet fname) in
(sqlite-select org-db-ft statement)
Expand All @@ -61,8 +66,7 @@ from fulltext where contents match '%s'" query)))
;; the full text might have :: in it.
collect
;; (cons snippet fname)
(format "%s :: %s" snippet fname)
)
(format "%s :: %s" snippet fname))
(sqlite-close org-db-ft)))))


Expand All @@ -75,10 +79,15 @@ from fulltext where contents match '%s'" query)))
(search-forward snippet nil t)))


(defun org-db-fulltext-search ()
(defvar org-db-project-p nil
"Boolean for limiting search to current project.")

(defun org-db-fulltext-search (&optional project)
"Search the fulltext database.
This function opens the file that matches your query string."
(interactive)
This function opens the file that matches your query string.
With optional prefix arg PROJECT limit query to current project."
(interactive "P")
(setq org-db-project-p project)
(ivy-read "query: " #'org-db-fulltext-candidates
:dynamic-collection t
:action #'org-db-fulltext-open))
Expand Down Expand Up @@ -115,3 +124,6 @@ This function opens the file that matches your query string."
(provide 'org-db-fulltext)

;;; org-db-fulltext.el ends here
;; Local Variables:
;; eval: (sem-mode)
;; End:
14 changes: 10 additions & 4 deletions org-db-images.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ This is much faster than putting it on the candidates at creation time"
(ivy-configure 'org-db-images :display-transformer-fn #'org-db-candidate-transformer)


(defun org-db-images ()
(defun org-db-images (&optional project)
"Search the images database."
(interactive)
(interactive "P")
(let* ((db-candidates (with-org-db
(sqlite-select org-db "select images.text, images.img_filename, images.position, files.filename
(sqlite-select
org-db
(format
"select images.text, images.img_filename, images.position, files.filename
from images
inner join files on files.rowid = images.filename_id")))
inner join files on files.rowid = images.filename_id%s"
(if project
(format " where files.filename like \"%s%%\"" (projectile-project-root))
"")))))
(candidates (cl-loop for (text fname position ofile) in db-candidates collect
(list
(s-join " " (s-split "\n" text))
Expand Down
34 changes: 23 additions & 11 deletions org-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -1275,13 +1275,19 @@ where properties.property = \"ADDRESS\""))))


;; * org-db src-blocks
(defun org-db-src-blocks ()
"Search src blocks."
(interactive)
(defun org-db-src-blocks (&optional project)
"Search src blocks.
Optional PROJECT prefix arg to limit to current project."
(interactive "P")

(let* ((src-blocks (with-org-db
(sqlite-select org-db "select src_blocks.language, src_blocks.contents,
src_blocks.begin, files.filename from src_blocks inner join files on files.rowid = src_blocks.filename_id")))
(sqlite-select
org-db
(format "select src_blocks.language, src_blocks.contents,
src_blocks.begin, files.filename from src_blocks inner join files on files.rowid = src_blocks.filename_id%s"
(if project
(format " where files.filename like \"%s%%\"" (projectile-project-root))
"")))))
(candidates (cl-loop for (language contents begin filename) in src-blocks collect
(list (format "%s: %s" language contents)
:filename filename :begin begin))))
Expand All @@ -1293,15 +1299,21 @@ src_blocks.begin, files.filename from src_blocks inner join files on files.rowid


;; * org-db headings
(defun org-db-heading-candidates ()
(defun org-db-heading-candidates (&optional project)
"Return heading candidates completion."
(let* ((headings (with-org-db
(sqlite-select org-db "
(sqlite-select
org-db
(format "
select headlines.level, headlines.todo_keyword, headlines.title, headlines.tags,
files.filename, headlines.begin, files.last_updated from headlines
inner join files
on files.rowid = headlines.filename_id
order by files.last_updated desc")))
%s
order by files.last_updated desc"
(if project
(format "where files.filename like \"%s%%\"" (projectile-project-root))
"")))))
(candidates (cl-loop for (level todo title tags filename begin last-updated) in headings
collect
(cons
Expand Down Expand Up @@ -1347,10 +1359,10 @@ order by files.last_updated desc")))


;;;###autoload
(defun org-db-headings ()
(defun org-db-headings (&optional project)
"Use ivy to open a heading with completion."
(interactive)
(let* ((candidates (org-db-heading-candidates)))
(interactive "P")
(let* ((candidates (org-db-heading-candidates project)))
(ivy-read "heading: " candidates
:action
'(1
Expand Down

0 comments on commit aa96425

Please sign in to comment.