From mboxrd@z Thu Jan 1 00:00:00 1970 From: pinard@iro.umontreal.ca (=?utf-8?Q?Fran=C3=A7ois?= Pinard) Subject: Re: Capture failure [7.7] Date: Mon, 19 Dec 2011 00:59:07 -0500 Message-ID: <871us1f6fo.fsf@iro.umontreal.ca> References: <8739cqo1s3.fsf@iro.umontreal.ca> <87wr9tk6u8.wl%dmaus@ictsoc.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:58129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcWFi-0001iy-VE for emacs-orgmode@gnu.org; Mon, 19 Dec 2011 00:59:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RcWFh-00060H-Li for emacs-orgmode@gnu.org; Mon, 19 Dec 2011 00:59:10 -0500 Received: from 206-248-137-202.dsl.teksavvy.com ([206.248.137.202]:56215 helo=mercure.epsilon-ti.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcWFh-00060D-En for emacs-orgmode@gnu.org; Mon, 19 Dec 2011 00:59:09 -0500 In-Reply-To: <87wr9tk6u8.wl%dmaus@ictsoc.de> (David Maus's message of "Sun, 18 Dec 2011 20:39:11 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: David Maus Cc: emacs-orgmode@gnu.org David Maus writes: > At Sun, 11 Dec 2011 23:24:28 -0500, > Fran=C3=A7ois Pinard wrote: =20 >> 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. >>=20 >> 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 cod= e. (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 entrie= s") "* TODO %?\n:DEADLINE:%^T\n%a\n %i") ("c" "ref-select =E2=86=92 all files" checkitem (function fp-org-goto-file-and-spot) "- [ ] %(fp-org-ref-select-data)") ("d" "ref-select =E2=86=92 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 =C3=A0 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=C3=A7ois