Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
174 lines (146 sloc) 6.32 KB
;;; helm-yaoddmuse.el --- Helm extension for yaoddmuse
;; 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)
(declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
(declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
;; Be sure to have yaoddmuse.el installed
;; install-elisp may be required if you want to install elisp file from here.
(defvar helm-yaoddmuse-use-cache-file nil)
(defvar helm-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
(defvar helm-c-yaoddmuse-ew-cache nil)
(defun helm-yaoddmuse-get-candidates ()
(declare (special yaoddmuse-pages-hash))
(if helm-yaoddmuse-use-cache-file
(unless helm-c-yaoddmuse-ew-cache
(load helm-c-yaoddmuse-cache-file)
(setq helm-c-yaoddmuse-ew-cache
(gethash "EmacsWiki" yaoddmuse-pages-hash)))
(yaoddmuse-update-pagename t)
(gethash "EmacsWiki" yaoddmuse-pages-hash)))
(defvar helm-c-source-yaoddmuse-emacswiki-edit-or-view
'((name . "Yaoddmuse Edit or View (EmacsWiki)")
(candidates . helm-yaoddmuse-get-candidates)
(action . (("Edit page" . (lambda (candidate)
(yaoddmuse-edit "EmacsWiki" candidate)))
("Browse page"
. (lambda (candidate)
(yaoddmuse-browse-page "EmacsWiki" candidate)))
("Browse page other window"
. (lambda (candidate)
(if (one-window-p)
(yaoddmuse-browse-page "EmacsWiki" candidate)))
("Browse diff"
. (lambda (candidate)
(yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
("Copy URL"
. (lambda (candidate)
(kill-new (yaoddmuse-url "EmacsWiki" candidate))
(message "Have copy page %s's URL to yank." candidate)))
("Create page"
. (lambda (candidate)
(yaoddmuse-edit "EmacsWiki" helm-input)))
("Update cache"
. (lambda (candidate)
(if helm-yaoddmuse-use-cache-file
(helm-yaoddmuse-cache-pages t)
(setq helm-c-yaoddmuse-ew-cache
(gethash "EmacsWiki" yaoddmuse-pages-hash)))
(action-transformer helm-c-yaoddmuse-action-transformer))
"Needs yaoddmuse.el.")
(defvar helm-c-source-yaoddmuse-emacswiki-post-library
'((name . "Yaoddmuse Post library (EmacsWiki)")
(init . (helm-yaoddmuse-init))
(action . (("Post library and Browse"
. (lambda (candidate)
(find-library-name candidate)
(file-name-nondirectory (find-library-name candidate))
nil t)))
("Post library"
. (lambda (candidate)
(find-library-name candidate)
(find-library-name candidate))))))))
"Needs yaoddmuse.el.")
(defun helm-c-yaoddmuse-action-transformer (actions candidate)
"Allow the use of `install-elisp' only on elisp files."
(if (string-match "\.el$" candidate)
(append actions '(("Install Elisp"
. (lambda (elm)
(install-elisp-from-emacswiki elm)))))
(defun helm-yaoddmuse-cache-pages (&optional load)
"Fetch the list of files on emacswiki and create cache file.
If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
(declare (special yaoddmuse-pages-hash))
(find-file helm-c-yaoddmuse-cache-file)
(insert "(puthash \"EmacsWiki\" '(")
(loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
(insert (concat "(\"" (car i) "\") ")))
(insert ") yaoddmuse-pages-hash)\n")
(kill-buffer (current-buffer))
(when (or current-prefix-arg
(load helm-c-yaoddmuse-cache-file))))
(defun helm-yaoddmuse-init ()
"Init helm buffer status."
(let ((helm-buffer (helm-candidate-buffer 'global))
(library-list (yaoddmuse-get-library-list)))
(with-current-buffer helm-buffer
;; Insert library name.
(dolist (library library-list)
(insert (format "%s\n" library)))
;; Sort lines.
(sort-lines nil (point-min) (point-max)))))
(defun helm-yaoddmuse-emacswiki-edit-or-view ()
"Preconfigured `helm' to edit or view EmacsWiki page.
Needs yaoddmuse.el."
(helm :sources 'helm-c-source-yaoddmuse-emacswiki-edit-or-view))
(defun helm-yaoddmuse-emacswiki-post-library ()
"Preconfigured `helm' to post library to EmacsWiki.
Needs yaoddmuse.el."
(helm :sources 'helm-c-source-yaoddmuse-emacswiki-post-library))
(provide 'helm-yaoddmuse)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; byte-compile-dynamic: t
;; End:
;;; helm-yaoddmuse.el ends here
Jump to Line
Something went wrong with that request. Please try again.