.Emacs for Windows 29 Jun 2009

(setq load-path (cons "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/org-6.27a/" load-path))
(add-to-list 'load-path "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/remember/")

(require 'org)
(require 'remember)
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

(global-font-lock-mode 1)                     ; for all buffers
(add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only

(defalias 'list-buffers 'ibuffer)
(defconst cls-tmp-dir    "~/.emacs.tmp")

(setq org-log-done t)
(setq org-directory "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org")
(setq org-default-notes-file "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/notes.org")

(setq remember-annotation-functions '(org-remember-annotation))
(setq remember-handler-functions '(org-remember-handler))
(add-hook 'remember-mode-hook 'org-remember-apply-template)
(define-key global-map "\C-cr" 'org-remember)

(setq org-remember-templates
    '(("Todo" ?t "* TODO %? %T %^g\n %i\n " "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/personal.org" )
     ("Journal" ?j "\n* %^{topic} %T \n%i%?\n" "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/journal.org")
     ("Reference" ?r "\n* %^{topic} %T \n%i%?\n" "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/reference.org")
     ("Notes" ?n "\n* %^{topic} %T \n%i%?\n" "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/notes.org")
     ("Contact" ?c "\n* %^{Name} :CONTACT:\n%[C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/contacts.txt]\n"
              "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/")
     ))

(require 'org-publish)
(setq org-publish-project-alist
      '(
	      ("org-notes"
		 :base-directory "~/org/"
		 :base-extension "org"
		 :publishing-directory "~/public_html/"
		 :recursive t
		 :publishing-function org-publish-org-to-html
		 :headline-levels 4             ; Just the default for this project.
		 :auto-preamble t
	         :auto-index t                  ; Generate index.org automagically...
		 :index-filename "sitemap.org"  ; ... call it sitemap.org ...
		 :index-title "Sitemap"         ; ... with title 'Sitemap'.
		 )
		("org-static"
		 :base-directory "~/org/"
		 :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
		 :publishing-directory "~/public_html/"
		 :recursive t
		 :publishing-function org-publish-attachment
		 )
		("org" :components ("org-notes" "org-static"))
      ))

(setq org-agenda-custom-commands
      '(("p" . "Priorities")
        ("pa" "A items" tags-todo "+PRIORITY=\"A\"")
        ("pb" "B items" tags-todo "+PRIORITY=\"B\"")
        ("pc" "C items" tags-todo "+PRIORITY=\"C\"")
        ;; ...other commands here
        ))

;; To change the location of the annotation file:
(setq org-annotate-file-storage-file "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/annotated.org")
(setq org-annotate-file-add-search t)

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(cua-mode t nil (cua-base))
 '(inhibit-startup-screen t)
 '(org-agenda-files (quote ("C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/personal.org")))
 '(show-paren-mode t)
 '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
 '(transient-mark-mode t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

(defun wc ()
  (interactive)
  (message "Word count: %s" (how-many "\\w+" (point-min) (point-max))))

(defun run-current-file ()
(interactive)
  (let (ext-map file-name file-ext prog-name cmd-str)
; get the file name
; get the program name
; run it
    (setq ext-map
          '(
            ("pl" . "perl")
            ("py" . "python")
            ("sh" . "bash")
            ("rb" . "ruby")
            )
          )
    (setq file-name (buffer-file-name))
    (setq file-ext (file-name-extension file-name))
    (setq prog-name (cdr (assoc file-ext ext-map)))
    (setq cmd-str (concat prog-name " " file-name))
    (shell-command cmd-str)))

(define-key global-map "\C-c9" 'run-current-file)
(global-set-key (kbd "M-S-") ;; open my personal.org file
  (lambda()(interactive)(find-file "C:/Documents and Settings/csnyder/Desktop/My Dropbox/emacs_org/personal.org")))

;; backups
(setq cls-backup-dir (concat cls-tmp-dir "/backups"))
(setq make-backup-files t ;; do make backups
  backup-by-copying t     ;; and copy them here
  backup-directory-alist '(("." . "~/.emacs.tmp/backups")) ;; FIXME
  version-control t
  kept-new-versions 2
  kept-old-versions 5
  delete-old-versions t)

dot emacs file mac 19June2009

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(setq load-path (cons "/Users/clsnyder/emacs_org/org-6.27a/lisp" load-path))
(add-to-list 'load-path "/Users/clsnyder/emacs_org/remember")
 
(require 'org)
(require 'remember)
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
 
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
 
(global-font-lock-mode 1)                     ; for all buffers
(add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only
 
(setq org-log-done t)
(setq org-directory "~/Dropbox/emacs_org")
(setq org-default-notes-file "~/Dropbox/emacs_org/notes.org")
 
(setq remember-annotation-functions '(org-remember-annotation))
(setq remember-handler-functions '(org-remember-handler))
(add-hook 'remember-mode-hook 'org-remember-apply-template)
(define-key global-map "\C-cr" 'org-remember)
 
(setq org-remember-templates
    '(("Todo" ?t "* TODO %? %T %^g\n %i\n " "~/Dropbox/emacs_org/personal.org" )
     ("Journal" ?j "\n* %^{topic} %T \n%i%?\n" "~/Dropbox/emacs_org/journal.org")
     ("Reference" ?r "\n* %^{topic} %T \n%i%?\n" "~/Dropbox/emacs_org/reference.org")
     ("Notes" ?n "\n* %^{topic} %T \n%i%?\n" "~/Dropbox/emacs_org/notes.org")
     ("Contact" ?c "\n* %^{Name} :CONTACT:\n%[~/Dropbox/emacs_org/contacts.txt]\n" 
              "~/Dropbox/emacs_org/contacts.org")
     ))
 
(setq org-agenda-custom-commands
      '(("p" . "Priorities")
        ("pa" "A items" tags-todo "+PRIORITY=\"A\"")
        ("pb" "B items" tags-todo "+PRIORITY=\"B\"")
        ("pc" "C items" tags-todo "+PRIORITY=\"C\"")
        ;; ...other commands here
        ))
 
 
;;
;; To change the location of the annotation file:
;;
(setq org-annotate-file-storage-file "~/Dropbox/emacs_org/annotated.org")
(setq org-annotate-file-add-search t)
 
 
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(cua-mode t nil (cua-base))
 '(org-agenda-files (quote ("~/Dropbox/emacs_org/personal.org")))
 '(show-paren-mode t)
 '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
 '(transient-mark-mode t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )
 
(defun wc ()
  (interactive)
  (message "Word count: %s" (how-many "\\w+" (point-min) (point-max))))
 
 
(defun run-current-file ()
(interactive)
  (let (ext-map file-name file-ext prog-name cmd-str)
; get the file name
; get the program name
; run it
    (setq ext-map
          '(
            ("pl" . "perl")
            ("py" . "python")
            ("sh" . "bash")
            ("rb" . "ruby")
            )
          )
    (setq file-name (buffer-file-name))
    (setq file-ext (file-name-extension file-name))
    (setq prog-name (cdr (assoc file-ext ext-map)))
    (setq cmd-str (concat prog-name " " file-name))
    (shell-command cmd-str)))
 
(define-key global-map "\C-c9" 'run-current-file)
 
; return a backup file path of a give file path
; with full directory mirroring from a root dir
; non-existant dir will be created
(defun my-backup-file-name (fpath)
  "Return a new file path of a given file path.
If the new path's directories does not exist, create them."
  (let (backup-root bpath)
    (setq backup-root "~/Dropbox/emacs_org/emacs-backup")
    (setq bpath (concat backup-root fpath "~"))
    (make-directory (file-name-directory bpath) bpath)
    bpath
  )
)
(setq make-backup-file-name-function 'my-backup-file-name)

Repeating events in org-mode

This is from org mode forum:

I am reading the Org-mode Release 6.27a manual to learn new things.
and just discovered the C-c C-x c (clone subtree) command.

This makes copies of a tree and inserts them as siblings. The command
prompts you for the number of copies to make. The really useful
feature is to update dates according to a pattern.

Here is an example of creating headings for each of the next six months:

Start with this:

** First of the month
*** July
SCHEDULED: <2009-07-01 Wed>

Position the cursor to the beginning of the line *** July
then issue the C-c C-x c

Answer the question “Number of clones to produce:” with 6

Next question is
“Date shift per clone (e.g. +1w, empty to copy unchanged): ”

Answer it +1m and the tree looks like:

*** July
SCHEDULED: <2009-07-01 Wed>
*** July
SCHEDULED: <2009-08-01 Sat>
*** July
SCHEDULED: <2009-09-01 Tue>
*** July
SCHEDULED: <2009-10-01 Thu>
*** July
SCHEDULED: <2009-11-01 Sun>
*** July
SCHEDULED: <2009-12-01 Tue>
*** July
SCHEDULED: <2010-01-01 Fri>

Now you just have to change the occurrences of July to the real
month names!

Emacs: Writing a Macro

To start defining a macro, press F3 or C-x (.[2] The abbreviation Def appears on the mode line, showing that you are in macro definition mode. In this mode, Emacs records all the keystrokes that you type, whether they are commands or literal text, so that you can replay them later. To end the macro, press F4 or C-x ); you leave macro definition mode, and Emacs stops recording your keystrokes. Emacs also stops recording your keystrokes automatically if an error occurs or if you press C-g.

[2] Mac OS X users may have bound F3 and F4, used in defining and executing macros, to another key. These users should press Option-F3 and Option-F4 to get the same functionality.

While you’re defining a macro, Emacs acts on your keystrokes as well as recording them: that is, anything you type while in macro definition mode is treated as a regular command and executed. While you’re defining a macro, you’re doing completely normal editing. That way you can see that the macro does exactly what you want it to, and you can cancel it (with C-g) if you notice that the macro isn’t really quite what you want.

To execute your macro, press F4 or C-x e. Emacs then replays your keystrokes exactly. (You can see that F4 has two different functions relating to macros: to end a macro definition and, after it’s defined, to execute the macro.)

This macro is referred to as the “last” keyboard macro, with last here meaning most recent. Only one macro is the last keyboard macro. A macro ring, much like the kill ring, allows you to access a number of macros during an Emacs session.

Table 6-1 shows the steps required to define and execute a macro. This macro takes a list of names in the ordinary First Name Last Name order and changes it to the frequently needed Last Name, First Name order.

Keystrokes Action
F3 or C-x ( Start the macro; Def appears on the mode line.
C-a Move to the beginning of the current line.
M-f Move forward a word.
, Type a comma.
M-t Transpose first and last.
C-n Move to the next line.
F4 or C-x ) End the macro definition.

Emacs: Interact with User

Q: In emacs, how can one get input from the user after a prompt? (modified from Xah Lee site)
A: “Interactive” turns a function into a command:

1
2
3
4
5
6
(defun irc-join (chan) 
  "join an IRC channel" 
  (interactive "sChannel to join: ") 
  (save-excursion 
    (setq irc-channel chan) 
    (irc-send-server (concat "JOIN " chan))))

Define a function via ‘defun’. ‘irc-join’, is the name
of the function. ‘chan’ is a local variable / parameter. Next is the description.
The string: “sChannel to join: ” –> The first character ‘s’ specifies
a string as the first variable of the parameter
list. The character ‘s’ means “string”. If you
wanted more parameters, it would be something like:

1
2
3
(defun function-name (stringparam numberparam) 
  (interactive "sPrompt here: \nnAnother prompt: ") 
        etc...

Note that each prompt string is separated by a newline character “\n”.
Also, ‘n’ means you want to get a number from the user.

Emacs: Color themes

To put in color themes:
1. Download the themes, and put them in a folder (A windows example would be):
“c:/Program File/Emacs/emacs/lisp/your_color_folder/”

2. Emacs must of course be able to find the files. You can check the “load path” (= where it looks) by:

The directories that Emacs searches through when an elisp file is to be loaded are stored in the load-path variable. This shows you the current load-path:

C-h v load-path RET.

3. You must modify the .emacs file as follows:

1
2
3
4
(add-to-list 'load-path "c:/Program File/Emacs/emacs/lisp/your_color_folder/") 
(require 'color-theme)
(color-theme-initialize)
(color-theme-matrix)

That’s it!!