diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-10-12 23:39:29 +0200 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-10-12 23:39:29 +0200 |
commit | 1b0abee054235ea4ac7589dd92d3939e1386d24a (patch) | |
tree | 91d2aa7d5a810bb0032dfe1585ad8e0023c5f81e /org | |
download | elibs-1b0abee054235ea4ac7589dd92d3939e1386d24a.tar.gz elibs-1b0abee054235ea4ac7589dd92d3939e1386d24a.tar.bz2 |
Initial contents
Diffstat (limited to 'org')
-rw-r--r-- | org/jao-org-gnus.el | 72 | ||||
-rw-r--r-- | org/jao-org-links.el | 29 | ||||
-rw-r--r-- | org/jao-org-popup.el | 31 | ||||
-rw-r--r-- | org/jao-org-tags.el | 61 | ||||
-rw-r--r-- | org/jao-org-utils.el | 37 |
5 files changed, 230 insertions, 0 deletions
diff --git a/org/jao-org-gnus.el b/org/jao-org-gnus.el new file mode 100644 index 0000000..8891e20 --- /dev/null +++ b/org/jao-org-gnus.el @@ -0,0 +1,72 @@ +;; Support for saving Gnus messages by Message-ID +(defun mde-org-gnus-save-by-mid () + (when (memq major-mode '(gnus-summary-mode gnus-article-mode)) + (when (eq major-mode 'gnus-article-mode) + (gnus-article-show-summary)) + (let* ((group gnus-newsgroup-name) + (method (gnus-find-method-for-group group))) + (when (eq 'nnml (car method)) + (let* ((article (gnus-summary-article-number)) + (header (gnus-summary-article-header article)) + (from (mail-header-from header)) + (message-id + (save-match-data + (let ((mid (mail-header-id header))) + (if (string-match "<\\(.*\\)>" mid) + (match-string 1 mid) + (error "Malformed message ID header %s" mid))))) + (date (mail-header-date header)) + (subject (gnus-summary-subject-string))) + (org-store-link-props :type "mid" :from from :subject subject + :message-id message-id :group group + :link (org-make-link "mid:" message-id)) + (apply 'org-store-link-props + :description (org-email-link-description) + org-store-link-plist) + t))))) + +(defvar mde-mid-resolve-methods '() + "List of methods to try when resolving message ID's. For Gnus, +it is a cons of 'gnus and the select (type and name).") +(setq mde-mid-resolve-methods + '((gnus nnml ""))) + +(defvar mde-org-gnus-open-level 1 + "Level at which Gnus is started when opening a link") +(defun mde-org-gnus-open-message-link (msgid) + "Open a message link with Gnus" + (require 'gnus) + (require 'org-table) + (catch 'method-found + (message "[MID linker] Resolving %s" msgid) + (dolist (method mde-mid-resolve-methods) + (cond + ((and (eq (car method) 'gnus) + (eq (cadr method) 'nnml)) + (funcall (cdr (assq 'gnus org-link-frame-setup)) + mde-org-gnus-open-level) + (when gnus-other-frame-object + (select-frame gnus-other-frame-object)) + (let* ((msg-info (nnml-find-group-number + (concat "<" msgid ">") + (cdr method))) + (group (and msg-info (car msg-info))) + (message (and msg-info (cdr msg-info))) + (qname (and group + (if (gnus-methods-equal-p + (cdr method) + gnus-select-method) + group + (gnus-group-full-name group (cdr method)))))) + (when msg-info + (gnus-summary-read-group qname nil t) + (gnus-summary-goto-article message nil t)) + (throw 'method-found t))) + (t (error "Unknown link type")))))) + +(eval-after-load 'org-gnus + '(progn + (add-to-list 'org-store-link-functions 'mde-org-gnus-save-by-mid) + (org-add-link-type "mid" 'mde-org-gnus-open-message-link))) + +(provide 'jao-org-gnus) diff --git a/org/jao-org-links.el b/org/jao-org-links.el new file mode 100644 index 0000000..ca57f69 --- /dev/null +++ b/org/jao-org-links.el @@ -0,0 +1,29 @@ +(require 'org) + +;; doc links +(defvar jao-org--sink-dir "./") +(org-add-link-type "doc" 'jao-org-follow-doc 'identity) +(defun jao-org-follow-doc (link) + (let ((dest-path (concat "./doc/" + (and (boundp 'docs-dir) + (concat (symbol-name docs-dir) "/")) + link))) + (when (not (file-exists-p dest-path)) + (let* ((sink-file (expand-file-name link jao-org--sink-dir)) + (real-file (if (file-exists-p sink-file) sink-file + (read-file-name "Import file: " + jao-org--sink-dir link link)))) + (shell-command (format "mv %s %s" real-file dest-path)))) + (browse-url (format "file://%s" (expand-file-name dest-path))))) + +(defsubst jao-org--title->file (title) + (concat (mapconcat 'downcase (split-string title nil t) "-") ".pdf")) + +(defun jao-org-insert-doc (title) + (interactive "sDocument title: ") + (insert (format "[[doc:%s][%s]]" (jao-org--title->file title) title))) + +(defun jao-org-links-setup (sink-dir) + (setq jao-org--sink-dir (file-name-as-directory sink-dir))) + +(provide 'jao-org-links)
\ No newline at end of file diff --git a/org/jao-org-popup.el b/org/jao-org-popup.el new file mode 100644 index 0000000..eb5b24d --- /dev/null +++ b/org/jao-org-popup.el @@ -0,0 +1,31 @@ +;;; frame popups +;; http://metajack.im/2008/12/30/gtd-capture-with-emacs-orgmode/ +(defsubst jao-remember--frame-p () + (equal "*Remember*" (frame-parameter nil 'name))) + +(defadvice remember-finalize (after delete-remember-frame activate) + "Advise remember-finalize to close the frame if it is the remember frame" + (when (jao-remember--frame-p) (delete-frame))) + +(defadvice remember-destroy (after delete-remember-frame activate) + "Advise remember-destroy to close the frame if it is the remember frame" + (when (jao-remember--frame-p) (delete-frame))) + +;; make the frame contain a single window. by default org-remember +;; splits the window. +(defun jao-remember--delete-other-windows () + (when (jao-remember--frame-p) (delete-other-windows))) + +(add-hook 'remember-mode-hook 'jao-remember--delete-other-windows) + +(defun make-remember-frame () + "Create a new frame and run org-remember" + (interactive) + (make-frame-on-display (getenv "DISPLAY") + '((name . "*Remember*") + (width . 80) + (height . 10))) + (select-frame-by-name "*Remember*") + (org-remember nil ?x)) + +(provide 'jao-org-popup)
\ No newline at end of file diff --git a/org/jao-org-tags.el b/org/jao-org-tags.el new file mode 100644 index 0000000..b00276d --- /dev/null +++ b/org/jao-org-tags.el @@ -0,0 +1,61 @@ +;; lifted from http://orgmode.org/worg/org-hacks.php + +(require 'org) + +(defvar ba/org-adjust-tags-column nil) + +(defun ba/org-adjust-tags-column-reset-tags () + "In org-mode buffers it will reset tag position according to +`org-tags-column'." + (when (and + (not (string= (buffer-name) "*Remember*")) + (eql major-mode 'org-mode)) + (let ((b-m-p (buffer-modified-p))) + (condition-case nil + (save-excursion + (goto-char (point-min)) + (command-execute 'outline-next-visible-heading) + ;; disable (message) that org-set-tags generates + (flet ((message (&rest ignored) nil)) + (org-set-tags 1 t)) + (set-buffer-modified-p b-m-p)) + (error nil))))) + +(defun ba/org-adjust-tags-column-now () + "Right-adjust `org-tags-column' value, then reset tag position." + (set (make-local-variable 'org-tags-column) + (- (- (window-width) 3))) + (ba/org-adjust-tags-column-reset-tags)) + +(defun ba/org-adjust-tags-column-maybe () + "If `ba/org-adjust-tags-column' is set to non-nil, adjust tags." + (when ba/org-adjust-tags-column + (ba/org-adjust-tags-column-now))) + +(defun ba/org-adjust-tags-column-before-save () + "Tags need to be left-adjusted when saving." + (when ba/org-adjust-tags-column + (setq org-tags-column 1) + (ba/org-adjust-tags-column-reset-tags))) + +(defun ba/org-adjust-tags-column-after-save () + "Revert left-adjusted tag position done by before-save hook." + (ba/org-adjust-tags-column-maybe) + (set-buffer-modified-p nil)) + +;; automatically align tags on right-hand side +(defun jao-org-tags-setup () + (setq ba/org-adjust-tags-column t) + (add-hook 'window-configuration-change-hook + 'ba/org-adjust-tags-column-maybe) + (add-hook 'before-save-hook 'ba/org-adjust-tags-column-before-save) + (add-hook 'after-save-hook 'ba/org-adjust-tags-column-after-save)) + +(defun jao-org-tags-uninstall () + (setq ba/org-adjust-tags-column nil) + (remove-hook 'window-configuration-change-hook + 'ba/org-adjust-tags-column-maybe) + (remove-hook 'before-save-hook 'ba/org-adjust-tags-column-before-save) + (remove-hook 'after-save-hook 'ba/org-adjust-tags-column-after-save)) + +(provide 'jao-org-tags) diff --git a/org/jao-org-utils.el b/org/jao-org-utils.el new file mode 100644 index 0000000..535e8f4 --- /dev/null +++ b/org/jao-org-utils.el @@ -0,0 +1,37 @@ +(require 'org) + +;;; links +(defun jao-org-link-at-point () + (when (thing-at-point-looking-at "\\[\\[\\([^]]+\\)\\]\\[[^]]+\\]\\]") + (match-string-no-properties 1))) + +(defun jao-org-copy-link-at-point () + (interactive) + (message "%s" (or (jao-org-link-at-point) "No link at point"))) + +;;; eldoc +(defun jao-org-eldoc--hook () + (set (make-local-variable 'eldoc-documentation-function) + 'jao-org-link-at-point) + (eldoc-mode)) + +(defun jao-org-utils-eldoc-setup () + (add-hook 'org-mode-hook 'jao-org-eldoc--hook)) + +;;; play fair with saveplace +(defun jao-org--show-if-hidden () + (when (outline-invisible-p) + (save-excursion + (outline-previous-visible-heading 1) + (org-show-subtree)))) + +;;; verifying org refile targets +(defun jao-org--refile-target-verify () + (not (looking-at-p ".*\\[\\[.+$"))) + +(defun jao-org-utils-setup () + (setq org-refile-target-verify-function 'jao-org--refile-target-verify) + (add-hook 'org-mode-hook 'jao-org--show-if-hidden t)) + + +(provide 'jao-org-utils) |