123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- (require 'org)
- (defvar org-annotate-file-storage-file "~/.org-annotate-file.org"
- "File in which to keep annotations.")
- (defvar org-annotate-file-add-search nil
- "If non-nil then add a link as a second level to the actual
- location in the file")
- (defvar org-annotate-file-always-open t
- "non-nil means always expand the full tree when you visit
- `org-annotate-file-storage-file'.")
- (defun org-annotate-file-elipsify-desc (string &optional after)
- "Strip starting and ending whitespace and replace any chars
- that appear after the value in `after' with '...'"
- (let* ((after (number-to-string (or after 30)))
- (replace-map (list (cons "^[ \t]*" "")
- (cons "[ \t]*$" "")
- (cons (concat "^\\(.\\{" after
- "\\}\\).*") "\\1..."))))
- (mapc (lambda (x)
- (when (string-match (car x) string)
- (setq string (replace-match (cdr x) nil nil string))))
- replace-map)
- string))
- (defun org-annotate-file ()
- "Put a section for the current file into your annotation file"
- (interactive)
- (unless (buffer-file-name)
- (error "This buffer has no associated file."))
- (org-annotate-file-show-section))
- (defun org-annotate-file-show-section (&optional buffer)
- "Visit the buffer named `org-annotate-file-storage-file' and
- show the relevant section"
- (let* ((filename (abbreviate-file-name (or buffer (buffer-file-name))))
- (line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
- (link (org-make-link-string (concat "file:" filename) filename))
- (search-link (org-make-link-string
- (concat "file:" filename "::" line)
- (org-annotate-file-elipsify-desc line))))
- (with-current-buffer (find-file org-annotate-file-storage-file)
- (unless (org-mode-p)
- (org-mode))
- (goto-char (point-min))
- (widen)
- (when org-annotate-file-always-open
- (show-all))
- (unless (search-forward-regexp
- (concat "^* " (regexp-quote link)) nil t)
- (org-annotate-file-add-upper-level link))
- (beginning-of-line)
- (org-narrow-to-subtree)
-
- (when org-annotate-file-add-search
- (unless (search-forward-regexp
- (concat "^** " (regexp-quote search-link)) nil t)
- (org-annotate-file-add-second-level search-link))))))
- (defun org-annotate-file-add-upper-level (link)
- (goto-char (point-min))
- (call-interactively 'org-insert-heading)
- (insert link))
- (defun org-annotate-file-add-second-level (link)
- (goto-char (point-at-eol))
- (call-interactively 'org-insert-subheading)
- (insert link))
- (provide 'org-annotate-file)
|