Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid adding brain properties above the file property drawer #377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions org-brain.el
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,14 @@ PROPERTY could for instance be `org-brain-children-property-name'."
(org-entry-get-multivalued-property (org-brain-entry-marker entry) property)))))
(if (equal propertylist '("")) nil propertylist)))

(defun org-brain--file-point-min ()
"Move point to begining skipping the property drawer if it exists."
(goto-char (point-min))
(when-let (property-range (org-get-property-block))
(goto-char (cdr property-range))
(line-move 1)
(beginning-of-visual-line)))

(defun org-brain-add-relationship (parent child)
"Add external relationship between PARENT and CHILD."
(when (equal parent child)
Expand All @@ -1324,7 +1332,7 @@ PROPERTY could for instance be `org-brain-children-property-name'."
(if (org-brain-filep parent)
;; Parent = File
(org-with-point-at (org-brain-entry-marker parent)
(goto-char (point-min))
(org-brain--file-point-min)
(if (re-search-forward (concat "^#\\+" org-brain-children-property-name ":.*$") nil t)
(insert (concat " " (org-brain-entry-identifier child)))
(insert (concat "#+" org-brain-children-property-name ": "
Expand All @@ -1337,7 +1345,7 @@ PROPERTY could for instance be `org-brain-children-property-name'."
(if (org-brain-filep child)
;; Child = File
(org-with-point-at (org-brain-entry-marker child)
(goto-char (point-min))
(org-brain--file-point-min)
(if (re-search-forward (concat "^#\\+" org-brain-parents-property-name ":.*$") nil t)
(insert (concat " " (org-brain-entry-identifier parent)))
(insert (concat "#+" org-brain-parents-property-name ": "
Expand Down Expand Up @@ -1551,7 +1559,7 @@ If ONEWAY is t, add ENTRY2 as friend of ENTRY1, but not the other way around."
(if (org-brain-filep entry1)
;; Entry1 = File
(org-with-point-at (org-brain-entry-marker entry1)
(goto-char (point-min))
(org-brain--file-point-min)
(if (re-search-forward (concat "^#\\+" org-brain-friends-property-name ":.*$") nil t)
(insert (concat " " (org-brain-entry-identifier entry2)))
(insert (concat "#+" org-brain-friends-property-name ": "
Expand Down Expand Up @@ -2144,7 +2152,7 @@ If run interactively, get ENTRY from context and prompt for TITLE."
(if (org-brain-filep entry)
;; File entry
(org-with-point-at (org-brain-entry-marker entry)
(goto-char (point-min))
(org-brain--file-point-min)
(when (assoc "TITLE" (org-brain-keywords entry))
(re-search-forward "^#\\+TITLE:")
(org-brain-delete-current-line))
Expand All @@ -2168,7 +2176,7 @@ If run interactively, get ENTRY from context."
(org-with-point-at (org-brain-entry-marker entry)
(let ((tag-str (read-string "FILETAGS: "
(mapconcat #'identity org-file-tags ":"))))
(goto-char (point-min))
(org-brain--file-point-min)
(when (assoc "FILETAGS" (org-brain-keywords entry))
(re-search-forward "^#\\+FILETAGS:")
(org-brain-delete-current-line))
Expand All @@ -2195,7 +2203,7 @@ If run interactively use `org-brain-entry-at-pt' and prompt for NICKNAME."
(if (org-brain-filep entry)
(let ((nickname (org-entry-protect-space nickname)))
(org-with-point-at (org-brain-entry-marker entry)
(goto-char (point-min))
(org-brain--file-point-min)
(if (re-search-forward "^#\\+NICKNAMES:.*$" nil t)
(insert (concat " " nickname))
(insert (format "#+NICKNAMES: %s\n" nickname)))
Expand Down