emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: pinard@iro.umontreal.ca (François Pinard)
To: David Maus <dmaus@ictsoc.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Capture failure [7.7]
Date: Mon, 19 Dec 2011 00:59:07 -0500	[thread overview]
Message-ID: <871us1f6fo.fsf@iro.umontreal.ca> (raw)
In-Reply-To: <87wr9tk6u8.wl%dmaus@ictsoc.de> (David Maus's message of "Sun, 18 Dec 2011 20:39:11 +0100")

David Maus <dmaus@ictsoc.de> 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	other threads:[~2011-12-19  5:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12  4:24 Capture failure [7.7] François Pinard
2011-12-18 19:39 ` David Maus
2011-12-19  5:59   ` François Pinard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871us1f6fo.fsf@iro.umontreal.ca \
    --to=pinard@iro.umontreal.ca \
    --cc=dmaus@ictsoc.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).