mirror of
https://github.com/org-roam/org-roam
synced 2025-09-16 15:56:48 -05:00
(feature): add jump to point from org-roam buffer (#99)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
### New Features
|
||||
* [#87][gh-87], [#90][gh-90] Support encrypted Org files
|
||||
* [#110][gh-110] Add prefix to `org-roam-insert`, for inserting titles down-cased
|
||||
* [#99](https://github.com/jethrokuan/org-roam/pull/99) Add keybinding so that `<return>` or `mouse-1` in the backlinks buffer visits the source file of the backlink at point
|
||||
|
||||
### Bugfixes
|
||||
* [#86][gh-86] Fix `org-roam--parse-content` incorrect `:to` computation for nested files
|
||||
@@ -23,6 +24,7 @@
|
||||
### Contributors
|
||||
* [@chip2n](https://github.com/chip2n/)
|
||||
* [@l3kn](https://github.com/l3kn/)
|
||||
* [@jdormit](https://github.com/jdormit)
|
||||
|
||||
## 0.1.1 (2020-02-15)
|
||||
|
||||
|
@@ -86,10 +86,11 @@ Like file-name-extension, but does not strip version number."
|
||||
(org-roam--org-file-p path))
|
||||
(goto-char start)
|
||||
(let* ((element (org-element-at-point))
|
||||
(begin (or (org-element-property :content-begin element)
|
||||
(org-element-property :begin element)))
|
||||
(content (or (org-element-property :raw-value element)
|
||||
(buffer-substring
|
||||
(or (org-element-property :content-begin element)
|
||||
(org-element-property :begin element))
|
||||
begin
|
||||
(or (org-element-property :content-end element)
|
||||
(org-element-property :end element)))))
|
||||
(content (string-trim content))
|
||||
@@ -97,13 +98,13 @@ Like file-name-extension, but does not strip version number."
|
||||
(file-truename (buffer-file-name (current-buffer))))))
|
||||
(list :from file-path
|
||||
:to (file-truename (expand-file-name path (file-name-directory file-path)))
|
||||
:content content)))))))
|
||||
:properties (list :content content :point begin))))))))
|
||||
|
||||
(cl-defun org-roam--insert-item (item &key forward backward)
|
||||
"Insert ITEM into FORWARD and BACKWARD cache.
|
||||
|
||||
ITEM is of the form: (:from from-path :to to-path :content preview-content)."
|
||||
(pcase-let ((`(:from ,p-from :to ,p-to :content ,content) item))
|
||||
ITEM is of the form: (:from from-path :to to-path :properties (:content preview-content :point point))."
|
||||
(pcase-let ((`(:from ,p-from :to ,p-to :properties ,props) item))
|
||||
;; Build forward-links
|
||||
(let ((links (gethash p-from forward)))
|
||||
(if links
|
||||
@@ -116,14 +117,14 @@ ITEM is of the form: (:from from-path :to to-path :content preview-content)."
|
||||
(let ((contents-hash (gethash p-to backward)))
|
||||
(if contents-hash
|
||||
(if-let ((contents-list (gethash p-from contents-hash)))
|
||||
(let ((updated (cons content contents-list)))
|
||||
(let ((updated (cons props contents-list)))
|
||||
(puthash p-from updated contents-hash)
|
||||
(puthash p-to contents-hash backward))
|
||||
(progn
|
||||
(puthash p-from (list content) contents-hash)
|
||||
(puthash p-from (list props) contents-hash)
|
||||
(puthash p-to contents-hash backward)))
|
||||
(let ((contents-hash (make-hash-table :test #'equal)))
|
||||
(puthash p-from (list content) contents-hash)
|
||||
(puthash p-from (list props) contents-hash)
|
||||
(puthash p-to contents-hash backward))))))
|
||||
|
||||
(defun org-roam--extract-title ()
|
||||
|
36
org-roam.el
36
org-roam.el
@@ -397,6 +397,25 @@ This is equivalent to removing the node from the graph."
|
||||
(let ((time (org-read-date nil 'to-time nil "Date: ")))
|
||||
(org-roam--new-file-named (format-time-string "%Y-%m-%d" time))))
|
||||
|
||||
(defun org-roam-jump-to-backlink ()
|
||||
"Jumps to original file and location of the backlink content snippet at point"
|
||||
(interactive)
|
||||
(let ((file-from (get-text-property (point) 'file-from))
|
||||
(p (get-text-property (point) 'file-from-point)))
|
||||
(when (and file-from p)
|
||||
(find-file file-from)
|
||||
(goto-char p)
|
||||
(org-show-context))))
|
||||
|
||||
(define-derived-mode org-roam-backlinks-mode org-mode "Backlinks"
|
||||
"Major mode for the org-roam backlinks buffer
|
||||
|
||||
Bindings:
|
||||
\\{org-roam-backlinks-mode-map}")
|
||||
|
||||
(define-key org-roam-backlinks-mode-map [mouse-1] 'org-roam-jump-to-backlink)
|
||||
(define-key org-roam-backlinks-mode-map (kbd "RET") 'org-roam-jump-to-backlink)
|
||||
|
||||
;;; Org-roam buffer updates
|
||||
|
||||
(defun org-roam--find-file (file)
|
||||
@@ -419,8 +438,8 @@ This is equivalent to removing the node from the graph."
|
||||
(cons '(file . org-roam--find-file) org-link-frame-setup))
|
||||
(let ((inhibit-read-only t))
|
||||
(erase-buffer)
|
||||
(when (not (eq major-mode 'org-mode))
|
||||
(org-mode))
|
||||
(when (not (eq major-mode 'org-roam-backlinks-mode))
|
||||
(org-roam-backlinks-mode))
|
||||
(make-local-variable 'org-return-follows-link)
|
||||
(setq org-return-follows-link t)
|
||||
(insert
|
||||
@@ -433,10 +452,15 @@ This is equivalent to removing the node from the graph."
|
||||
(insert (format "** [[file:%s][%s]]\n"
|
||||
file-from
|
||||
(org-roam--get-title-or-slug file-from)))
|
||||
(dolist (content contents)
|
||||
(insert (concat (propertize (s-trim (s-replace "\n" " " content))
|
||||
'font-lock-face 'org-block)
|
||||
"\n\n"))))
|
||||
(dolist (properties contents)
|
||||
(let ((content (propertize
|
||||
(s-trim (s-replace "\n" " "
|
||||
(plist-get properties :content)))
|
||||
'font-lock-face 'org-block
|
||||
'help-echo "mouse-1: visit backlinked note"
|
||||
'file-from file-from
|
||||
'file-from-point (plist-get properties :point))))
|
||||
(insert (format "%s \n\n" content)))))
|
||||
backlinks))
|
||||
(insert "\n\n* No backlinks!")))
|
||||
(read-only-mode 1)))
|
||||
|
Reference in New Issue
Block a user