Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
343 lines (290 sloc) 11.3 KB
;;; helm-misc.el --- Various functions for helm
;; Copyright (C) 2012 Thierry Volpiatto <>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Code:
(eval-when-compile (require 'cl))
(require 'helm)
(defgroup helm-misc nil
"Various Applications and libraries for Helm."
:group 'helm)
(defcustom helm-time-zone-home-location "Paris"
"The time zone of your home"
:group 'helm-misc
:type 'string)
(defface helm-time-zone-current
'((t (:foreground "green")))
"Face used to colorize current time in `helm-world-time'."
:group 'helm-misc)
(defface helm-time-zone-home
'((t (:foreground "red")))
"Face used to colorize home time in `helm-world-time'."
:group 'helm-misc)
;;; Latex completion
(defun helm-latex-math-candidates ()
"Collect candidates for latex math completion."
(declare (special LaTeX-math-menu))
(loop for i in (cddr LaTeX-math-menu)
for elm = (loop for s in i when (vectorp s)
collect (cons (aref s 0) (aref s 1)))
append elm))
(defvar helm-source-latex-math
'((name . "Latex Math Menu")
(init . (lambda ()
(LaTeX-math-mode 1))))
(candidate-number-limit . 9999)
(candidates . helm-latex-math-candidates)
(action . (lambda (candidate)
(call-interactively candidate)))))
;;;; <Headline Extraction>
(defvar helm-source-fixme
'((name . "TODO/FIXME/DRY comments")
(headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
"Show TODO/FIXME/DRY comments in current file.")
(defvar helm-source-rd-headline
'((name . "RD HeadLine")
(headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
(condition . (memq major-mode '(rdgrep-mode rd-mode)))
(subexp . 1))
"Show RD headlines.
RD is Ruby's POD.")
(defvar helm-source-oddmuse-headline
'((name . "Oddmuse HeadLine")
(headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
"^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
(condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
(subexp . 1))
"Show Oddmuse headlines, such as EmacsWiki.")
(defvar helm-source-emacs-source-defun
'((name . "Emacs Source DEFUN")
(headline . "DEFUN\\|DEFVAR")
(condition . (string-match "/emacs2[0-9].+/src/.+c$"
(or buffer-file-name ""))))
"Show DEFUN/DEFVAR in Emacs C source file.")
(defvar helm-source-emacs-lisp-expectations
'((name . "Emacs Lisp Expectations")
(headline . "(desc[ ]\\|(expectations")
(condition . (eq major-mode 'emacs-lisp-mode)))
"Show descriptions (desc) in Emacs Lisp Expectations.")
(defvar helm-source-emacs-lisp-toplevels
'((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
(headline . "^(\\|(@\\*\\|^;;;;")
(get-line . buffer-substring)
(condition . (eq major-mode 'emacs-lisp-mode))
"Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
linkd.el is optional because linkd stars are extracted by regexp.")
;;; Eev anchors
(defvar helm-source-eev-anchor
'((name . "Anchors")
. (lambda ()
(loop initially (goto-char (point-min))
while (re-search-forward
(format ee-anchor-format "\\([^\.].+\\)") nil t)
for anchor = (match-string-no-properties 1)
collect (cons (format "%5d:%s"
(line-number-at-pos (match-beginning 0))
(format ee-anchor-format anchor))
(persistent-action . (lambda (item)
(ee-to item)
(persistent-help . "Show this entry")
(action . (("Goto link" . ee-to)))))
;;; Jabber Contacts (jabber.el)
(defun helm-jabber-online-contacts ()
"List online Jabber contacts."
(let (jids)
(dolist (item (jabber-concat-rosters) jids)
(when (get item 'connected)
(push (if (get item 'name)
(cons (get item 'name) item)
(cons (symbol-name item) item)) jids))))))
(defvar helm-source-jabber-contacts
'((name . "Jabber Contacts")
(init . (lambda () (require 'jabber)))
(candidates . (lambda () (mapcar 'car (helm-jabber-online-contacts))))
(action . (lambda (x)
(cdr (assoc x (helm-jabber-online-contacts)))))))))
;;; World time
(defun helm-time-zone-transformer (candidates sources)
(loop for i in candidates
(cond ((string-match (format-time-string "%H:%M" (current-time)) i)
(propertize i 'face 'helm-time-zone-current))
((string-match helm-time-zone-home-location i)
(propertize i 'face 'helm-time-zone-home))
(t i))))
(defvar helm-source-time-world
'((name . "Time World List")
(init . (lambda ()
(let ((helm-buffer (helm-candidate-buffer 'global)))
(with-current-buffer helm-buffer
(display-time-world-display display-time-world-list)))))
(filtered-candidate-transformer . helm-time-zone-transformer)))
;;; LaCarte
(defvar helm-source-lacarte
'((name . "Lacarte")
(init . (lambda () (require 'lacarte)))
(candidates . (lambda ()
(delete '(nil) (lacarte-get-overall-menu-item-alist)))))
(candidate-number-limit . 9999)
(action . helm-call-interactively))
"Needs lacarte.el.")
(defun helm-call-interactively (cmd-or-name)
"Execute CMD-OR-NAME as Emacs command.
It is added to `extended-command-history'.
`helm-current-prefix-arg' is used as the command's prefix argument."
(setq extended-command-history
(cons (helm-stringify cmd-or-name)
(delete (helm-stringify cmd-or-name) extended-command-history)))
(let ((current-prefix-arg helm-current-prefix-arg)
(cmd (helm-symbolify cmd-or-name)))
(if (stringp (symbol-function cmd))
(execute-kbd-macro (symbol-function cmd))
(setq this-command cmd)
(call-interactively cmd))))
;; Minibuffer History
(defvar helm-source-minibuffer-history
'((name . "Minibuffer History")
(header-name . (lambda (name)
(format "%s (%s)" name minibuffer-history-variable)))
. (lambda ()
(let ((history (loop for i in
(symbol-value minibuffer-history-variable)
unless (string= "" i) collect i)))
(if (consp (car history))
(mapcar 'prin1-to-string history)
(action . (lambda (candidate)
(insert candidate)))))
;;; Helm ratpoison UI
(defvar helm-source-ratpoison-commands
'((name . "Ratpoison Commands")
(init . helm-ratpoison-commands-init)
(action ("Execute the command" . helm-ratpoison-commands-execute))
(display-to-real . helm-ratpoison-commands-display-to-real)
(defun helm-ratpoison-commands-init ()
(unless (helm-candidate-buffer)
(with-current-buffer (helm-candidate-buffer 'global)
;; with ratpoison prefix key
(call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
(while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
(replace-match "<ratpoison> \\1: \\2"))
(goto-char (point-max))
;; direct binding
(call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
(while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
(replace-match "\\1: \\2")))))
(defun helm-ratpoison-commands-display-to-real (display)
(and (string-match ": " display)
(substring display (match-end 0))))
(defun helm-ratpoison-commands-execute (candidate)
(call-process "ratpoison" nil nil nil "-ic" candidate))
;;; Helm stumpwm UI
(defvar helm-source-stumpwm-commands
'((name . "Stumpwm Commands")
(init . helm-stumpwm-commands-init)
(action ("Execute the command" . helm-stumpwm-commands-execute))
(defun helm-stumpwm-commands-init ()
(with-current-buffer (helm-candidate-buffer 'global)
(call-process "stumpish" nil (current-buffer) nil "commands"))
(while (re-search-forward "\\([^ ]+\\) \n?" nil t)
(replace-match "\\1\n"))
(goto-char (point-max))))
(defun helm-stumpwm-commands-execute (candidate)
(call-process "stumpish" nil nil nil candidate))
(defun helm-world-time ()
"Preconfigured `helm' to show world time."
(helm-other-buffer 'helm-source-time-world "*helm world time*"))
(defun helm-insert-latex-math ()
"Preconfigured helm for latex math symbols completion."
(helm-other-buffer 'helm-source-latex-math "*helm latex*"))
(defun helm-eev-anchors ()
"Preconfigured `helm' for eev anchors."
(helm-other-buffer 'helm-source-eev-anchor "*Helm eev anchors*"))
(defun helm-ratpoison-commands ()
"Preconfigured `helm' to execute ratpoison commands."
(helm-other-buffer 'helm-source-ratpoison-commands
"*helm ratpoison commands*"))
(defun helm-stumpwm-commands()
(helm-other-buffer 'helm-source-stumpwm-commands
"*helm stumpwm commands*"))
(defun helm-mini ()
"Preconfigured `helm' lightweight version \(buffer -> recentf\)."
(require 'helm-files)
(helm-other-buffer '(helm-source-buffers-list
"*helm mini*"))
(defun helm-minibuffer-history ()
"Preconfigured `helm' for `minibuffer-history'."
(let ((enable-recursive-minibuffers t))
(helm-other-buffer 'helm-source-minibuffer-history
"*helm minibuffer-history*")))
(provide 'helm-misc)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; helm-misc.el ends here
Jump to Line
Something went wrong with that request. Please try again.