org-projectile tweaks.

This commit is contained in:
Ivan Malison 2014-12-08 04:34:31 -08:00
parent 7ae7909304
commit 946c6230b4
2 changed files with 91 additions and 26 deletions

View File

@ -277,13 +277,15 @@ The current directory is assumed to be the project's root otherwise."
(or (--reduce-from (or (--reduce-from
(or acc (or acc
(let* ((cache-key (format "%s-%s" it dir)) (let* ((cache-key (format "%s-%s" it dir))
(cache-value (gethash cache-key projectile-project-root-cache))) (cache-value (gethash cache-key
projectile-project-root-cache)))
(if cache-value (if cache-value
(if (eq cache-value 'no-project-root) (if (eq cache-value 'no-project-root)
nil nil
cache-value) cache-value)
(let ((value (funcall it dir))) (let ((value (funcall it dir)))
(puthash cache-key (or value 'no-project-root) projectile-project-root-cache) (puthash cache-key (or value 'no-project-root)
projectile-project-root-cache)
value)))) value))))
nil nil
projectile-project-root-files-functions) projectile-project-root-files-functions)
@ -331,20 +333,17 @@ The current directory is assumed to be the project's root otherwise."
(eval-after-load 'subword '(diminish 'subword-mode)) (eval-after-load 'subword '(diminish 'subword-mode))
(display-time-mode 1)
;; =============================================================================
;; use-package
;; =============================================================================
;; Set path from shell. ;; Set path from shell.
(use-package exec-path-from-shell (use-package exec-path-from-shell
:ensure t :ensure t
:config (exec-path-from-shell-initialize)) :config (exec-path-from-shell-initialize))
(use-package load-dir
:ensure t
:config
(progn
(add-to-list 'load-dirs "~/.emacs.d/load.d")
(defvar site-lisp "/usr/share/emacs24/site-lisp/")
(when (file-exists-p site-lisp) (add-to-list 'load-dirs site-lisp))))
(use-package tramp (use-package tramp
:commands tramp :commands tramp
:config :config
@ -506,6 +505,14 @@ The current directory is assumed to be the project's root otherwise."
:commands string-inflection-toggle :commands string-inflection-toggle
:bind ("C-c l" . string-inflection-toggle)) :bind ("C-c l" . string-inflection-toggle))
(use-package load-dir
:ensure t
:config
(progn
(add-to-list 'load-dirs "~/.emacs.d/load.d")
(defvar site-lisp "/usr/share/emacs24/site-lisp/")
(when (file-exists-p site-lisp) (add-to-list 'load-dirs site-lisp))))
;; ============================================================================= ;; =============================================================================
;; Non-Programming Stuff ;; Non-Programming Stuff
;; ============================================================================= ;; =============================================================================

View File

@ -1,11 +1,63 @@
;;; org-projectile.el --- Repository todo management for org-mode
;; Copyright (C) 2014 Ivan Malison
;; Author: Ivan Malison <IvanMalison@gmail.com>
;; Keywords: org projectile todo
;; URL: https://github.com/IvanMalison/org-projectile
;; Version: 0.0.0
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This package aims to provide an easy interface to creating per
;; project org-mode TODO headings.
;;; Code:
(require 'org-capture)
(require 'projectile)
(defvar org-projectile:projects-file "~/org/projects.org") (defvar org-projectile:projects-file "~/org/projects.org")
(defun org-projectile:project-root-of-filepath (filepath)
"Retrieves the root directory of the project to which filepath
belongs, if available."
(file-truename
(let ((dir (file-truename filepath)))
(--reduce-from
(or acc
(let* ((cache-key (format "%s-%s" it dir))
(cache-value (gethash cache-key projectile-project-root-cache)))
(if cache-value
(if (eq cache-value 'no-project-root)
nil
cache-value)
(let ((value (funcall it dir)))
(puthash cache-key (or value 'no-project-root) projectile-project-root-cache)
value))))
nil
projectile-project-root-files-functions))))
(defun org-projectile:project-todo-entry (&optional todo-format) (defun org-projectile:project-todo-entry (&optional todo-format)
(unless todo-format (setq todo-format "* TODO %?\n")) (unless todo-format (setq todo-format "* TODO %?\n"))
`("p" "Project Todo" entry `("p" "Project Todo" entry
(file+function ,org-projectile:projects-file (file+function ,org-projectile:projects-file
(lambda () (let ((heading (org-projectile:insert-heading-for-filename (lambda () (let ((heading
(org-capture-get :original-file)))) (org-projectile:insert-heading-for-filename
(org-capture-get :original-file))))
(org-projectile:insert-or-goto-heading heading) (org-projectile:insert-or-goto-heading heading)
(org-end-of-line) (org-end-of-line)
heading))) heading)))
@ -13,7 +65,7 @@
(defun org-projectile:project-heading-from-file (filename) (defun org-projectile:project-heading-from-file (filename)
(file-name-nondirectory (file-name-nondirectory
(directory-file-name (project-root-of-file filename)))) (directory-file-name (org-projectile:project-root-of-filepath filename))))
(defun org-projectile:insert-heading-for-filename (filename) (defun org-projectile:insert-heading-for-filename (filename)
(let ((project-heading (let ((project-heading
@ -24,22 +76,21 @@
project-heading)) project-heading))
(defun org-projectile:known-projects () (defun org-projectile:known-projects ()
(delete-dups `(,@(mapcar #'org-projectile:project-heading-from-file (projectile-relevant-known-projects)) (delete-dups `(,@(mapcar #'org-projectile:project-heading-from-file
,@(org-map-entries (lambda () (nth 4 (org-heading-components))) nil (list org-projectile:projects-file) (projectile-relevant-known-projects))
(lambda () (when (< 1 (nth 1 (org-heading-components))) (point))))))) ,@(org-map-entries
(lambda () (nth 4 (org-heading-components))) nil
(list org-projectile:projects-file)
(defun org-projectile:project-todo-completing-read () (lambda ()
(interactive) (when (< 1 (nth 1 (org-heading-components)))
(org-projectile:capture-for-project (point)))))))
(projectile-completing-read "Record TODO for project:"
(org-projectile:known-projects))))
(defun org-projectile:capture-for-project (heading) (defun org-projectile:capture-for-project (heading)
(org-capture-set-plist (org-projectile:project-todo-entry)) (org-capture-set-plist (org-projectile:project-todo-entry))
(with-current-buffer (find-file-noselect org-projectile:projects-file) (with-current-buffer (find-file-noselect org-projectile:projects-file)
(org-projectile:project-heading heading)) (org-projectile:project-heading heading))
(org-capture-set-target-location `(file+headline ,org-projectile:projects-file ,heading)) (org-capture-set-target-location `(file+headline
,org-projectile:projects-file ,heading))
(org-capture-place-template)) (org-capture-place-template))
(defun org-projectile:insert-or-goto-heading (heading) (defun org-projectile:insert-or-goto-heading (heading)
@ -66,5 +117,12 @@
(org-beginning-of-line) (org-beginning-of-line)
(org-set-property "CATEGORY" heading)) (org-set-property "CATEGORY" heading))
(require 'org-capture) ;;;###autoload
(require 'projectile) (defun org-projectile:project-todo-completing-read ()
(interactive)
(org-projectile:capture-for-project
(projectile-completing-read "Record TODO for project:"
(org-projectile:known-projects))))
(provide 'org-projectile)
;;; org-projectile.el ends here