emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Capture failure [7.7]


From: François Pinard
Subject: Re: [O] Capture failure [7.7]
Date: Mon, 19 Dec 2011 00:59:07 -0500
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/23.2 (gnu/linux)

David Maus <address@hidden> writes:

> At Sun, 11 Dec 2011 23:24:28 -0500,
> François Pinard wrote:
 
>> However, I had to make the following modification to get it going.  I'm
>> not sure what are the meaning of "beg" and "end" in this function, so
>> someone knowledgeable should check if (point) is appropriate as a value.
>> 
>> One sure thing is that "beg" and "end" should be initialized, as they
>> get later consulted in the function, and whenever :exact-position got a
>> value, that initialization does not occur.

> As far as I can see :exact-position is set when the target is
> `file+regexp', `file+function', or `function' and the error would be
> triggered if you combine one of these targets with the :prepend
> option.

> What capture template target are you using?

Hello, David.  I presume you are asking for factual information?  Here
it goes (I hope I pulled everything needed).  A few comments follow the code.


(setq org-capture-templates
      '(("a" "Agenda" entry (file+headline "notes.org" "Agenda entries")
         "* TODO %?\n:DEADLINE:%^t\n%a\n  %i")
        ("A" "Agenda HH:MM" entry (file+headline "notes.org" "Agenda entries")
         "* TODO %?\n:DEADLINE:%^T\n%a\n  %i")
        ("c" "ref-select → all files" checkitem
         (function fp-org-goto-file-and-spot)
         "- [ ] %(fp-org-ref-select-data)")
        ("d" "ref-select → this file" checkitem
         (function fp-org-goto-spot)
         "- [ ] %(fp-org-ref-select-data)")
        ("e" "Epsilon" entry (file+headline "epsilon.org" "Reclasser")
         "* %?\n%i")
        ("n" "Notes" entry (file+headline "notes.org" "Reclasser")
         "* %?\n%i")
        ))


(defun fp-org-goto-file-and-spot ()
  (call-interactively 'fp-org-find-file)
  (fp-org-goto-spot))


(defun fp-org-find-file (name)
  (interactive
   (let ((alist '()))
     (with-temp-buffer
       (shell-command (concat "cd " org-directory
                              " && find * -name '*.org'")
                      t)
       (goto-char (point-min))
       (while (not (eobp))
         (let* ((name (buffer-substring
                       (save-excursion (beginning-of-line) (point))
                       (save-excursion (end-of-line) (point))))
                (key (file-name-sans-extension
                       (file-name-nondirectory name))))
           (setq key (replace-regexp-in-string "_" " " key))
           (setq alist (cons (cons key name) alist)))
         (next-line)))
     (let* ((completion-ignore-case t)
            (ido-enable-flex-matching t)
            (selection (ido-completing-read "Org open? " alist nil t)))
       (if selection
           (list (cdr (assoc selection alist)))
         (error "Rien à ouvrir!")))))
  (when name
    (find-file (concat org-directory "/" name))))


(defun fp-org-goto-spot ()
  "Move to where an item might be inserted within the current header.
Remove some extraneous while lines while doing so.  If at end of file
and there is no `* Reclasser' section in the file, add one."
  (org-goto)
  (when (eobp)
    (let ((reclasser "\n* Reclasser\n")
          (todo-reclasser "\n* TODO *Reclasser"))
      (end-of-buffer)
      (unless (or (save-excursion (search-backward reclasser nil t))
                  (save-excursion (search-backward todo-reclasser nil t)))
        (delete-char (- (skip-chars-backward " \t\n")))
        (insert reclasser))))
  (org-back-to-heading)
  (outline-next-heading)
  (delete-char (- (skip-chars-backward " \t\n")))
  (insert "\n")
  (setq fp-org-auto-capture-finalize-flag t))



(defvar fp-org-auto-capture-finalize-flag nil)

(defun fp-org-auto-capture-finalize ()
  (when (and fp-org-auto-capture-finalize-flag
             (buffer-base-buffer (current-buffer))
             (string-match "\\`CAPTURE-" (buffer-name)))
    (org-capture-finalize t)
    (setq fp-org-auto-capture-finalize-flag nil)))

(add-hook 'post-command-hook 'fp-org-auto-capture-finalize)



(defun fp-org-ref-select-data ()
  "Reformat from ref-select to Org mode."
   (with-temp-buffer
     (shell-command-on-region
      (point) (point) "xclip -out -selection clipboard" nil t)
     (goto-char (point-max))
     (if (search-backward " " nil t)
         (let ((url (buffer-substring (1+ (point)) (point-max))))
           (delete-region (1- (point)) (point-max))
           (goto-char (point-min))
           (delete-char 1)
           (while (search-forward "\\\"" nil t)
             (replace-match "\"" nil t))
           (goto-char (point-min))
           (while (search-forward "\\\\" nil t)
             (replace-match "\\" nil t))
           (goto-char (point-min))
           (while (search-forward "[" nil t)
             (replace-match "(" nil t))
           (goto-char (point-min))
           (while (search-forward "]" nil t)
             (replace-match ")" nil t))
           (concat "[[" url "][" (buffer-string) "]]"))
       (buffer-string))))



The "c" entry was causing problems.  But it works after the correction I
sent in my original message.  Before typing "C-c c c" is typed, I use a
small own Google Chrome extension which sets the clipboard  like this:

    "Page title" Url

Proper escaping has already been done by the Chrome extension between
the quotes for problematic characters.  The capture first triggers the
selection of the file which is going to receive the capture, using Ido
in flex mode (which is close to GNOME Do functionality).  Then, a
org-goto locates the item within which I want the capture to be saved.
Finally, exiting the goto automatically completes the capture bypassing
the user confirmation.  Of course, the clipboard is reformatted during
the capture so to comply with Org conventions about links.

François




reply via email to

[Prev in Thread] Current Thread [Next in Thread]