* Capture failure [7.7]
@ 2011-12-12 4:24 François Pinard
2011-12-18 19:39 ` David Maus
0 siblings, 1 reply; 3+ messages in thread
From: François Pinard @ 2011-12-12 4:24 UTC (permalink / raw)
To: emacs-orgmode
Hi, Org mode people.
I had some misery trying to debug a special personal machinery to
capture URLs from Chrome into Org. Not worth detailing here. And
moreover, as it works now, I'm happy with this.
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.
François
P.S. This is using a copy of the Git repository as updated yesterday.
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 566fb96..783fe70 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -913,7 +913,8 @@ it. When it is a variable, retrieve the value. Return whatever we get."
beg end)
(cond
((org-capture-get :exact-position)
- (goto-char (org-capture-get :exact-position)))
+ (goto-char (org-capture-get :exact-position))
+ (setq beg (point) end (point)))
((not target-entry-p)
;; Insert as top-level entry, either at beginning or at end of file
(setq beg (point-min) end (point-max)))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Capture failure [7.7]
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
0 siblings, 1 reply; 3+ messages in thread
From: David Maus @ 2011-12-18 19:39 UTC (permalink / raw)
To: François Pinard; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
At Sun, 11 Dec 2011 23:24:28 -0500,
François Pinard wrote:
>
> Hi, Org mode people.
>
> I had some misery trying to debug a special personal machinery to
> capture URLs from Chrome into Org. Not worth detailing here. And
> moreover, as it works now, I'm happy with this.
>
> 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?
Best,
-- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de
[-- Attachment #2: Type: application/pgp-signature, Size: 230 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Capture failure [7.7]
2011-12-18 19:39 ` David Maus
@ 2011-12-19 5:59 ` François Pinard
0 siblings, 0 replies; 3+ messages in thread
From: François Pinard @ 2011-12-19 5:59 UTC (permalink / raw)
To: David Maus; +Cc: emacs-orgmode
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-19 5:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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).