Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created May 21, 2010 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalmarczyk/408702 to your computer and use it in GitHub Desktop.
Save michalmarczyk/408702 to your computer and use it in GitHub Desktop.
(defmacro -> (e &rest es)
(if (and (consp es) (not (consp (cdr es))))
(if (consp (car es))
`(,(caar es) ,e ,@(cdar es))
`(,(car es) ,e))
(if (consp es)
`(-> (-> ,e ,(car es)) ,@(cdr es))
e)))
(defmacro ->> (e &rest es)
(if (and (consp es) (not (consp (cdr es))))
(if (consp (car es))
`(,@(car es) ,e)
`(,(car es) ,e))
(if (consp es)
`(->> (->> ,e ,(car es)) ,@(cdr es))
e)))
;;; stolen from Lau Jensen, rewritten using ->>
;;; http://www.bestinclass.dk/index.clj/2010/03/approaching-productivity.html
(defun my-erc-clean-message (s)
(->> s
(replace-regexp-in-string "'" "'")
(replace-regexp-in-string "\"" """)
(replace-regexp-in-string "&" "&")
(replace-regexp-in-string "<" "&lt;")
(replace-regexp-in-string ">" "&gt;")))
(defun my-erc-match-call-libnotify (matched-type nick msg)
(let* ((cmsg (split-string (my-erc-clean-message msg)))
(nick (first (split-string nick "!")))
(msg (mapconcat #'identity (rest cmsg) " ")))
(shell-command-to-string
(format "notify-send -u critical '%s says:' '%s'" nick msg))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment