summaryrefslogtreecommitdiffstats
path: root/site/code_vault.org
blob: 394bee155bce11af9ad5340f8e43c84f0e915270 (plain)
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
#+TITLE: Code Vault

Here we have some code snippets that I no longer (intend to) use, but
might still need (to look at) at some point in time.

* Jabber urgency and libnotify

  This piece of code sends a message through ~libnotify~ and sets a
  window urgency hint when a new message is received.

  #+BEGIN_SRC emacs-lisp
(defvar jabber-activity-jids-count 0)

(defun jabber-urgency-hint ()
  (let ((count (length jabber-activity-jids)))
    (unless (= jabber-activity-jids-count count)
      (if (zerop count)
          (x-urgency-hint (selected-frame) nil)
        (x-urgency-hint (selected-frame) t))
      (setq jabber-activity-jids-count count))))

(defun libnotify-jabber-notify (from buf text proposed-alert)
  "(jabber.el hook) Notify of new Jabber chat messages via libnotify"
  (when (or jabber-message-alert-same-buffer
            (not (memq (selected-window) (get-buffer-window-list buf))))
    (if (jabber-muc-sender-p from)
        (notify-send (format "(PM) %s"
                             (jabber-jid-displayname
                              (jabber-jid-user from)))
                     (format "%s: %s" (jabber-jid-resource from) text)))
    (notify-send (format "%s: " (jabber-jid-displayname from))
                 (format "%.20s" text))))

(add-hook 'jabber-activity-update-hook 'jabber-urgency-hint)
(add-hook 'jabber-alert-message-hooks 'libnotify-jabber-notify)
  #+END_SRC

* Show symbol instead of ~lambda~

  #+BEGIN_SRC emacs-lisp
(defun oni:pretty-lambdas ()
  "Show a lambda sign where the world `lambda' is found."
  (font-lock-add-keywords
   nil `(("(?\\(\\<lambda\\>\\)[ :]"
          (0 (progn
               (compose-region (match-beginning 1)
                               (match-end 1)
                               ?λ)))))))
  #+END_SRC