updates
[emacs.git] / .emacs.d / elisp / local / ganneff.el
index eafbf9f..a7c9a39 100644 (file)
 
 ;;; Code:
 
-;;;###autoload
-(defun my-dired-init ()
-  "Bunch of stuff to run for dired when it's loaded."
-  (define-key dired-mode-map [return] 'dired-single-buffer)
-  (define-key dired-mode-map [mouse-1] 'dired-single-buffer-mouse)
-  (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
-  (define-key dired-mode-map "^"
-    (function
-     (lambda nil (interactive) (dired-single-buffer "..")))))
-
 ;;;###autoload
 (defun ido-disable-line-trucation () (set (make-local-variable 'truncate-lines) nil))
 
+; match-paren will either jump to the "other" paren or simply insert %
+; #+BEGIN_SRC emacs-lisp tangle:yes
+;;;###autoload
+(defun match-paren (arg)
+  "Go to the matching parenthesis if on parenthesis otherwise insert %."
+  (interactive "p")
+  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
+        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
+        (t (self-insert-command (or arg 1)))))
 
 ;;;###autoload
 (defun sacha/isearch-yank-current-word ()
@@ -206,6 +205,133 @@ Doesn't mess with special buffers."
 ;(setq org-icalendar-verify-function 'org-mycal-export-limit)
 ;(org-export-icalendar-combine-agenda-files)
 
+
+;;;###autoload
+(defun font-lock-comment-annotations ()
+  "Highlight a bunch of well known comment annotations.
+
+This functions should be added to the hooks of major modes for programming."
+  (font-lock-add-keywords
+   nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|OPTIMIZE\\|HACK\\|REFACTOR\\):"
+          1 font-lock-warning-face t))))
+
+;;;###autoload
+(defun jj-open-shell ()
+  "Open a shell in the directory of the current buffer file"
+
+  (interactive)
+  (when buffer-file-name
+    (setenv "ZSTARTDIR" (file-truename buffer-file-name)))
+  (when dired-directory
+    (setenv "ZSTARTDIR" (concat (file-truename dired-directory) "/dired")))
+  (start-process "open-shell" nil "/usr/bin/x-terminal-emulator"))
+
+; From: http://www.blogbyben.com/2013/09/emacs-function-humanifying-urls.html,
+; licensed CC BY 3.0. Author: Ben Simon
+;;;###autoload
+(defun url-humanify ()
+  "Take the URL at point and make it human readable."
+  (interactive)
+  (let* ((area (bounds-of-thing-at-point 'url))
+         (num-params  (count-matches "&" (car area) (cdr area)))
+         (i 0))
+    (beginning-of-thing 'url)
+    (when (search-forward "?" (cdr area) t nil)
+      (insert "\n  ")
+      (while (< i num-params)
+        (search-forward "&" nil t nil)
+        (insert "\n  ")
+        (save-excursion
+          (previous-line)
+          (beginning-of-line)
+          (let ((start (search-forward "="))
+                (end (search-forward "&")))
+            (url-decode-region start end)))
+        (setq i (+ i 1))))))
+
+; From: http://www.blogbyben.com/2013/09/emacs-function-humanifying-urls.html,
+; licensed CC BY 3.0. Author: Ben Simon
+;;;###autoload
+(defun url-decode-region (start end)
+  "Replace a region with the same contents, only URL decoded."
+  (interactive "r")
+  (let ((text (url-unhex-string (buffer-substring start end))))
+    (delete-region start end)
+    (insert text)))
+
+;;;###autoload
+(defun align-code (beg end &optional arg)
+  (interactive "rP")
+  (if (null arg)
+      (align beg end)
+    (let ((end-mark (copy-marker end)))
+      (indent-region beg end-mark nil)
+      (align beg end-mark))))
+
+;;;###autoload
+ (defun insert-date (prefix)
+    "Insert the current date. With prefix-argument, use ISO format. With
+   two prefix arguments, write out the day and month name."
+    (interactive "P")
+    (let ((format (cond
+                   ((not prefix) "%d.%m.%Y")
+                   ((equal prefix '(4)) "%Y-%m-%d")
+                   ((equal prefix '(16)) "%A, %d. %B %Y")
+                   ((equal prefix '(64)) "%Y-%m-%dT%H:%M:%S.%3N")
+                   ))
+          (system-time-locale "de_DE"))
+      (insert (format-time-string format))))
+
+;;;###autoload
+(defun occur-dwim ()
+  "Call `occur' with a sane default."
+  (interactive)
+  (push (if (region-active-p)
+            (buffer-substring-no-properties
+             (region-beginning)
+             (region-end))
+          (thing-at-point 'symbol))
+        regexp-history)
+  (call-interactively 'occur))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; change case of letters                                                 ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; http://ergoemacs.org/emacs/modernization_upcase-word.html
+;;;###autoload
+(defun toggle-letter-case ()
+  "Toggle the letter case of current word or text selection.
+Toggles between: “all lower”, “Init Caps”, “ALL CAPS”."
+  (interactive)
+  (let (p1 p2 (deactivate-mark nil) (case-fold-search nil))
+    (if (region-active-p)
+        (setq p1 (region-beginning) p2 (region-end))
+      (let ((bds (bounds-of-thing-at-point 'word) ) )
+        (setq p1 (car bds) p2 (cdr bds)) ) )
+
+    (when (not (eq last-command this-command))
+      (save-excursion
+        (goto-char p1)
+        (cond
+         ((looking-at "[[:lower:]][[:lower:]]") (put this-command 'state "all lower"))
+         ((looking-at "[[:upper:]][[:upper:]]") (put this-command 'state "all caps") )
+         ((looking-at "[[:upper:]][[:lower:]]") (put this-command 'state "init caps") )
+         ((looking-at "[[:lower:]]") (put this-command 'state "all lower"))
+         ((looking-at "[[:upper:]]") (put this-command 'state "all caps") )
+         (t (put this-command 'state "all lower") ) ) )
+      )
+
+    (cond
+     ((string= "all lower" (get this-command 'state))
+      (upcase-initials-region p1 p2) (put this-command 'state "init caps"))
+     ((string= "init caps" (get this-command 'state))
+      (upcase-region p1 p2) (put this-command 'state "all caps"))
+     ((string= "all caps" (get this-command 'state))
+      (downcase-region p1 p2) (put this-command 'state "all lower")) )
+    )
+  )
+
+
 (provide 'ganneff)
 
 ;;; ganneff.el ends here