From 9451afae694e90211fe1c8a500daa50cc886b735 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 16 Sep 2011 12:11:16 +0200 Subject: [PATCH] EMACS: Add X urgency hint when someone speaks to me on jabber --- .emacs.d/init.el | 65 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 23d68f8..6896d41 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -3,7 +3,7 @@ (normal-top-level-add-subdirs-to-load-path)) ;;-----[ Defun ]--------------------------------------------------------- -(defun oni/what-face (pos) +(defun ext/what-face (pos) "Find out which face the current position uses" (interactive "d") (let ((face (or (get-char-property (point) 'read-face-name) @@ -12,11 +12,11 @@ (message "Face: %s" face) (message "No face at %d" pos)))) -(defun oni/what-major-mode (buffer-or-string) +(defun ext/what-major-mode (buffer-or-string) "Find out which major-mode is currently used" (with-current-buffer buffer-or-string major-mode)) -(defun oni/my-comp-finish-function (buf str) +(defun ext/my-comp-finish-function (buf str) "Don't show compilation window if everything went ok" (if (string-match "exited abnormally" str) ;; there were errors @@ -25,6 +25,29 @@ (run-at-time 0.5 nil 'delete-windows-on buf) (message "NO COMPILATION ERRORS!"))) +(defun ext/pretty-lambdas () + (font-lock-add-keywords + nil `(("(\\(lambda\\>\\)" + (0 (progn + (compose-region (match-beginning 1) + (match-end 1) + ?λ))))))) + +(defun ext/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 oni/c-toggle-header-source () "Toggle between a C source and header file" (interactive) @@ -49,9 +72,9 @@ (oni/replace-occurrences "é" "é")) (defun oni/before-save-hook () - (if (eq (oni/what-major-mode (current-buffer)) 'html-mode) + (if (eq (ext/what-major-mode (current-buffer)) 'html-mode) (oni/replace-html-special-chars)) - (if (not (eq (oni/what-major-mode (current-buffer)) 'markdown-mode)) + (if (not (eq (ext/what-major-mode (current-buffer)) 'markdown-mode)) (delete-trailing-whitespace))) (defun oni/after-save-hook () @@ -59,14 +82,6 @@ (suffix (file-name-extension fname))) (if (string-equal suffix "el") (byte-compile-file fname)))) - -(defun oni/pretty-lambdas () - (font-lock-add-keywords - nil `(("(\\(lambda\\>\\)" - (0 (progn - (compose-region (match-beginning 1) - (match-end 1) - ?λ))))))) ;;-----[ Theme ]--------------------------------------------------------- (require 'naquadah-theme) @@ -118,7 +133,7 @@ `((,integer-regex-1 0 font-lock-constant-face) (,integer-regex-2 0 font-lock-constant-face))) (rainbow-delimiters-mode) - (oni/pretty-lambdas) + (ext/pretty-lambdas) (set-column-markers 73 81)) (if (>= emacs-major-version 24) @@ -320,6 +335,21 @@ (require 'autosmiley) ;;-----[ Jabber ]-------------------------------------------------------- +(defvar ext/jabber-activity-jids-count 0) + +(defun ext/jabber-urgency-hint () + (let ((count (length jabber-activity-jids))) + (unless (= ext/jabber-activity-jids-count count) + (if (zerop count) + (ext/x-urgency-hint (selected-frame) nil) + (ext/x-urgency-hint (selected-frame) t)) + (setq ext/jabber-activity-jids-count count)))) + +(defun oni/jabber-chat-mode-hook () + (autosmiley-mode) + (local-set-key [S-return] 'newline) + (local-set-key [C-return] 'newline)) + (when (require 'jabber-autoloads nil 'noerror) (setq jabber-account-list '(("ryuslash@gmail.com" @@ -327,9 +357,8 @@ (:connection-type . ssl)))) (setq jabber-history-enabled t) (setq jabber-use-global-history nil) - (define-key jabber-chat-mode-map [S-return] 'newline) - (define-key jabber-chat-mode-map [C-return] 'newline) - (add-hook 'jabber-chat-mode-hook 'autosmiley-mode)) + (add-hook 'jabber-chat-mode-hook 'oni/jabber-chat-mode-hook) + (add-hook 'jabber-activity-update-hook 'ext/jabber-urgency-hint)) ;;-----[ X11 ]----------------------------------------------------------- (when window-system @@ -449,7 +478,7 @@ (delete-selection-mode t) (show-paren-mode t) -(add-to-list 'compilation-finish-functions 'oni/my-comp-finish-function) +(add-to-list 'compilation-finish-functions 'ext/my-comp-finish-function) (global-set-key "\C-m" 'newline-and-indent) (global-set-key (kbd "C-x n r") 'narrow-to-region)