7272 org-projectile:per-repo-filename))
7373
7474(defun org-projectile:project-name-to-location-per-repo (_project-name )
75- (goto-char (point-max )))
75+ (goto-char (point-max ))
76+ nil )
7677
7778(defun org-projectile:per-repo ()
7879 " Use org-projectile in per-repo mode."
8990
9091(defun org-projectile:get-approach-for-project (project-name )
9192 (or (cdr (assoc project-name org-projectile:project-to-approach))
92- org-projectile:default-approach))
93+ org-projectile:default-approach))
9394
9495(defun org-projectile:project-name-to-org-file-hybrid (project-name )
9596 (let ((approach (org-projectile:get-approach-for-project project-name)))
96- (cond
97+ (cond
9798 ((equal approach 'one-file )
9899 (org-projectile:project-name-to-org-file-one-file project-name))
99100 ((equal approach 'per-repo )
194195 (read-file-name (concat " org-mode file for " project-name " : " )
195196 (file-name-directory org-projectile:projects-file)))
196197
197- (defun org-projectile:set-project-file-default (&optional project-to-org-filepath-filepath )
198+ (defun org-projectile:set-project-file-default
199+ (&optional project-to-org-filepath-filepath)
198200 " Set the filepath for any known projects that do not have a filepath.
199201
200202If PROJECT-TO-ORG-FILEPATH-FILEPATH is provided use that as the
@@ -211,12 +213,13 @@ location of the filepath cache."
211213(defun org-projectile:find-project-in-known-files (project-name )
212214 (cl-loop for org-file in (funcall org-projectile:todo-files) when
213215 (-contains-p
214- (org-map-entries (lambda () (org-projectile:get-link-description
215- (nth 4 (org-heading-components )))) nil
216- (list org-file)
217- (lambda ()
218- (when (< 1 (nth 1 (org-heading-components )))
219- (point )))) project-name)
216+ (org-map-entries (lambda ()
217+ (org-projectile:get-link-description
218+ (nth 4 (org-heading-components )))) nil
219+ (list org-file)
220+ (lambda ()
221+ (when (< 1 (nth 1 (org-heading-components )))
222+ (point )))) project-name)
220223 return org-file))
221224
222225(fset 'org-projectile:project-name-to-location-prompt
@@ -249,16 +252,18 @@ location of the filepath cache."
249252(defun org-projectile:location-for-project (project-name &optional for-insert )
250253 (let* ((filename (funcall org-projectile:project-name-to-org-file project-name)))
251254 (switch-to-buffer (find-file-noselect filename))
252- (funcall org-projectile:project-name-to-location project-name)
253- (org-end-of-line )
254- (org-projectile:end-of-properties)
255- ; ; It sucks that this has to be done, but we have to insert a
256- ; ; subheading if the entry does not have one in order to convince
257- ; ; capture to actually insert the template as a subtree of the
258- ; ; selected entry. We return a marker where the dummy subheading
259- ; ; was created so that it can be deleted later.
260- (when (and for-insert (not (save-excursion (org-goto-first-child ))))
261- (save-excursion (org-insert-subheading nil ) (point-marker )))))
255+ (funcall org-projectile:project-name-to-location project-name)))
256+
257+ (defun org-projectile:target-subheading-and-return-marker ()
258+ (org-end-of-line )
259+ (org-projectile:end-of-properties)
260+ ; ; It sucks that this has to be done, but we have to insert a
261+ ; ; subheading if the entry does not have one in order to convince
262+ ; ; capture to actually insert the template as a subtree of the
263+ ; ; selected entry. We return a marker where the dummy subheading
264+ ; ; was created so that it can be deleted later.
265+ (when (and for-insert (not (save-excursion (org-goto-first-child ))))
266+ (save-excursion (org-insert-subheading nil ) (point-marker )))))
262267
263268(defun org-projectile:file-truename (filepath )
264269 (when filepath
@@ -268,7 +273,8 @@ location of the filepath cache."
268273 (org-projectile:file-truename
269274 (let ((dir (file-name-directory filepath)))
270275 (--some (let* ((cache-key (format " %s -%s " it dir))
271- (cache-value (gethash cache-key projectile-project-root-cache)))
276+ (cache-value (gethash
277+ cache-key projectile-project-root-cache)))
272278 (if cache-value
273279 cache-value
274280 (let ((value (funcall it (org-projectile:file-truename dir))))
@@ -304,31 +310,37 @@ location of the filepath cache."
304310 (match-string-no-properties 4 ) heading)))
305311
306312(defun org-projectile:known-projects ()
307- (remove-if #'null (delete-dups `(,@(mapcar #'org-projectile:project-heading-from-file
308- (projectile-relevant-known-projects))
309- ,@(org-map-entries
310- (lambda () (org-projectile:get-link-description
311- (nth 4 (org-heading-components )))) nil
312- (funcall org-projectile:todo-files)
313- (lambda ()
314- (when (< 1 (nth 1 (org-heading-components )))
315- (point ))))))))
313+ (remove-if
314+ #'null
315+ (delete-dups
316+ `(,@(mapcar #'org-projectile:project-heading-from-file
317+ (projectile-relevant-known-projects))
318+ ,@(org-map-entries
319+ (lambda () (org-projectile:get-link-description
320+ (nth 4 (org-heading-components )))) nil
321+ (funcall org-projectile:todo-files)
322+ (lambda ()
323+ (when (< 1 (nth 1 (org-heading-components )))
324+ (point ))))))))
316325
317326(defun org-projectile:todo-files ()
318327 (funcall org-projectile:todo-files))
319328
320329(defun org-projectile:default-todo-files ()
321- (cl-remove-if-not #'file-exists-p
322- (delete-dups (cl-loop for project-name in
323- (mapcar #'org-projectile:project-heading-from-file
324- (projectile-relevant-known-projects))
325- collect (funcall org-projectile:project-name-to-org-file
326- project-name)))))
330+ (cl-remove-if-not
331+ #'file-exists-p
332+ (delete-dups
333+ (cl-loop for project-name in
334+ (mapcar #'org-projectile:project-heading-from-file
335+ (projectile-relevant-known-projects))
336+ collect (funcall org-projectile:project-name-to-org-file
337+ project-name)))))
327338
328339(defun org-projectile:project-name-to-location-alist ()
329340 (cl-loop for project-location in projectile-known-projects
330- collect `(,(file-name-nondirectory (directory-file-name project-location)) .
331- , project-location )))
341+ collect `(,(file-name-nondirectory
342+ (directory-file-name project-location)) .
343+ , project-location )))
332344
333345(defun org-projectile:project-location-from-name (name )
334346 (cdr (assoc name (org-projectile:project-name-to-location-alist))))
@@ -346,7 +358,8 @@ location of the filepath cache."
346358 org-capture-link-is-already-stored)
347359 (plist-get org-store-link-plist :annotation )
348360 (ignore-errors (org-store-link nil ))))
349- org-projectile:subheading-cleanup-marker)
361+ org-projectile:subheading-cleanup-marker
362+ org-projectile:do-target-entry)
350363 (org-capture-put :original-buffer orig-buf
351364 :original-file (or (buffer-file-name orig-buf)
352365 (and (featurep 'dired )
@@ -363,15 +376,18 @@ location of the filepath cache."
363376 (org-current-time )))
364377 (org-capture-put :template (org-capture-fill-template capture-template))
365378 (org-capture-set-target-location
366- `(function ,(lambda () (setq org-projectile:subheading-cleanup-marker
379+ `(function ,(lambda () (setq org-projectile:do-target-entry
367380 (org-projectile:location-for-project project-name t )))))
368381 ; ; Apparently this needs to be forced because (org-at-heading-p)
369382 ; ; will not be true and so `org-capture-set-target-location` will
370383 ; ; set this value to nil.
371384 ; ; TODO(@IvanMalison): Perhaps there is a better way to do this?
372385 ; ; Maybe something that would allow us to get rid of the horrible
373386 ; ; subheading-cleanup-marker hack?
374- (org-capture-put :target-entry-p t )
387+ (org-capture-put :target-entry-p org-projectile:do-target-entry)
388+ (when org-projectile:do-target-entry
389+ (setq org-projectile:subheading-cleanup-marker
390+ (org-projectile:target-subheading-and-return-marker)))
375391 (org-capture-place-template)
376392 (when org-projectile:subheading-cleanup-marker
377393 (org-projectile:cleanup-subheading
0 commit comments