Source

.emacs.d / lisplets / activate-babenv.el

The fluss branch has multiple heads

Full commit
  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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
;;;; Basic settings by Arne Babenhauserheide

;;; basic requirements for all activate snippets
(require 'activate-base)


;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Modes and features ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;

;; rainbow coloring of all text
(require 'rainbow-text)

;; Convenient printing
(require 'printing)
(pr-update-menus t)
; make sure we use localhost as cups server
(setenv "CUPS_SERVER" "localhost")
(require 'cups)

; EDE for JAVA
;; (require 'ede-generic)
;; (defclass ede-generic-ant-project (ede-generic-project)
;;   ((buildfile :initform "build.xml"))
;;   "Generic project for Ant projects")
;; (defmethod ede-generic-setup-configuration ((proj
;; ede-generic-ant-project) config)
;;   "Set up a configuration for Ant."
;;   (oset config build-command "ant -f"))
;; (ede-generic-new-autoloader "edeproject-ant" "Ant"
;;                             "build.xml" 'ede-generic-ant-project)
;; (defclass ede-generic-target-java (ede-generic-target)
;;   ((shortname :initform "Java")
;;    (extension :initform "java"))
;;   "EDE Generic Project target for Java code.
;; All directories need at least one target.")
;; (setq ede-locate-setup-options
;;       '(ede-locate-global
;;         ede-locate-base))
;; (semanticdb-enable-gnu-global-databases 'java-mode)
;; (semanticdb-enable-gnu-global-databases 'jde-mode)


; use ido mode for file and buffer Completion when switching buffers
(require 'ido)
(ido-mode t)

; persistent history
(savehist-mode t)

; use allout minor mode to have outlining everywhere.
(allout-mode)

; Address book on steroids
(require 'bbdb)
(bbdb-initialize  'message 'w3)

; and bbdb-vcard importer
(require 'vcard)
(require 'bbdb-vcard)

(require 'org)
(require 'ob-R)
; and org mode, though mainly for remember
(setq org-directory "~/.emacs.d/private/org")
(setq org-default-notes-file (concat org-directory "/emacs-remember-mode.org"))
(setq remember-data-file (concat org-directory "/emacs-remember-mode.org"))
(require 'remember)
(require 'remember-bbdb)
;(require 'remember-planner)
(require 'activate-quick-note)
;(org-remember-insinuate)

; and some more org stuff → http://orgmode.org/guide/Activation.html#Activation
; The following lines are always needed.  Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

(defun org-insert-quote (q)
  (interactive "sEnter Quote: ")
  (insert "#+begin_quote\n«" q "»\n#+end_quote"))
  
; and add reftex for org-mode
;(add-hook 'org-mode-hook 'turn-on-reftex)
(add-to-list 'auto-mode-alist '("\\.bib\\'" . bibtex-mode))
(add-hook 'bibtex-mode-hook 'auto-revert-mode)
(setq reftex-default-bibliography
      (quote
       ("/home/arne/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/ref")))
; from http://tincman.wordpress.com/2011/01/04/research-paper-management-with-emacs-org-mode-and-reftex/
(defun org-mode-reftex-search ()
  ;;jump to the notes for the paper pointed to at from reftex search
  (interactive)
  (org-open-link-from-string (format "[[notes:%s]]" (reftex-citation t))))
; A way to guess the master filename for a newly opened file, if the master is already open.
(defun guess-TeX-master (filename)
      "Guess the master file for FILENAME from currently open .tex files."
      (let ((candidate nil)
            (filename (file-name-nondirectory filename)))
        (save-excursion
          (dolist (buffer (buffer-list))
            (with-current-buffer buffer
              (let ((name (buffer-name))
                    (file buffer-file-name))
                (if (and file (string-match "\\.tex$" file))
                    (progn
                      (goto-char (point-min))
                      (if (re-search-forward (concat "\\\\input{" filename "}") nil t)
                          (setq candidate file))
                      (if (re-search-forward (concat "\\\\include{" (file-name-sans-extension filename) "}") nil t)
                          (setq candidate file))))))))
        (if candidate
            (message "TeX master document: %s" (file-name-nondirectory candidate)))
        candidate))

(defun org-mode-reftex-setup ()
  (interactive)
  (and (buffer-file-name) (file-exists-p (buffer-file-name))
       (progn
		; Reftex should use the org file as master file. See C-h v TeX-master for infos.
		(setq TeX-master t)
		(turn-on-reftex)
		; don’t ask for the tex master on every start.
        (reftex-parse-all)
        ;add a custom reftex cite format to insert links
        (reftex-set-cite-format
         '((?b . "[[bib:%l][%l-bib]]")
           (?n . "[[notes:%l][%l-notes]]")
           (?p . "[[papers:%l][%l-paper]]")
           (?t . "%t")
           (?h . "** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l-paper]]")))))
  (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
  (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search))

(add-hook 'org-mode-hook 'org-mode-reftex-setup)

; add functions to complete papers and bibtex entries
(defun string-replace (this withthat in)
  "replace THIS with WITHTHAT' in the string IN"
  (with-temp-buffer
    (insert in)
    (goto-char (point-min))
    (replace-string this withthat)
    (buffer-substring (point-min) (point-max))))

(defun org-papers-complete-link (&optional arg)
  "Create a papers link using completion."
  (let (file link)
    (let ((pwd (file-name-as-directory (expand-file-name ".")))
	  (pwd1 (file-name-as-directory (abbreviate-file-name
					 (expand-file-name ".")))))
    (setq file (read-file-name "papers: " "papers/"))
    (setq file (string-replace "papers/" "" file))
    (setq file (string-replace pwd "" (string-replace pwd1 "" file)))
    (setq file (string-replace ".pdf" "" file))
    (setq link (org-make-link "papers:" file))
    link)))

(defun org-bib-complete-link (&optional arg)
  "Create a bibtex link using reftex autocompletion."
  (org-make-link "bib:" (reftex-do-citation nil t "bib")))

(setq org-link-abbrev-alist
      '(("bib" . "~/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/ref.bib::%s")
       ("notes" . "~/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/papers.org::#%s")
       ("papers" . "~/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/papers/%s.pdf")))

(setq org-agenda-files (list "~/.emacs.d/private/org/emacs-plan.org"))

; Also journal for quick writing of articles.
(require 'journal)
(if (file-directory-p "~/.emacs.d/private/journal/")
       (setq-default journal-dir "~/.emacs.d/private/journal/"))

; And add proper word wrapping
(global-visual-line-mode t)

; add goto last change
; to the path
(setq load-path (cons "~/.emacs.d/libs/goto-chg" load-path))
(require 'goto-chg)
(global-set-key [(control .)] 'goto-last-change)
(global-set-key [(control meta .)] 'goto-last-change-reverse)

; and add Rudel for Gobby realtime collaboration
(load-file "~/.emacs.d/libs/rudel/rudel-loaddefs.el")
(global-rudel-minor-mode 1)
;; (defun load-rudel ()
;;   (interactive)
;;   (setq load-path (cons "~/.emacs.d/libs/rudel/" load-path))
;;   (setq load-path (cons "~/.emacs.d/libs/rudel/jupiter" load-path))
;;   (setq load-path (cons "~/.emacs.d/libs/rudel/obby" load-path))
;;   (require 'rudel-mode)
;;   (require 'rudel-obby)
;;   (global-rudel-minor-mode))
;; (load-rudel)

;; no fsync on write (faster on USB-stick).
; Set `write-region-inhibit-fsync' to non-nil: avoid fsync on write. "Customize Save" in the !Emacs Manual (C-h r g Customize Save <RET>).
; On sane filesystems like (not 'vfat), this removes the short freezing on write.
(setq write-region-inhibit-fsync t)

; And activate the type-break-mode, to save my hands :)
;(type-break-mode t)

; typing of emacs: learn typing by shooting - - - well: words
(require 'typing)

; and add htmlize to be able to export a buffer to html.
(require 'htmlize)

; and add ezbl for uzbl control via emacs.
; (setq load-path (cons "~/.emacs.d/libs/ezbl" load-path))
; (require 'ezbl)

; and control-lock-mode, so we can enter a vi style command-mode.
(require 'control-lock)
; also bind M-ü and M-ä to toggling control lock.
(global-set-key (kbd "M-ü") 'control-lock-toggle)
(global-set-key (kbd "C-ü") 'control-lock-toggle)
(global-set-key (kbd "M-ä") 'control-lock-toggle)
(global-set-key (kbd "C-ä") 'control-lock-toggle)
(global-set-key (kbd "S-SPC ü") 'control-lock-toggle)

; and use cua mode to get xcvz (to make it easier to work with other software).
; reduce the delay to 0.005 to make it snappy.
; (cua-mode t)
; (setq cua-prefix-override-inhibit-delay 0.005)

;; and emms
(require 'activate-emms)

; and F14 and F15 for org plan
; F14 switches to plan. C-F14 switches back
; F13 (<print>) for agenda today (scheduled + TODOs), C-F13 for the week.
(defun switch-to-plan()
  (interactive)
  (bookmark-jump "emacs-plan"))
(global-set-key [Scroll_Lock] 'switch-to-plan)
(defun switch-back()
  (interactive)
  (switch-to-buffer nil)) ; this is a glorified C-x b ENTER
(global-set-key [C-Scroll_Lock] 'switch-back)
(defun timer-pause-continue-or-start()
  (interactive)
  (if (not org-timer-start-time) 
      (org-timer-start)
    (org-timer-pause-or-continue)))
(global-set-key [pause] 'timer-pause-continue-or-start)
(defun timer-write-and-stop()
  (interactive)
  (org-timer-item)
  (org-timer-stop))
(global-set-key [C-pause] 'timer-write-and-stop)

(setq org-agenda-custom-commands
      '(("o" "Agenda and TODOs"
         ((tags "KANBAN")
		  (agenda nil)
          (todo "")))))
(defun agenda-and-todo ()
  (interactive)
  (org-agenda nil "o"))

;; (defun kanban ()
;;   (interactive)
;;   (find-file "~/plan.org")
;;   (goto-line 0)
;;   (search-forward ":KANBAN:")
;;   (org-tree-to-indirect-buffer 1)
;  (org-narrow-to-subtree 1)

; and F13 for agenda-list: The org-key
(global-set-key [print] 'agenda-and-todo)
; (global-set-key [print] 'org-agenda-list)
(global-set-key [C-print] 'switch-to-plan)
(global-set-key [S-C-print] 'switch-back)
; this requires a recent version of org-mode, so we add some error handling.
;; (defmacro try (fn &rest clean-up)
;;   `(unwind-protect
;;        (let (retval)
;;          (condition-case ex
;;              (setq retval (progn ,fn))
;;            ('error
;;             (message (format "Caught exception: [%s]" ex))
;;             (setq retval (cons 'exception (list ex)))))
;;          retval)
;;      ,@clean-up))
;; (try (org-capture nil "t") ())
(defun org-capture-task ()
  (interactive)
  (condition-case ex
      (org-capture nil "t")
    ('void-function (message "org-capture is not known. You may need a more recent version of org-mode."))))
(global-set-key [M-print] 'org-capture-task)
(global-set-key [s-print] 'org-capture-task)
(global-set-key [H-print] 'org-capture-task)

; babel, for executing code in org-mode.
;(org-babel-do-load-languages
; 'org-babel-load-languages
; '((python . t)
;   (sh . t)
;   (emacs-lisp . t)))

; org-mode babel latex export with highliting
(require 'org-latex)
(add-to-list 'org-export-latex-packages-alist '("" "minted"))
(add-to-list 'org-export-latex-packages-alist '("" "color"))
(setq org-export-latex-listings 'minted)

; org mode protokoll latex export class
(add-to-list 'org-export-latex-classes
             `("protokoll"
               "\\documentclass{scrartcl}\\usepackage{parskip}\\usepackage{underscore}\\setlength{\\parindent}{0cm}"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" "\\newpage" "\\subsection*{%s}" "\\newpage")
               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
             )

; org mode flyer latex export class
(add-to-list 'org-export-latex-classes
             `("leaflet"
               "\\documentclass{leaflet}\\usepackage{parskip}\\usepackage{underscore}\\setlength{\\parindent}{0cm}"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" "\\newpage" "\\subsection*{%s}" "\\newpage")
               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
             )


(add-to-list 'org-export-latex-classes
             `("brief"
               "\\documentclass{scrlttr2}
\\usepackage{parskip}
\\usepackage{underscore}
\\usepackage[ngerman]{babel}
\\setlength{\\parindent}{0cm}
\\KOMAoptions{paper=a4}"
               ("\n\\vspace{3mm}\\hspace*{10mm}\\textbf{%s}\n\\vspace{3mm}" . "\n\\vspace{3mm}\\hspace*{10mm}\\textbf{%s}\n\\vspace{3mm}")
               ("\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}" . "\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}")
               ("\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}" . "\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}")
               ("\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}" . "\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}")
               ("\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}" . "\n\\vspace{3mm}\\hspace*{5mm}\\textit{%s}\n\\vspace{3mm}")
             ))


; ToDoChiKu
(require 'todochiku)


(setq semantic-load-turn-useful-things-on t)
(setq global-semantic-show-tag-boundaries-mode nil)
(setq global-semantic-show-parser-state-mode nil)
(setq semanticdb-default-save-directory "/tmp")
(setq semanticdb-global-mode nil)
(setq semanticdb-persistent-path (quote (never)))
(semantic-load-enable-code-helpers)
(global-semantic-auto-parse-mode -1)
(global-semantic-show-unmatched-syntax-mode -1)
(setq truncate-partial-width-windows nil)
(add-hook 'outline-mode-hook 
          (lambda () 
            (require 'outline-magic)))
            
(add-hook 'outline-minor-mode-hook 
          (lambda () 
            (require 'outline-magic)
            (define-key outline-minor-mode-map [(f10)] 'outline-cycle)))

; Nyan mode :)
; and add Rudel for Gobby realtime collaboration
; (load-file "~/.emacs.d/libs/nyan-mode/nyan-mode.el")
(require 'nyan-mode)
(nyan-mode 1)

; Google maps
(require 'google-maps)
(require 'org-location-google-maps)

;; let emacs blink when something interesting happens.
;; does not work in KDE…
(defun x-urgency-hint (frame arg &optional source)
  (let* ((wm-hints (append (x-window-property 
                            "WM_HINTS" frame "WM_HINTS" 
                            (if source
                                source
                              (string-to-number 
                               (frame-parameter frame 'outer-window-id)))
                            nil t) nil))
         (flags (car wm-hints)))
    (setcar wm-hints
            (if arg
                (logior flags #x00000100)
              (logand flags #xFFFFFEFF)))
    (x-change-window-property "WM_HINTS" wm-hints frame "WM_HINTS" 32 t)))

(defun x-urgent (&optional arg)
  (interactive)
  (let (frame (car (car (cdr (current-frame-configuration)))))
  (x-urgency-hint frame t)))


; transpose-paragraphs with C-x M-tx
(global-set-key (kbd "C-x M-t") 'transpose-paragraphs)


;; Show unicode characters
(require 'xub-mode)
(defun copy-char-at-point ()
  (interactive)
  (copy-region-as-kill (point) (+ (point) 1)))
(defun charselect (&optional start end)
  (interactive "nstart: \nnend: ")
  (switch-to-buffer (get-buffer-create "*UNICODE*"))
  (erase-buffer)
  (let ( (i start) )
    (while (<= i end)
      (insert (format "%s" (char-to-string i)))
      (setq i (1+ i))
      ))
  (local-set-key "\C-w" 'copy-char-at-point)
  (xub-mode))
(defun charselect-arrows ()
  (interactive)
  (charselect 8592 8703))

;; Hightlight TODO and FIXME in comments 
(require 'fic-ext-mode)
(defun add-something-to-mode-hooks (mode-list something)
  "helper function to add a callback to multiple hooks"
  (dolist (mode mode-list)
    (add-hook (intern (concat (symbol-name mode) "-mode-hook")) something)))

(add-something-to-mode-hooks '(c++ tcl emacs-lisp python text markdown latex) 'fic-ext-mode)


(setq load-path (cons "~/.emacs.d/libs/ebib" load-path))
(require 'ebib)

;; Convenient printing
(require 'printing)
(pr-update-menus t)
; make sure we use localhost as cups server
(setenv "CUPS_SERVER" "localhost")
(require 'cups)

; rainbow-color brackets
(setq load-path (cons "~/.emacs.d/libs/rainbow-delimiters" load-path))
(require 'rainbow-delimiters)

; put the current w3m url into register a
(defun w3m-current-url-to-register-a ()
  (interactive)
  (set-register 97 w3m-current-url))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; activate snippets to use ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Latex
(require 'activate-latex-ide)

(require 'activate-markdown)
(require 'activate-auto-complete)

; requires auto-complete
(require 'popup-kill-ring)

; whitespace cleanup
(require 'activate-ethan-wspace)

;(require 'activate-ropemacs-integration)
(require 'activate-german-spelling)
; allow quick switching
(defun fd-switch-dictionary()
  (interactive)
  (let* ((dic ispell-current-dictionary)
         (change (if (string= dic "deutsch8") "english" "deutsch8")))
    (ispell-change-dictionary change)
    (message "Dictionary switched from %s to %s" dic change)
    ))

; alternate command name
(defun flyspell-switch-dictionary()
  (interactive)
  (fd-switch-dictionary))

; Activate transparent GnuPG encryption.
(require 'epa-file)
(epa-file-enable)

; Identi.ca mode
(require 'activate-identica)

; command frequency
;(require 'activate-command-frequency)

; fullscreen darkroom via F11
(require 'activate-darkroom)

; KDE integration
(require 'activate-kde-default-keybindings)

;;; custom commands

; colored shell commands via C-!
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(defun my-shell-execute(cmd)
  "Execute a shell command in an interactive shell buffer."
   (interactive "sShell command: ")
   (shell (get-buffer-create "shell-commands-buf"))
   (process-send-string (get-buffer-process "shell-commands-buf") (concat cmd "\n")))
(global-set-key (kbd "C-!") 'my-shell-execute)

; also a simple way to get the current date
(defun date ()
  "print the current time and date in iso-format"
  (interactive)
  ; string format: empty line, date, ----, empty line.
  (insert "\n\n" (format-time-string "%Y-%m-%d %H:%M:%S") "\n-------------------\n\n"))

(defun tagebucheintrag ()
  (interactive)
  (bookmark-jump "tagebuch")
  (goto-char (point-max))
  (date))

; not needed at work
;(global-set-key "\C-ct" 'tagebucheintrag)

; also a simple way to get the current date
(defun markdown-splitter ()
  "print the current time and date in iso-format"
  (interactive)
  ; string format: empty line, date, ----, empty line.
  (insert "\n\n------\n\n"))

(defun 1w6-idee ()
  (interactive)
  (bookmark-jump "1w6-ideen")
  (goto-char (point-max))
  (markdown-splitter))

(global-set-key "\C-cw" '1w6-idee)

; and use shift-space as C-x, for ergonomics
; update: don’t use shift-space as C-x anymore, because I have a better keyboard, now.
; (global-set-key [?\S- ] ctl-x-map)

;; remove consecutive duplicate lines
;; see http://www.emacswiki.org/emacs/DuplicateLines
(defun uniquify-all-lines-region (start end)
    "Find duplicate lines in region START to END keeping first occurrence."
    (interactive "*r")
    (save-excursion
      (let ((end (copy-marker end)))
        (while
            (progn
              (goto-char start)
              (re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t))
          (replace-match "\\1\n\\2")))))

(defun uniquify-all-lines-buffer ()
    "Delete duplicate lines in buffer and keep first occurrence."
    (interactive "*")
    (uniquify-all-lines-region (point-min) (point-max)))


(defun diplom-bach () (interactive)
  """jump to diplom"""
  (bookmark-jump "diplom"))

; chording
(require 'stenochords)

; python
(require 'activate-python)


;; display time in status bar:
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)

;; battery mode:
;(require 'battery)
;(setq battery-mode-line-format " [%L %p%% %dC]")
;(display-battery-mode)

; Fortran stuff
(require 'fortran-tools)

; strike text

(defun strikethrough (start end)
  (interactive "r") 
  (goto-char (min start end))
  (while (< (point) (+ (max start end) (abs (- start end))))
	(forward-char)
	(insert "̶")))

; Kanban for org-mode
(require 'kanban)

; phone book
(require 'bbdb-phone-book)

; timed notes in bbdb
(require 'bbdb-timed-notes)

;;;;;;;;;;;;;
;;; Fixes ;;;
;;;;;;;;;;;;;

; Also tell emacs to ignore alt-gr clicks needed for M4 in the Neo Layout.
; Means: don’t beep.
(define-key special-event-map (kbd "<key-17>") 'ignore)
(define-key special-event-map (kbd "<M-key-17>") 'ignore)

; and make it resize correctly in KDE (and hopefully in dwm, too)
(tool-bar-mode -1)

; yank-pop should yank if the last command was no yank.
(defun yank-pop (&optional arg)
  "Replace just-yanked stretch of killed text with a different stretch.
At such a time, the region contains a stretch of reinserted
previously-killed text.  `yank-pop' deletes that text and inserts in its
place a different stretch of killed text.

With no argument, the previous kill is inserted.
With argument N, insert the Nth previous kill.
If N is negative, this is a more recent kill.

The sequence of kills wraps around, so that after the oldest one
comes the newest one.

When this command inserts killed text into the buffer, it honors
`yank-excluded-properties' and `yank-handler' as described in the
doc string for `insert-for-yank-1', which see."
  (interactive "*p")
  (if (not (eq last-command 'yank))
      (yank)
    (setq this-command 'yank)
    (unless arg (setq arg 1))
    (let ((inhibit-read-only t)
          (before (< (point) (mark t))))
      (if before
          (funcall (or yank-undo-function 'delete-region) (point) (mark t))
        (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
      (setq yank-undo-function nil)
      (set-marker (mark-marker) (point) (current-buffer))
      (insert-for-yank (current-kill arg))
      ;; Set the window start back where it was in the yank command,
      ;; if possible.
      (set-window-start (selected-window) yank-window-start t)
      (if before
          ;; This is like exchange-point-and-mark, but doesn't activate the mark.
          ;; It is cleaner to avoid activation, even though the command
          ;; loop would deactivate the mark because we inserted text.
          (goto-char (prog1 (mark t)
                       (set-marker (mark-marker) (point) (current-buffer))))))
    nil))

;; Get rid of F9 starting gnuplot mode
(global-unset-key (kbd "<f9>"))


;;;;;;;;;;;;;;;;;;;;;;;
;;; Tipps from cern ;;;
;;; https://twiki.cern.ch/twiki/bin/view/CDS/EmacsTips
;;;;;;;;;;;;;;;;;;;;;;;

(setq visible-bell t)


(setq backup-by-copying t      ; don't clobber symlinks
      backup-directory-alist
      '(("." . "~/.local/share/emacs-saves"))    ; don't litter my fs tree
      delete-old-versions t
      kept-new-versions 6
      kept-old-versions 2
      version-control t)       ; use versioned backups

(require 'saveplace)
(setq-default save-place t)
(savehist-mode t)

;; which function am I editing?
;(when (>= emacs-major-version 23)
;  (add-hook 'python-mode-hook
;           (lambda ()
;             (which-function-mode t))))

;; spell check only strings/comments when in Python mode: Disabled,
;; because it kills my default of using C-. to jump to the last
;; change.

; (add-hook 'python-mode-hook 'flyspell-prog-mode)

;(when (locate-library "ipython")
;  (require 'ipython)
;  (setq py-python-command-args '("-colors" "Linux")))

(require 'w3m-search)
(eval-after-load "w3m-search"
  '(progn
     (add-to-list 'w3m-search-engine-alist
                  '("wikipedia-en"
                    "http://en.wikipedia.org/wiki/Special:Search?search=%s"
                    nil))
     (add-to-list 'w3m-uri-replace-alist
                  '("\\`wp:" w3m-search-uri-replace "wikipedia-en"))))

;; Add google searching
(defun gg ()
  (interactive)
  (let ((m (if (mark) (mark) 1)))
  (let ((start (min (point) m))
	   (end (max (point) m)))
	   (let ((default (if (and (not (eq start end)) (= (count-lines start end) 1) (>= (- end start) 3) ) (concat "gg:" (buffer-substring start end)) "gg:")))
		 (w3m-goto-url (read-from-minibuffer "Search: " default))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Additional settings ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Use the system clipboard
(setq x-select-enable-clipboard t)

; Tell tramp (remote file access) to use ssh by default and connect to my local ssh forward when using /ssh::
(setq tramp-default-method "ssh")
(setq tramp-default-user "arne"
           tramp-default-host "localhost#2222")

; and save the scratch buffer on exit
; → http://xxtjaxx.homelinux.net/snippet/SaveYourScratch/
(defun save-scratch ()
  (switch-to-buffer (get-buffer "*scratch*"))
  (write-file "~/.scratch.el" nil)
  )
(add-hook 'kill-emacs-hook 'save-scratch)
(setq initial-scratch-message (shell-command-to-string "cat ~/.scratch.el") )


;; save registerts and open files over restarts,
;; thanks to http://www.xsteve.at/prg/emacs/power-user-tips.html
;; save a list of open files in ~/.emacs.desktop
;; save the desktop file automatically if it already exists
;(setq desktop-save 'if-exists)
;(desktop-save-mode 1)

;; save a bunch of variables to the desktop file
;; for lists specify the len of the maximal saved data also
(setq desktop-globals-to-save
      (append '((extended-command-history . 300)
                (file-name-history        . 100)
                (grep-history             . 30)
                (compile-history          . 30)
                (minibuffer-history       . 5000)
                (query-replace-history    . 60)
                (read-expression-history  . 60)
                (regexp-history           . 60)
                (regexp-search-ring       . 20)
                (search-ring              . 2000)
                (shell-command-history    . 50)
                tags-file-name
                register-alist)))

;; restore only 5 buffers at once and the rest lazily
(setq desktop-restore-eager 5)

; maybe nicer: http://github.com/doomvox/desktop-recover

;; also add private data
(require 'activate-private-data)

; and wanderlust for mail.
(require 'activate-wanderlust)

; add tm5 rc file syntax highlighting
(require 'font-lock-tm5rc)

(defun pyrad ()
  (interactive)
  (call-process-shell-command "dbus-send --type=method_call --dest=org.kde.pyRad /MainApplication org.kde.KUniqueApplication.newInstance"))

(global-set-key [M-f6] 'pyrad)

(defun freenet-darknet ()
       (interactive)
       (insert "Besides: If you run freenet¹ for censorship-resistant communication, I’d love to add your node as darknet contact. ¹: http://freenetproject.org"))

;; Open the plan file and switch to my basic starting folder
(find-file "~/.emacs.d/private/org/emacs-plan.org")
(cd "~/Quell")

(provide 'activate-babenv)