I'm running
/usr/bin/emacs -l ~/.emacs -eval '(org-icalendar-export-agenda-files)' --batch
in a cron job.
Orgmode adds the uuid to the properties of new todo items in the agenda files, but then prompts to save the agenda files (only when run from the command line in batch mode).
Save file /home/user/gtd/work.org? (y or n)
My cludgy work around is to echo y | /usr/bin/emacs.... But since there are actually 3 agenda files that are potentially modified, this is not a good solution. There must be some variable to set or something that will cause org-icalendar-export-agenda-files to just save the files it modifies.
Using defadvice is not a good practice in general1 but, if you want to fix this and can't wait your fix to get included in the next emacs release, try this:
(defadvice org-icalendar-create-uid (after org-icalendar-create-uid-after activate)
(save-buffer))
This advices org-icalendar-create-uid so that when a new UID is created, the current buffer gets saved2. You need to be really careful advising functions. I would recommend to create a export-icalendar.el script similar to this:
;; initialize org-mode
(require 'org)
;; pick your agenda files
(setq org-agenda-files '("~/org"))
;; store UIDs in properties drawer
(setq org-icalendar-store-UID t)
;; optional configuration
(setq org-icalendar-use-scheduled '(event-if-todo event-if-not-todo))
(setq org-agenda-default-appointment-duration 50)
;; avoid interactive prompts if UIDs are created
(defadvice org-icalendar-create-uid (after org-icalendar-create-uid-after activate)
(save-buffer))
(org-icalendar-combine-agenda-files)
To run it, do it like this3:
emacs --batch -l export-icalendar.el
1: http://emacswiki.org/emacs/AdvisingFunctions
2: org-icalendar-create-uid is called inside with-current-buffer, see ox-icalendar.el for details.
3: Never run org-icalendar-combine-agenda-files through eval using emacsclient, it causes problems if you were already visiting agenda files.
Would you be helped by
the function save-some-buffers
in emacs?
Like in
/usr/bin/emacs -l ~/.emacs -eval '(progn (org-icalendar-export-agenda-files) (save-some-buffers t))' --batch
Yes, it can been seen as a kludge.
Related
How can I make eshell autocomplete behave like Bash and Emacs in general i.e. it offers a list of choices rather than arbitrary selects one for you?
For example, if I have two directories "Download" and "Downloads", when I type "Down" and hit TAB, I expect another buffer pops up and shows me the choices. But eshell just completes it for me, i.e. if I press TAB, it completes to "Download"; hit TAB again, it changes to "Downloads".
Use this:
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
and
(setq eshell-cmpl-cycle-completions nil)
Both do as you ask and show a buffer listing the completions when I run my emacs as 'emacs -q' to avoid my own customizations. This is with emacs 23.3, are you running a much older version?
Also see http://www.emacswiki.org/emacs/EshellCompletion which is where I first went to check this out.
Steps to try this out:
Start emacs using 'emacs -q' as the command -- no other arguments.
Change to the *scratch* buffer
Paste or type in one of the above code snippets
Put your cursor at the end of the snippet and press 'C-e' to execute the code.
Start eshell
test
if neither one works, report back here with your version info and any other relevant details
You only need to have the following line:
(setq eshell-cmpl-cycle-completions nil)
eshell-mode automatically set pcomplete-cycle-completions to the value of eshell-cmpl-cycle-completions locally.
I have a perltidy-mode.el lisp file, which is being loaded - I can call it manually by M-x perltidy-mode.
What would be the proper way to run it automatically after a file is opened (or emacs is loaded)?
(defalias 'perl-mode 'cperl-mode)
(defalias 'perl-mode 'perltidy-mode)
doesn't seem to work.
It seems I've forgotten a lot of lisp/emacs
If you would like to activate it for every opened perl file, you can add it to a hook:
(defun my-perl-hook ()
(perltidy-mode 1))
(add-hook 'perl-mode-hook 'my-perl-hook)
Note: I know nothing about this mode, or about the different perl modes, so you might to add your function to other hooks as well.
I am upgrading to emacs23. I find that my emacs.el loads much more slowly.
It's my own fault really... I have a lot of stuff in there.
So I am also trying to autoload everything possible that is currently "required" by my emacs.el.
I have a module that exposes 12 entry points - interactive functions I can call.
Is the correct approach to have 12 calls to autoload in order to insure that the module is loaded regardless of which function I call? Are there any problems with this approach? Will it present performance issues?
If not that approach, then what?
What you really want is to get the autoloads generated for you automatically, so that your .emacs file remains pristine. Most packages have the ;;;###autoload lines in them already, and if not, you can easily add them.
To manage this, you can put all the packages in a directory, say ~/emacs/lisp, and in there have a file named update-auto-loads.el which contains:
;; put this path into the load-path automatically
;;;###autoload
(progn
(setq load-path (cons (file-name-directory load-file-name) load-path)))
;;;###autoload
(defun update-autoloads-in-package-area (&optional file)
"Update autoloads for files in the diretory containing this file."
(interactive)
(let ((base (file-truename
(file-name-directory
(symbol-file 'update-autoloads-in-package-area 'defun)))))
(require 'autoload) ;ironic, i know
(let ((generated-autoload-file (concat base "loaddefs.el")))
(when (not (file-exists-p generated-autoload-file))
(with-current-buffer (find-file-noselect generated-autoload-file)
(insert ";;") ;; create the file with non-zero size to appease autoload
(save-buffer)))
(cd base)
(if file
(update-file-autoloads file)
(update-autoloads-from-directories base)))))
;;;###autoload
(defun update-autoloads-for-file-in-package-area (file)
(interactive "f")
(update-autoloads-in-package-area file))
If you add 'update-autoloads-in-package-area to your kill-emacs-hook, then the loaddefs.el will automatically be updated every time you exit Emacs.
And, to tie it all together, add this to your .emacs:
(load-file "~/emacs/lisp/loaddefs.el")
Now, when you download a new package, just save it in the ~/emacs/lisp directory, update the loaddefs via M-x update-autoloads-in-package-area (or exit emacs), and it'll be available the next time you run Emacs. No more changes to your .emacs to load things.
See this question for other alternatives to speeding up Emacs startup: How can I make Emacs start-up faster?
Well, who cares how slowly it starts?
Fire it up via emacs --daemon & and then connect using either one of
emacsclient -c /some/file.ext, or
emacsclient -nw
I created aliases for both these as emx and emt, respectively. Continuing once editing session is so much saner...
Ideally you shouldn't have any load or require in your .emacs file.
You should be using autoload instead...
e.g.
(autoload 'slime-selector "slime" t)
You will need to use eval-after-load to do any library specific config, but the upshot is that you won't need to wait for all this to load up front, or cause errors on versions of Emacs that don't have the same functionality. (e.g. Terminal based, or a different platform etc.)
While this may not affect you right now, chances are, in future you will want to use the same config on all machines / environments where you use Emacs, so it's a very good thing to have your config ready to fly.
Also use (start-server) and open external files into Emacs using emacsclient - So you avoid restarting Emacs.
I would like the Org-mode agenda to automatically show what I have to do today when I open Emacs. The org-agenda command is interactive, so it doesn't seem to work well for this purpose.
Is there a way to show the Org-mode agenda on Emacs start-up?
Thanks,
Conor
You can use after-init-hook to run a piece of code after initialization has finished. To run (org-agenda-list) after init, use:
(add-hook 'after-init-hook 'org-agenda-list)
This works for me (in .emacs):
(setq inhibit-splash-screen t)
(org-agenda-list)
(delete-other-windows)
Without the first line, the splash screen "covered" the agenda; without the third one, the scratch buffer remained visible.
One alternative to the hook is to set the initial-buffer-choice variable. This is particularly useful if there are multiple buffers or a number of functions on the hook. The function on this variable needs to return a buffer. Naively this might be:
(setq initial-buffer-choice (lambda ()
(org-agenda-list 1)
(get-buffer "*Org Agenda*")))
Try (org-agenda-list). If you just want today, (org-agenda-list 1).
And of course, apropos is your friend. C-h C-a org-agenda (or whatever command) will show you useful info on that command.
I have a bash alias to start emacs with the Agenda open:
alias org='/usr/bin/emacs --funcall org-agenda-list &'
Enjoy.
It is not exactly at startup, but I keep Emacs running so I need a different approach
(require 'midnight)
(midnight-delay-set 'midnight-delay "7:30am")
(add-hook 'midnight-hook 'org-agenda-list)
Credits to https://stackoverflow.com/a/14947354/217408
I'd like to save the output of org-agenda to a text file, every time that the org-agenda is calculated. This way, I can use an external program (like ATNotes on windows or conky on linux), to pick up this text file and display it on my desktop.
How can I do this?
I feel like I'm raining on your parade after you went to the trouble to write this code snipped (and used a piece of around advice, too!), but actually this feature is already baked into org-mode, and documented in the manual. The command you want is org-write-agenda (C-x C-w in an agenda buffer). See the section of the org-mode info entitled "Exporting Agenda Views."
If you want to do it while you have emacs open, you can just call save-buffer on the *Agenda* buffer via M-x save-buffer (since orgmode binds C-x C-s to org-save-all-org-buffer. You could bind save-buffer to something else in the org-mode-map if you wanted.
If you want to do it via a cron, you should be able to use the snippet in this thread on the org-mode mailing list to pipe the output to a file. I've used this in the past:
emacs -batch -eval '(org-batch-agenda "a" org-agenda-ndays 7 org-agenda-include-diary nil org-agenda-files (quote ("~/org/todo.org")))' > agenda.txt
So I finally decided to open the emacs lisp manual and figure this out myself. I wrote this bit of code, which seems to be working just fine! :)
;; Save the org-agenda for display with conky
(defadvice org-todo-list (after saveorgagenda activate)
"save this output to my todo file"
(get-buffer-create "todo")
(with-current-buffer "todo"
(set-buffer-modified-p nil))
(kill-buffer "todo")
(write-file "~/todo"))
EDIT REASONS:
1) Without kill-buffer, the defadvice creates a new todo buffer on every execution of org-todo-list. This gets pretty irritating.
2) Without the get-buffer-create function, kill-buffers fails the first time since there is no buffer named todo at that time.
3) Without set-buffer-modified-p, the function will keep telling you "todo buffer is modified. Really kill it? (y or n)" which would defeat the whole purpose really.
Whew! I'm so happy I actually took the time and effort to figure this out! :D