daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Jan 21st, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (require 'org-build)
  2.  
  3. (defun knowt-elisp-directory ()
  4.   (concat (getenv "KNOWT_SOURCE_DIRECTORY") "elisp/"))
  5. (message (format "knowt-elisp-directory: %s" (knowt-elisp-directory)))
  6.  
  7. (defun user-init-file () (concat (knowt-elisp-directory) "elisp" "init.el"))
  8. (message (format "user-init-file: %s" (user-init-file)))
  9.  
  10. (defun knowt-user-directory ()
  11.   (file-name-as-directory (or (getenv "KNOWT_USER_DIRECTORY") (expand-file-name "~/.knowt/"))))
  12. (message (format "knowt-user-directory: %s" (knowt-user-directory)))
  13.  
  14. (defun knowt-emacs-directory ()
  15.   (file-name-as-directory (concat (knowt-user-directory) ".emacs.d/")))
  16. (message (format "knowt-emacs-directory: %s" (knowt-emacs-directory)))
  17.  
  18. (defun knowt-emacs-file (filename)
  19.   (concat (knowt-emacs-directory) (file-name-nondirectory filename)))
  20. (message (format "knowt-emacs-file: %s" (knowt-emacs-file "FOO")))
  21.  
  22. (defun knowt-user-file (filename)
  23.   (concat (knowt-user-directory) (file-name-nondirectory filename)))
  24. (message (format "knowt-user-file: %s" (knowt-user-file "FOO")))
  25.  
  26. (defun knowt-mode-el-file ()
  27.   (concat (knowt-emacs-directory) "knowt-mode.el"))
  28. (message (format "knowt-mode-el-file: %s" (knowt-mode-el-file)))
  29.  
  30. (defun knowt-user-org-file ()
  31.   (concat (knowt-emacs-directory) "init.org"))
  32. (message (format "knowt-user-org-file: %s" (knowt-user-org-file)))
  33.  
  34. (defun knowt-user-el-file ()
  35.   (concat (knowt-emacs-directory) "init.el"))
  36. (message (format "knowt-user-el-file: %s" (knowt-user-el-file)))
  37.  
  38. (defun knowt-build-el-file ()
  39.   (concat (knowt-elisp-directory) "org-build.el"))
  40. (message (format "knowt-build-el-file: %s" (knowt-build-el-file)))
  41.  
  42. (defun knowt-org-file ()
  43.   (concat (knowt-user-directory) "knowt.org"))
  44. (message (format "knowt-org-file: %s" (knowt-org-file)))
  45.  
  46. (defun knowt-build-custom-org ()
  47.   (org-build (knowt-user-org-file) (knowt-user-el-file)))
  48.  
  49. (defun knowt-build-custom ()
  50.   (if (file-exists-p (knowt-user-org-file))
  51.       (progn
  52.         (knowt-build-custom-org)
  53.         (if (file-exists-p (knowt-user-el-file))
  54.             (load-file (knowt-user-el-file))))))
  55.  
  56. (defun knowt-reload ()
  57.   (unload-feature 'knowt-mode)
  58.   (message (format "WTFFF %s" (knowt-mode-el-file)))
  59.   (load-file (knowt-mode-el-file))
  60.   (knowt-mode 1))
  61.  
  62. (defun knowt-reset ()
  63.   (delete-other-windows)
  64.   (switch-to-buffer "knowt.org")
  65.   (widen)
  66.   (org-mode-restart)
  67.   (org-global-cycle 1)
  68.   (beginning-of-buffer)
  69.   (search-forward "* Knowt Help")
  70.   (org-cycle)
  71.   (beginning-of-buffer)
  72.   (knowt-reload))
  73.  
  74. (defun knowt-check-bookmark ()
  75.   (if (org-entry-get nil "url")
  76.       (browse-url (org-entry-get nil "url"))))
  77.  
  78. (defun narrow-to-subtree ()
  79.   (org-narrow-to-subtree)
  80.   (beginning-of-buffer)
  81.   (outline-hide-subtree)
  82.   (outline-show-children)
  83.   (org-show-entry)
  84.   (knowt-check-bookmark))
  85.  
  86. (defun knowt-narrow-regexp (term)
  87.   (beginning-of-buffer)
  88.   (search-forward-regexp (format "^[\\*].*%s" term))
  89.   (knowt-narrow-to-subtree))
  90.  
  91. (defun knowt-narrow-occur ()
  92.   (helm-occur)
  93.   (knowt-narrow-to-subtree))
  94.  
  95. (defun knowt-narrow-heading ()
  96.   (helm-org-in-buffer-headings)
  97.   (outline-hide-subtree)
  98.   (knowt-narrow-to-subtree))
  99.  
  100. (define-minor-mode knowt-mode
  101.   "Provide functions useful for knowt.org"
  102.   :lighter " Knowt"
  103.   :keymap (let ((map (make-sparse-keymap)))
  104.             (global-set-key (kbd "<f19> <f19>") (lambda () (interactive) (knowt-reset)))
  105.             (global-set-key (kbd "<f19> m")
  106.                             (lambda () (interactive)
  107.                               (find-file-other-window (knowt-mode-org-file))))
  108.             (define-key map (kbd "M-n") 'outline-next-visible-heading)
  109.             (define-key map (kbd "M-p") 'outline-previous-visible-heading)
  110.             (define-key map (kbd "M-N") 'outline-next-heading)
  111.             (define-key map (kbd "M-P") 'outline-previous-heading)
  112.             (define-key map (kbd "<f19> s") (lambda () (interactive) (knowt-narrow-occur)))
  113.             (define-key map (kbd "<f19> h") (lambda () (interactive) (knowt-narrow-heading)))
  114.             (define-key map (kbd "<f19> n") (lambda () (interactive) (knowt-narrow-to-subtree)))
  115.             (define-key map (kbd "<f19> t") 'org-show-todo-tree)
  116.             (define-key map (kbd "<f19> a") 'org-agenda)
  117.             map)
  118.   :after-hook (progn
  119.                 (setq ace-jump-helm-line-default-action 'select)
  120.                 (setq org-confirm-elisp-link-function nil)
  121.                 (setq org-confirm-shell-link-function nil)
  122.                 (setq org-agenda-files (list (knowt-org-file)))
  123.                 (setq org-agenda-sorting-strategy '(todo-state-up priority-down effort-up))
  124.                 (message "knowt-mode ready!")))
  125. (provide 'knowt-mode)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top