Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

174 lines (146 sloc) 6.472 kb
;;; helm-yaoddmuse.el --- Helm extension for yaoddmuse
;; Copyright (C) 2012 Thierry Volpiatto <thierry.volpiatto@gmail.com>
;; 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; 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 <http://www.gnu.org/licenses/>.
;;; 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
(ignore-errors
(unless helm-c-yaoddmuse-ew-cache
(load helm-c-yaoddmuse-cache-file)
(setq helm-c-yaoddmuse-ew-cache
(gethash "EmacsWiki" yaoddmuse-pages-hash)))
helm-c-yaoddmuse-ew-cache)
(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)
(split-window-vertically))
(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
(progn
(helm-yaoddmuse-cache-pages t)
(setq helm-c-yaoddmuse-ew-cache
(gethash "EmacsWiki" yaoddmuse-pages-hash)))
(yaoddmuse-update-pagename))))))
(action-transformer helm-c-yaoddmuse-action-transformer))
"Needs yaoddmuse.el.
http://www.emacswiki.org/emacs/download/yaoddmuse.el")
(defvar helm-c-source-yaoddmuse-emacswiki-post-library
'((name . "Yaoddmuse Post library (EmacsWiki)")
(init . (helm-yaoddmuse-init))
(candidates-in-buffer)
(action . (("Post library and Browse"
. (lambda (candidate)
(yaoddmuse-post-file
(find-library-name candidate)
"EmacsWiki"
(file-name-nondirectory (find-library-name candidate))
nil t)))
("Post library"
. (lambda (candidate)
(yaoddmuse-post-file
(find-library-name candidate)
"EmacsWiki"
(file-name-nondirectory
(find-library-name candidate))))))))
"Needs yaoddmuse.el.
http://www.emacswiki.org/emacs/download/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)))))
actions))
;;;###autoload
(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'."
(interactive)
(declare (special yaoddmuse-pages-hash))
(yaoddmuse-update-pagename)
(save-excursion
(find-file helm-c-yaoddmuse-cache-file)
(erase-buffer)
(insert "(puthash \"EmacsWiki\" '(")
(loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
do
(insert (concat "(\"" (car i) "\") ")))
(insert ") yaoddmuse-pages-hash)\n")
(save-buffer)
(kill-buffer (current-buffer))
(when (or current-prefix-arg
load)
(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)))))
;;;###autoload
(defun helm-yaoddmuse-emacswiki-edit-or-view ()
"Preconfigured `helm' to edit or view EmacsWiki page.
Needs yaoddmuse.el.
http://www.emacswiki.org/emacs/download/yaoddmuse.el"
(interactive)
(helm :sources 'helm-c-source-yaoddmuse-emacswiki-edit-or-view))
;;;###autoload
(defun helm-yaoddmuse-emacswiki-post-library ()
"Preconfigured `helm' to post library to EmacsWiki.
Needs yaoddmuse.el.
http://www.emacswiki.org/emacs/download/yaoddmuse.el"
(interactive)
(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.