I've set up a cron job to email myself my agenda every morning; it just runs
emacs -batch -eval '(org-batch-agenda "a")'
I'd like to set up a custom agenda to exclude all habits (i.e. those with STYLE: habit), but I couldn't figure out how to do this.
Try piping to AWK and remove all lines with 'HABIT' before you email it.
<emacs command> | awk '!/HABIT/' | <email>
The following works: use a custom init.el file, and add:
(require 'org-habit)
(custom-set-variables
'(org-habit-show-habits nil))
Related
Assume that I have in a certain directory several org-mode files: foo1.org, foo2.org, etc. I would like to have a script (maybe a makefile) that I could invoke something like
$ generate-pdfs
and foo1.pdf, foo2.pdf, etc. will be generated.
I thought that something like emacs --batch --eval <MAGIC> is a good start, but I don't know the magic.
A solution that is solely inside emacs could be of interest as well.
As you said, Emacs has the --batch option to perform operations with Emacs from the shell. In addition to that, you can use the -l flag to load Emacs Lisp code from a file and execute it, and the -f flag to execute a single Lisp function.
Here is a basic example, which exports a single org-mode file to HTML:
emacs myorgfile.org --batch -f org-html-export-to-html --kill
Perhaps you want something more advanced like exporting/publishing a full org-mode project. I do not have sample code for that, but it should not be too complicated.
I also have a sample Makefile I wrote some time ago to export all org-mode files in the directory to HTML (and also copy the HTML files to another directory):
OUT_DIR=/some/output/dir/html
# Using GNU Make-specific functions here
FILES=$(patsubst %.org,$(OUT_DIR)/%.html,$(wildcard *.org))
.PHONY: all clean install-doc
all: install-doc
install-doc: $(OUT_DIR) $(FILES)
$(OUT_DIR):
mkdir -v -p $(OUT_DIR)
%.html: %.org
emacs $< --batch -f org-html-export-to-html--kill
$(OUT_DIR)/%.html: %.html
install -v -m 644 -t $(OUT_DIR) $<
rm $<
clean:
rm *.html
EDIT:
With Org-mode 8 and the new export engine the function for HTML export has changed.
To make the previous examples work with Org 7 or older, replace org-html-export-to-html with org-export-as-html.
I expect to publish (by the end of this week-end) OrgMk, a suite of Makefile and standalone Bash scripts (usable as well under Cygwin) just to do that! Even more: generation of HTML, Ascii, Beamer, etc.
You'll find it on my GitHub account: https://github.com/fniessen/ (where I already have Emacs configuration files, color themes and other stuff such as an Org Babel refcard -- in progress).
Mark a few org files in dired and call this:
(defun dired-org-to-pdf ()
(interactive)
(mapc
(lambda (f)
(with-current-buffer
(find-file-noselect f)
(org-latex-export-to-pdf)))
(dired-get-marked-files)))
If you know what async is, wrap the call as it can take a while.
update:
Here's a version that combines the awesome dired approach with the lame
other one:)
(defun dired-org-to-pdf ()
(interactive)
(let ((files
(if (eq major-mode 'dired-mode)
(dired-get-marked-files)
(let ((default-directory (read-directory-name "dir: ")))
(mapcar #'expand-file-name
(file-expand-wildcards "*.org"))))))
(mapc
(lambda (f)
(with-current-buffer
(find-file-noselect f)
(org-latex-export-to-pdf)))
files)))
How can I have emacs start and be in the middle of a command input? Particularly, I want emacs to start in the middle of a command input find-file with a message in the small buffer saying:
Find file: ~/
and the cursor at the last character of it so that I can continue typing the remaining path to open the file I want.
You can execute one of the following commands on the command prompt or make a shell script containing it appropriately:
$ emacs -f find-file # if you want to start Emacs in the current direcoty
$ (cd ~; emacs -f find-file) # if you want to start Emacs in your home diretory
From the emacs(1) man page:
-f function, --funcall function
Excute the lisp function function
I have to admit that my lisp is a bit rusty, but this works for me. Drop it in your ~/.emacs file (or whatever init file you are using):
(add-hook 'emacs-startup-hook
(lambda ()
(if (= (length command-line-args) 1)
(call-interactively 'find-file))))
If you call emacs with no arguments, like this:
sawa#localhost:~$ emacs
It will invoke find-file for you. If, on the other hand, you invoke emacs with an argument, such as a filename, like this:
sawa#localhost:~$ emacs somefile.txt
It will default to just visiting somefile.txt
I try to do a grep on the result of emacs' find-grep, so I use the following command:
find ... | xargs ... | grep -v "include"
The result does show up i the grep buffer, but when I press enter on each entry trying to go to that file, emacs says that file does not exist. On the minibuffer, before the full path of the file, there is a ^[[K character. That basically make the the whole file name unrecognizable. I looked through grep's manual, still no sure what I can do about it.
I probably don't have to do this, but I'm just not sure how to pass two pattern, one is for grep and the other one is to inverse grep. (May be regular expression?)
Anyone has any suggestions on this?
Solution:
I was doing this on a Cento 5.5 machine. It turns out to be a issue due to the old version of grep. I installed a latest version of grep in my home directory, and everything's good now.
After "debugging" the issue through the comments, this is a solution that should work for you. Add it to your .emacs and customize it so that the regexp matches the special characters you want to strip from the filename: ^[[K
(defadvice compilation-find-file (before compilation-find-file-strip-odd-chars activate)
"Strip the ^[[K in the input string"
(let ((filename (ad-get-arg 1)))
(save-match-data
(when (string-match "^\\[\\[K" filename)
(ad-set-arg 1 (replace-match "" nil nil filename))))))
I had the same problem, but couldn't change my version of grep,
so I used a workaround. The problem seemed to be greps line endings
so I simply run the results of grep through awk
and print them as is.
... | grep -v blaa | awk '{print $0}'
This fixes the problem for me, though I don't know why.
I relise that I have to add something like:
shell
: to my .emacs file. But then how can I get it to do shell commands like:
cd /mydirectory
: and other shell actions
This is a function which does what you want. You can add it (customizing the actions), or just add the body:
(defun shell-and-stuff ()
"run a shell, then do some extra stuff"
(interactive)
(let ((shell-buf (get-buffer-create "*shell*")))
(shell shell-buf)
(comint-send-string
(get-buffer-process shell-buf)
"cd some-directory
ls
touch frog
")))
(shell-and-stuff)
The cd part is easy, just let bind the variable default-directory. See this question for some possible solutions.
Trey Jackson's idea looks good. Also note that the manual (info "(emacs) Interactive Shell") says
Emacs sends the new shell the contents of the file
~/.emacs_SHELLNAME as input, if it exists, where SHELLNAME is the
name of the file that the shell was loaded from. For example, if you
use bash, the file sent to it is ~/.emacs_bash. If this file is not
found, Emacs tries to fallback on ~/.emacs.d/init_SHELLNAME.sh.
So you could put your commands in that file.
The symptom of the problem looks like "[0m[27m[24m[J[34;1" which on a terminal translates into the color blue.
-A
I've got the following in my .emacs
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
The solution that is currently giving me some success is to redefine the shell function as an ansi term:
;; shell-mode
(defun sh ()
(interactive)
(ansi-term "/bin/zsh"))
For the "ignore" alternative, put something like "alias ls=ls" or "unset LS_COLORS" in your ~/.emacs_{bash,tsch,whatever-your-shell-is-called} file. This file is executed in all subordinate shells created by emacs.
Emacs sends the new shell the contents of the file ~/.emacs_shellname as input, if it exists, where shellname is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ~/.emacs_bash. If this file is not found, Emacs tries to fallback on ~/.emacs.d/init_shellname.sh.
The following should work in your .bash_profile or .bashrc
case $TERM in
xterm-color)
export PS1='\[\e]0;\W\007\]\[\e[34;1m\]\W\[\e[0m\]\$ '
;;
*)
export PS1='\W\$ '
;;
esac