From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcin Borkowski Subject: Re: Clocking in on non-org files Date: Sat, 16 Aug 2014 14:12:48 +0200 Message-ID: <20140816141248.524ea25c@aga-netbook> References: <20131006140745.1a38e497@aga-netbook> <20131006151125.GG2622@kuru.dyndns-at-home.com> <20131006232625.2f42aa85@aga-netbook> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIcr0-0006OG-93 for emacs-orgmode@gnu.org; Sat, 16 Aug 2014 08:13:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIcqu-0007wQ-5b for emacs-orgmode@gnu.org; Sat, 16 Aug 2014 08:13:02 -0400 Received: from msg.wmi.amu.edu.pl ([150.254.78.50]:50851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIcqt-0007wH-Rb for emacs-orgmode@gnu.org; Sat, 16 Aug 2014 08:12:56 -0400 Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id 0777E77B8C for ; Sat, 16 Aug 2014 14:12:54 +0200 (CEST) Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WWozGnfI5hPG for ; Sat, 16 Aug 2014 14:12:53 +0200 (CEST) Received: from aga-netbook (unknown [185.13.171.31]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id C114B77B8A for ; Sat, 16 Aug 2014 14:12:53 +0200 (CEST) In-Reply-To: <20131006232625.2f42aa85@aga-netbook> 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: emacs-orgmode@gnu.org Dnia 2013-10-06, o godz. 23:26:25 Marcin Borkowski napisa=C5=82(a): > Dnia 2013-10-06, o godz. 17:11:25 > Suvayu Ali napisa=C5=82(a): >=20 > > On Sun, Oct 06, 2013 at 02:07:45PM +0200, Marcin Borkowski wrote: > > >=20 > > > I have a bunch of TODO items connected with LaTeX files (in > > > general: projects) I'm working on. I was wondering whether it > > > might be possible and/or wise to set things up so that I could > > > clock in (C-c C-x C-i) in a buffer containing such a file. > > > Currently, executing org-clock-in in a non-Org buffer results in > > > an error (at least with my setup); with a prefix argument, > > > everything is fine, I'm asked for one of the last clocked items. > > > My dream is that I can clock in my buffer with just > >=20 > > Try capture: (info "(org) Template elements"). >=20 > Thanks, I didn't think about it, though it's not exactly what I'm > looking for. My dream setup is like this: I bind globally C-c C-x C-i > to something, and when typing this key sequence /outside/ Org-mode, I > am asked about a /node/ somewhere in my Org files (preferably with > autocompletion, like refiling). Then, apart from starting the clock, > a file-local variable remembering this node is added /to the file I'm > in/ (as a comment at the end, for instance), so that the /next/ time > I'm editing this file, C-c C-x C-i just starts clocking. Hi, I finally had some time & motivation to look into it. Below is my solution. It is not perfect (in fact, probably far from being perfect), but should work. I'd like to hear some comments, especially regarding two issues: (1) whether my keybindings are reasonable (especially C-c C-x C-j, which has different semantics than its Org-mode counterpart, but C-c C-j is already taken e.g. by AUCTeX) and (2) usage of org-insert-link, which asks for the description, which is completely unnecessary here. (This touches one problem I have with Org: it has lots of huge functions, which could be split into smaller ones. For instance, if org-insert-link called a separate function to select the link and another one asking for the description, I could use the former and not care about the latter. But this is a minor issue.) The workflow is as follows: I use org-store-link in e.g. some Org headline, say "* TODO Write a cool book", then go to cool-book.tex and do M-x org-insert-default-link. From now on, in cool-book.tex, I can C-c C-x C-j in cool-book.tex (and look into subtasks of the abovementioned TODO, for example), I can also C-c C-x C-i to clock in, C-c C-x C-o to clock out and C-c C-x C-x to cancel the clock. WDYT? ;;;;;;;;;;;; Code begins here ;;;;;;;;;;;; ;; Org-related functions (clocking and goto) working in arbitrary files (defun org-goto-default-link () "Jumps to the link pointed by the variable org-default-link, which should be a file local variable." (if (boundp 'org-default-link) (let ((org-link org-default-link)) (set-buffer (get-buffer-create "*Org Link Temp Buffer*")) (erase-buffer) (insert org-link) (org-open-at-point-global) (kill-buffer "*Org Link Temp Buffer*")) (error "Not in Org mode and org-default-link not set."))) (defun org-goto-anywhere (&optional alternative-interface) "An interactive wrapper around org-goto-default-link, calling normal org-goto if in Org mode." (interactive) (if (equal major-mode 'org-mode) (org-goto alternative-interface) (org-goto-default-link))) =20 (defun org-clock-in-anywhere (&optional select) "Clock in. If called without prefix and not in Org-mode, clock in the entry pointed by org-default-link." (interactive "P") (if (or select (equal major-mode 'org-mode)) (org-clock-in select) (save-excursion (org-goto-default-link) (org-clock-in)))) (defun org-insert-default-link () "Inserts a link (using org-insert-link) into the org-default-link file local variable. Uses org-insert-link interface, which prompts also for the description, which is irrelevant here." (interactive) (let ((link (save-excursion (switch-to-buffer (get-buffer-create "*Org Link Temp Buffer*")) (erase-buffer) (org-insert-link) (buffer-string)))) (add-file-local-variable 'org-default-link link) (kill-buffer "*Org Link Temp Buffer*"))) =20 (global-set-key (kbd "C-c C-x C-i") 'org-clock-in-anywhere) (global-set-key (kbd "C-c C-x C-o") 'org-clock-out) (global-set-key (kbd "C-c C-x C-j") 'org-goto-anywhere) (global-set-key (kbd "C-c C-x C-x") 'org-clock-cancel) ;;;;;;;;;;;; Code ends here ;;;;;;;;;;;; --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Adam Mickiewicz University