]> err.no Git - dotfiles/blob - emacs
loosen font specs a bit
[dotfiles] / emacs
1 ; -*- emacs-lisp -*-
2 ;
3
4 (message "checking for local setup and loading..")
5 (if (file-exists-p "/local/skel/all.emacs")
6     (load "/local/skel/all.emacs" nil t t))
7
8 (message "loading .emacs-standard")
9 (load "~/.emacs-standard")
10
11 (setq vc-follow-symlinks t
12       custom-file (expand-file-name "~/.emacs-custom"))
13
14 (cw/requiring-forms nil
15   (message "checking for local setup and loading..")
16   (if (file-exists-p "/local/skel/all.emacs")
17       (load "/local/skel/all.emacs" nil t t))
18   (if (file-exists-p custom-file)
19       (load custom-file nil t t)))
20
21 (setq tfheen-color-preference 'dark) ; light or dark
22 (require 'jka-compr)
23 (auto-compression-mode t)
24
25 (cw/for-emacs
26  (if (string-match "[Uu][Tt][Ff]-?8" (or (getenv "LC_ALL")
27                                          (getenv "LANG")
28                                          (format ""))) 
29      (progn
30        (set-language-environment "UTF-8") ; UTF-8 mode
31        (if (not window-system)
32            (progn
33              (set-keyboard-coding-system 'utf-8)
34              (set-terminal-coding-system 'utf-8))))
35    (set-language-environment "Latin-1")))
36
37 ;(prefer-coding-system "utf-8")
38
39 (add-to-list 'Info-default-directory-list (expand-file-name "~/usr/info"))
40
41 (add-to-list 'load-path (expand-file-name "~/data/emacs/lisp"))
42 (add-to-list 'load-path (expand-file-name "~/svn/elisp"))
43
44 (cw/requiring-package (eweouz)
45   (add-hook 'gnus-startup-hook 'eweouz-insinuate-gnus)
46   (add-hook 'mail-setup-hook 'eweouz-insinuate-sendmail)
47   (add-hook 'message-setup-hook 'eweouz-insinuate-message))
48
49 ;;;(cw/requiring-package (bbdb)
50 ;;;   (cw/not-for-host ".*ntnu.no"
51 ;;;                    (bbdb-initialize 'gnus 'message 'w3))
52 ;;;   (setq bbdb-use-pop-up nil
53 ;;;         bbdb-quiet-about-name-mismatches t
54 ;;;         bbdb-default-area-code nil
55 ;;;         bbdb-north-american-phone-numbers-p nil
56 ;;;         bbdb-user-mail-names "\(tollef|tfheen\)"
57 ;;;         bbdb-offer-save 1
58 ;;;         bbdb-use-pop-up nil
59 ;;;         mail-setup-hook 'bbdb-insinuate-sendmail
60 ;;;     bbdb-dwim-net-address-allow-redundancy t
61 ;;;     bbdb-complete-name-allow-cycling t)
62 ;;;   (add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
63 ;;;   (add-hook mail-setup-hook 'bbdb-define-all-aliases))
64
65 (setq default-major-mode 'text-mode
66       mail-user-agent 'gnus-user-agent
67       read-mail-command 'gnus)
68
69 (add-hook 'text-mode-hook 'turn-on-auto-fill)
70 (add-hook 'debian-changelog-mode-hook 'turn-on-auto-fill)
71
72 (fset 'yes-or-no-p 'y-or-n-p)
73
74 (cw/requiring-package (mailcrypt)
75   (cw/not-for-host ".*ntnu.no"
76                    (mc-setversion "gpg") )
77   (autoload 'mc-install-write-mode "mailcrypt" nil t)
78   (autoload 'mc-install-read-mode "mailcrypt" nil t)
79   (add-hook 'mail-mode-hook 'mc-install-write-mode)
80   (add-hook 'mail-setup-hook 'mc-install-write-mode)
81   (add-hook 'gnus-summary-mode-hook 'mc-install-read-mode)
82   (add-hook 'news-reply-mode-hook 'mc-install-write-mode)
83   (setq mc-temp-directory (expand-file-name "~/tmp")
84         mc-encrypt-for-me t
85         mc-gpg-user-id "tfheen@opera.no"
86         mc-passwd-timeout 600))
87
88 (global-set-key "\M-n" 'browse-url-at-point)
89 ;(global-set-key (kbd "C-x C-c")
90 ;#'(lambda () (interactive)
91 ;    (if (and window-system (string-match "yiwaz\\|thosu" system-name))
92 ;        (message "you must be kidding")
93 ;      (save-buffers-kill-emacs))))
94
95 (global-set-key [(control backspace)] 'undo)
96 (global-set-key [(control return)] 'find-tag)
97
98 (cw/requiring-package (w3-auto))
99
100 (setq browse-url-browser-function 'browse-url-generic
101       browse-url-new-window-p t
102       browse-url-mozilla-program (or (executable-find "firefox-3.0") "firefox")
103       browse-url-generic-program "chromium")
104
105 ;; File modes
106
107 (autoload 'php-mode "php-mode" "PHP editing mode" t)
108 (autoload 'css-mode "css-mode")
109 (autoload 'pov-mode "pov-mode" "PoVray scene file mode" t)
110 (autoload 'jde-mode "jde" "Java Development Environment" t)
111 (autoload 'dtml-mode "dtml-mode" "Document Template Markup Language" t)
112 (autoload 'vcl-mode "vcl-mode")
113
114 (add-to-list 'auto-mode-alist '("\\.php3$" . php-mode))
115 (add-to-list 'auto-mode-alist '("\\.css$" . css-mode))
116 (add-to-list 'auto-mode-alist '("\\.pov$" . pov-mode))
117 (add-to-list 'auto-mode-alist '("\\.jl$" . lisp-mode))
118 (add-to-list 'auto-mode-alist '("\\.java$" . jde-mode))
119 (add-to-list 'auto-mode-alist '("\\.vcl$" . vcl-mode))
120
121 ;; Set up autoloading and auto-mode
122 (autoload 'ps-mode "ps-mode"
123   "Major mode for editing PostScript" t)
124 (setq auto-mode-alist
125       (append
126        '(("\\.[eE]?[pP][sS]$" . ps-mode))
127        auto-mode-alist))
128
129 ;; Various programming settings and languages
130 ; K&R
131 (setq perl-indent-level 8
132       perl-continued-statement-offset 8
133       perl-continued-brace-offset 0
134       perl-brace-offset -8
135       perl-brace-imaginary-offset 0
136       perl-label-offset -8)
137
138 (setq next-line-add-newlines nil
139       compilation-window-height 10
140       european-calendar-style t
141       diff-switches "-u")
142
143 (defun reverse-list-in-list (reverse-list)
144   (require 'cl)
145   (let '(bar (copy-list reverse-list))
146     (setq liste (list))
147        (while (car bar)
148          (let '(elem (car bar))
149            (add-to-list 'liste (reverse elem)))
150          (setq bar (cdr bar)))
151        (reverse liste)))
152
153 (setq py-honor-comment-indentation nil)
154
155 (add-hook 'sgml-mode-hook '(lambda()(local-set-key "\C-c>" 'sgml-insert-end-tag)))
156 ;(add-hook 'emacs-lisp-mode-hook '(lambda()(local-set-key "\C-j" 'find-function)))
157 ;(require 'template)
158 ;(add-hook 'c-mode-common-hook 'tmpl-init)
159 ;(add-hook 'c-mode-common-hook 'auto-insert-file-header)
160 (add-hook 'c-mode-common-hook (lambda() (local-set-key "\M-\C-x" 'compile)))
161 (add-hook 'c-mode-common-hook (lambda() (local-set-key "\M-\C-z" 'next-error)))
162
163 (cw/requiring-package (auto-header))
164
165 (setq header-full-name "Tollef Fog Heen"
166       header-email-address "tollef@err.no"
167       add-log-mailing-address "tfheen@err.no"
168       debian-changelog-mailing-address "tfheen@debian.org"
169       tags-table-list '("~/varnish" "~/usr/include/"))
170
171 (setq sgml-local-catalogs (list "~/usr/lib/sgml/sgml.catalog"))
172
173 ;; Find-file hooks
174 ; Stolen from Jan Ingvoldstad
175 (add-hook 'find-file-hooks
176           '(lambda ()
177           ;; Invoke proper modes when we don't know file extensions
178           (cond ((looking-at "#!.*/perl") (perl-mode))
179                 ((looking-at "#!.*/tclsh") (tcl-mode))
180                 ((looking-at "#!.*/wish") (tcl-mode))
181                 ((looking-at "#!.*/make") (makefile-mode)))))
182
183 ;; Visual fluff.
184
185 (cw/for-emacs
186  (if (functionp 'toggle-scroll-bar)
187      (progn
188        (toggle-scroll-bar -1)
189        (setq scrollbars-visible-p nil))))
190
191 (setq scroll-bar-mode nil)
192 ; (set-default-font "fixed")
193
194 ;      show-paren-style 'expression)
195
196 ; Highlight matching/nonmatching parens
197 ;(if (not xemacsp)
198 ;    (show-paren-mode t)) ; show-paren-mode takes too much cpu
199 (cw/for-emacs
200  (global-font-lock-mode t)
201  (font-lock-mode 1))
202
203 ;; Multiple mode
204
205 (cw/requiring-package
206  (mmm-auto)
207  (setq mmm-global-mode 'maybe)
208  (set-face-background 'mmm-default-submode-face "White"))
209
210 (cw/requiring-package
211     (font-lock)
212   (cw/requiring-package
213       (poe)
214     (set-face-foreground (find-face font-lock-string-face) "Blue")))
215
216 (cw/requiring-package (tramp)
217   (setq tramp-auto-save-directory "/home/tfheen/tmp"
218         tramp-default-method "rsync"))
219
220 ;;         (setq tramp-multi-file-name-structure (quote ("\\`/r:\\(\\([a-z0-9]+\\)\\)?\\(\\(%s\\)+\\):\\(.*\\)\\'" 2 3 -1))
221 ;;                             tramp-make-tramp-file-format "/r:%m/%u@%h:%p"
222 ;;                             tramp-file-name-regexp "\\`/r:"
223 ;;                             tramp-make-multi-tramp-file-format (quote ("/r:%m" "/%m:%u@%h" ":%p"))
224 ;;                             tramp-make-tramp-file-user-nil-format "/r:%m/%h:%p"
225 ;;                             tramp-file-name-structure '("\\`/r:\\(\\([a-zA-Z0-9]+\\)/\\)?\\(\\([-a-zA-Z0-9_#/:]+\\)@\\)?\\([-a-zA-Z0-9_#/:@.]+\\):\\(.*\\)\\'" 2 4 5 6)))
226
227
228 (cw/for-emacs-21-and-later
229  (blink-cursor-mode 0)
230  (if window-system
231      (tooltip-mode 0))
232  (if window-system
233      (tool-bar-mode 0))
234  (global-set-key [home] 'beginning-of-buffer)
235  (global-set-key [end] 'end-of-buffer)
236  (menu-bar-mode 0)
237  (setq cursor-in-non-selected-windows nil))
238
239 (defun tfheen-complete (&optional x)
240   (interactive)
241   (if (eq major-mode 'jde-mode)
242       (jde-complete-at-point)
243     (hippie-expand x)))
244
245 (global-set-key [C-tab] 'dabbrev-expand)
246 (global-set-key "\M- " 'tfheen-complete)
247
248
249 ;(add-hook 'diary-hook 'appt-make-list)
250 ;(add-hook 'diary-hook 'appt-make-list)
251 ;(diary 0)
252
253 ; Mode line
254 (display-time)
255
256 (cw/for-emacs-22-and-later
257  (setq inhibit-splash-screen t)
258  (setq inhibit-startup-echo-area-message "tfheen")
259 )
260
261 (cw/for-emacs-23-and-later
262  (setq line-move-visual nil))
263
264 ;(cw/for-emacs-21
265 ; (display-battery))
266 ;(cw/for-emacs-22
267 ; (display-battery-mode))
268 (setq display-time-format "%H:%M"
269       display-time-string-forms '(24-hours ":" minutes))
270
271 (setq show-trailing-whitespace t)
272 ;(setq-default indent-tabs-mode nil)
273 (cw/for-emacs-21-and-later
274  (define-coding-system-alias 'iso885915 'iso-8859-15)
275  (define-coding-system-alias 'utf8 'utf-8)
276  (define-coding-system-alias 'iso-8859-15 'iso-8859-1))
277
278 (setq add-log-full-name "Tollef Fog Heen"
279       add-log-time-format 'tfheen-dpkg-changelog-time)
280
281 (defun tfheen-dpkg-changelog-time ()
282   (let* ((time (decode-time))
283         (sec (first time))
284         (minute (second time))
285         (hour (third time))
286         (day (fourth time))
287         (month (fifth time))
288         (year (sixth time))
289         (dow (seventh time))
290         (dst (eighth time))
291         (zone (second (current-time-zone)))
292         (daynames '("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"))
293         (monthnames '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
294         (dayname nil)
295         (monthname nil))
296     (setq dayname (nth (- dow 1) daynames)
297           monthname (nth (- month 1) monthnames))
298     (format "%s %s %d %2d:%2d:%2d %s %d" dayname monthname day hour minute sec zone year)))
299
300 (add-to-list 'load-path (expand-file-name "~/external/slime"))
301 (cw/requiring-package (slime)
302     (add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
303     (add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
304     (setq inferior-lisp-program "sbcl-mt"))
305
306 (setq mouse-yank-at-point t)
307
308 ;: WL setup
309
310 (setq elmo-imap4-default-stream-type 'ssl
311       elmo-imap4-default-server "mail.raw.no"
312       elmo-imap4-default-port 993)
313 ;      wl-folder-access-subscribe-alist '(("^%" . (t . "."))))
314 (setq elmo-imap4-default-authenticate-type 'clear
315       elmo-default-authenticate-type 'clear)
316
317 (put 'downcase-region 'disabled nil)
318
319 (defun linux-c-mode ()
320   "C mode with adjusted defaults for use with the Linux kernel."
321   (interactive)
322   (c-mode)
323   (c-set-style "K&R")
324   (setq tab-width 8)
325   (setq indent-tabs-mode t)
326   (setq c-basic-offset 8))
327
328 (autoload 'javascript-mode "javascript-mode" "JavaScript mode" t)
329 (setq auto-mode-alist (append '(("\\.js$" . javascript-mode))
330                               auto-mode-alist))
331
332 (cw/for-emacs-22-and-later
333  (setq org-remember-templates
334        '((?t "* TODO %?\n  %i\n  %a" "~/svn/plans/todo.org")
335          (?a "* Appointment: %?\n%^T\n%i\n  %a" "~/svn/plans/todo.org")))
336  (setq remember-annotation-functions '(org-remember-annotation)
337        remember-handler-functions '(org-remember-handler)
338        org-return-follows-link t
339        org-todo-keywords '("TODO" "STARTED" "WAITING" "DONE")
340        org-agenda-include-diary t
341        org-agenda-include-all-todo t
342        org-tags-column (* -1 (- (frame-width) 10))
343        org-agenda-align-tags-to-column (- (frame-width) 10)
344        org-hide-leading-stars nil
345        org-agenda-files '("~/svn/plans/todo.org")
346        org-stuck-projects '("+LEVEL=2-neverstuck/-DONE" ("TODO" "NEXT" "NEXTACTION" "") ("APPOINTMENT") "")
347        org-clock-out-when-done nil
348        org-clock-persist t
349        org-clock-into-drawer t)
350  (org-clock-persistence-insinuate))
351
352
353  (eval-after-load 'remember
354    '(add-hook 'remember-mode-hook 'org-remember-apply-template))
355  (global-set-key (kbd "C-c r") 'remember)
356
357  (require 'org)
358  (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
359  (global-set-key (kbd "C-c a") 'org-agenda)
360  (setq org-agenda-custom-commands
361        '(("w" todo
362           #("WAITING" 0 7
363             (face org-warning)))
364          ("h" tags-todo "@hjemme")
365          ("j" tags-todo "@jobb")))
366
367 (add-to-list 'window-size-change-functions
368              (lambda (frame) (setq org-tags-column (* -1 (- (frame-width) 10))
369                                    org-agenda-align-tags-to-column (- (frame-width) 10))))
370
371 (cw/for-host "qurzaw\\|thosu"
372   (setq gnus-home-directory "~/.emacs.d/gnus"
373         gnus-init-file "~/.gnus"
374         message-directory (concat gnus-home-directory "/Mail")))
375
376
377 (cw/for-emacs-23-and-later
378  (setq tfheen-base-size 8)
379
380  (setq tfheen-base-font "DejaVu Sans Mono"
381        tfheen-current-size tfheen-base-size)
382  ;; Firefox-like zooming of fonts.
383  
384  (defun font-zoom-increase-font-size ()
385    (interactive)
386    (setq tfheen-current-size (+ tfheen-current-size 2))
387    (let ((font-name (format "%s-%d" tfheen-base-font tfheen-current-size)))
388      (set-frame-font font-name)))
389  
390  (defun font-zoom-decrease-font-size ()
391    (interactive)
392    (setq tfheen-current-size (- tfheen-current-size 2))
393    (let ((font-name (format "%s-%d" tfheen-base-font tfheen-current-size)))
394      (set-frame-font font-name)))
395  
396  (defun font-zoom-reset-font-size ()
397    (interactive)
398    (let ((font-name (format "%s-%d" tfheen-base-font tfheen-base-size)))
399      (set-frame-font font-name)))
400  
401  (define-key global-map (read-kbd-macro "C--") 'font-zoom-decrease-font-size)
402  (define-key global-map (read-kbd-macro "C-+") 'font-zoom-increase-font-size)
403  (define-key global-map (read-kbd-macro "C-=") 'font-zoom-reset-font-size)
404  (font-zoom-reset-font-size))
405
406 (defun minutes-to-hours (minutes)
407   (/ (* 1.0 minutes) 60))
408
409 (defun weekend-p (time)
410   (> (string-to-number (format-time-string "%u" time)) 5))
411
412 (defun org-dblock-write:timebalance (params)
413   "Display day-by-day summary, giving a balance"
414   (let* ((ts (plist-get params :tstart))
415          (te (plist-get params :tend))
416          (ins (make-marker))
417          (start (time-to-seconds
418                  (apply 'encode-time (org-parse-time-string ts))))
419          (end (time-to-seconds
420                (apply 'encode-time (org-parse-time-string te))))
421          tbl sum)
422
423     (setq params (plist-put params :tstart nil))
424     (setq params (plist-put params :end nil))
425     (move-marker ins (point))
426     (while (<= start end)
427       (save-excursion
428         (let ((sum 0))
429           (org-clock-sum start (+ start 86400))
430           (goto-char (point-min))
431           (setq st t)
432           (while (or (and (bobp) (prog1 st (setq st nil))
433                           (get-text-property (point) :org-clock-minutes)
434                           (setq p (point-min)))
435                      (setq p (next-single-property-change (point) :org-clock-minutes)))
436             (goto-char p)
437             (message (format "pre: %s %d %d %s" (format-time-string "%Y-%m-%d" (seconds-to-time start)) sum start (point)))
438             (if (= 1 (car (org-heading-components)))
439                 (setq sum (+ sum (or (get-text-property p :org-clock-minutes) 0)))))
440           (push (list start sum) tbl)))
441       (setq start (+ 86400 start)))
442     (setq tbl (nreverse tbl))
443     (goto-char ins)
444     (setq sum 0)
445     (while tbl
446       (let* ((line (car tbl))
447              (ts (seconds-to-time (first line)))
448              (minutes (second line))
449              (hours (minutes-to-hours minutes)))
450         (setq sum (+ sum hours))
451         (if (not (weekend-p ts))
452             (setq sum (- sum 7.5)))
453         (if (> minutes 0)
454             (insert-before-markers
455              (format-time-string "%Y-%m-%d" ts)
456              (format " %f %f\n" hours sum))))
457         (setq tbl (cdr tbl)))))
458
459 (defun org-dblock-write:invoicerounding (params)
460   "Grab hours in a format suitable for an invoice, rounding all times to a full hour"
461   (let* ((ts (plist-get params :tstart))
462          (te (plist-get params :tend))
463          (ins (make-marker))
464          (start (time-to-seconds
465                  (apply 'encode-time (org-parse-time-string ts))))
466          (end (time-to-seconds
467                (apply 'encode-time (org-parse-time-string te))))
468          tbl sum)
469
470     (setq params (plist-put params :tstart nil))
471     (setq params (plist-put params :end nil))
472     (move-marker ins (point))
473     (while (<= start end)
474       (save-excursion
475         (let ((sum 0))
476           (org-clock-sum start (+ start 86400))
477           (goto-char (point-min))
478           (setq st t)
479           (while (or (and (bobp) (prog1 st (setq st nil))
480                           (get-text-property (point) :org-clock-minutes)
481                           (setq p (point-min)))
482                      (setq p (next-single-property-change (point) :org-clock-minutes)))
483             (goto-char p)
484             (message (format "pre: %s %d %d %s" (format-time-string "%Y-%m-%d" (seconds-to-time start)) sum start (point)))
485             (if (= 1 (car (org-heading-components)))
486                 (setq sum (+ sum (or (get-text-property p :org-clock-minutes) 0)))))
487           (push (list start sum) tbl)))
488       (setq start (+ 86400 start)))
489     (setq tbl (nreverse tbl))
490     (goto-char ins)
491     (setq sum 0)
492     (while tbl
493       (let* ((line (car tbl))
494              (ts (seconds-to-time (first line)))
495              (minutes (second line))
496              (hours (minutes-to-hours minutes)))
497         (setq sum (+ sum hours))
498         (if (not (weekend-p ts))
499             (setq sum (- sum 7.5)))
500         (if (> minutes 0)
501             (insert-before-markers
502              (format-time-string "%Y-%m-%d" ts)
503              (format " %f %f\n" hours sum))))
504         (setq tbl (cdr tbl)))))
505
506 (defun org-dblock-write:gtimelog (params)
507   "Display day-by-day time reports in gtimelog format."
508   (let* ((ts (plist-get params :tstart))
509          (te (plist-get params :tend))
510          (ins (make-marker))
511          (maxlevel (plist-get params :maxlevel))
512          (start (time-to-seconds
513                  (apply 'encode-time (org-parse-time-string ts))))
514          (end (time-to-seconds
515                (apply 'encode-time (org-parse-time-string te))))
516          tbl day-numbers heading1-label)
517
518     (setq params (plist-put params :tstart nil))
519     (setq params (plist-put params :end nil))
520     (move-marker ins (point))
521     (while (<= start end)
522       (save-excursion
523         (org-clock-sum start (+ start 86400))
524         (goto-char (point-min))
525         (setq st t)
526         (while (or (and (bobp) (prog1 st (setq st nil))
527                         (get-text-property (point) :org-clock-minutes)
528                         (setq p (point-min)))
529                    (setq p (next-single-property-change (point) :org-clock-minutes)))
530           (goto-char p)
531           (when (setq time (get-text-property p :org-clock-minutes))
532             (save-excursion
533               (beginning-of-line 1)
534               (when (and (looking-at (org-re "^\\(\\*+\\)[ \t]+\\(.*?\\)\\([ \t]+:[[:alnum:]_@:]+:\\)?[ \t]*$"))
535                          (setq level (org-reduced-level
536                                       (- (match-end 1) (match-beginning 1))))
537                          (<= level maxlevel))
538                 (if (= level 1)
539                     (setq heading1-label (match-string 2))
540                   (push (list
541                        start
542                        (concat heading1-label ": " (match-string 2))
543                        time) tbl)))))))
544       (setq start (+ 86400 start)))
545     (setq tbl (nreverse tbl))
546     (goto-char ins)
547     (setq ts 0)
548     (while tbl
549       (let ((line (car tbl)))
550         (if (< ts (car line))
551             ; New day
552             (progn
553               (insert-before-markers
554                (format-time-string "%Y-%m-%d %H:%M %z"
555                                    (seconds-to-time (first line)))
556                ": Arrive\n")
557               (setq ts (first line))))
558
559         (insert-before-markers
560          (format-time-string "%Y-%m-%d %H:%M %z"
561                              (seconds-to-time (+ ts (* 60 (third line)))))
562          ": "
563          (format "%s" (second line))
564          "\n")
565         (setq ts (+ ts (* 60 (third line))))
566         (setq tbl (cdr tbl))))))
567
568
569 ;(defadvice current-time (after tfheen-floor-current-time activate disable)
570 ;  (setq ad-return-value (seconds-to-time (* 900 (floor (time-to-seconds ad-return-value) 900)))))
571 ;(defadvice org-clock-in (around tfheen-round-clock activate)
572 ;  (ad-enable-advice 'current-time 'after 'tfheen-floor-current-time)
573 ;  (ad-activate 'current-time)
574 ;  ad-do-it
575 ;  (ad-disable-advice 'current-time 'after 'tfheen-floor-current-time)
576 ;  (ad-activate 'current-time))
577
578 ;(defadvice current-time (after tfheen-ceiling-current-time activate disable)
579 ;  (setq ad-return-value (seconds-to-time (* 900 (ceiling (time-to-seconds ad-return-value) 900)))))
580 ;(defadvice org-clock-out (around tfheen-round-clock activate)
581 ;  (ad-enable-advice 'current-time 'after 'tfheen-ceiling-current-time)
582 ;  (ad-activate 'current-time)
583 ;  ad-do-it
584 ;  (ad-disable-advice 'current-time 'after 'tfheen-ceiling-current-time)
585 ;  (ad-activate 'current-time))
586
587 (autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t)
588 (add-to-list 'auto-mode-alist '("\\.vala$" . vala-mode))
589 (add-to-list 'auto-mode-alist '("\\.vapi$" . vala-mode))
590 (add-to-list 'file-coding-system-alist '("\\.vala$" . utf-8))
591 (add-to-list 'file-coding-system-alist '("\\.vapi$" . utf-8))
592
593 (cw/for-host "qurzaw"
594   (require 'twittering-mode))
595
596 (defun unfill-paragraph ()
597   (interactive)
598   (let ((fill-column (point-max)))
599     (fill-paragraph nil)))
600
601 (defun unfill-region ()
602   (interactive)
603   (let ((fill-column (point-max)))
604     (fill-region (region-beginning) (region-end) nil)))
605
606 (define-key global-map "\M-Q" 'unfill-paragraph)
607 (define-key global-map "\C-\M-q" 'unfill-region)
608
609 (setq twittering-use-native-retweet t
610       twittering-use-icon-storage t
611       twittering-icon-mode t)
612
613 (setq tfheen-twittering-filter-blacklist
614       '((text . "#oslo #planking")
615         (text . "#WEBELIEBE")
616        (user-screen-name . "\\(Oslo_HitHot\\|Map_Game\\|anbud1\\)")))
617
618 (defun tfheen-twitter-filter-search ()
619   (interactive)
620   (let ((non-matching-statuses ()))
621     (dolist (status twittering-new-tweets-statuses)
622       (if (eq (cadr (assoc 'source-spec status)) 'search)
623           (let ((matched-tweets 0))
624             (dolist (item tfheen-twittering-filter-blacklist)
625               (let* ((type (car item))
626                      (pat (cdr item)))
627                 (if (string-match pat (cdr (assoc type status)))
628                     (setq matched-tweets (+ 1 matched-tweets)))))
629             (if (= 0 matched-tweets)
630                 (setq non-matching-statuses (append non-matching-statuses `(,status)))))
631         (setq non-matching-statuses (append non-matching-statuses `(,status)))))
632     (setq new-statuses non-matching-statuses)))
633
634 (add-hook 'twittering-new-tweets-hook 'tfheen-twitter-filter-search)
635
636 (setq twittering-initial-timeline-spec-string
637       '(":home"
638         ":replies"
639         ":direct_messages"
640         ":search/#oslo/"
641         ":search/#varnish/"))
642
643 (define-key org-mode-map [home] 'beginning-of-buffer)
644 (define-key org-mode-map [end]  'end-of-buffer)
645
646 (defun tfheen/weekday-p ()
647   (let ((wday (nth 6 (decode-time))))
648     (and (< wday 6)
649          (> wday 0))))
650
651 (defun tfheen/working-p ()
652   (let ((hour (nth 2 (decode-time))))
653     (and (tfheen/weekday-p)
654          (and (>= hour 7) (<= hour 15)))))
655
656 (defun tfheen/org-auto-exclude-function (tag)
657   "Automatic task exclusion in the agenda with / RET"
658   (and (cond
659         ((string= tag "@farm")
660          t)
661         (t
662          (if (tfheen/working-p)
663              (setq tag "@hjemme")
664            (setq tag "@jobb"))
665          (unless (member (concat "-" tag) org-agenda-filter)
666            tag)))
667        (concat "-" tag)))
668
669 (setq org-agenda-auto-exclude-function 'tfheen/org-auto-exclude-function)
670
671 (defun mw-to-mdwn ()
672   (interactive)
673   (save-excursion
674     (replace-regexp "^==== \\(.*\\) ====" "#### \\1" nil (point-min) (point-max))
675     (replace-regexp "^=== \\(.*\\) ===" "### \\1" nil (point-min) (point-max))
676     (replace-regexp "^== \\(.*\\) ==" "## \\1" nil (point-min) (point-max))
677     (replace-regexp "^= \\(.*\\) =" "# \\1" nil (point-min) (point-max))
678    ))