[137488] users/chunyang/helm-ls-svn.el/helm-ls-svn.el

chunyang at macports.org chunyang at macports.org
Fri Jun 12 10:40:33 PDT 2015


Revision: 137488
          https://trac.macports.org/changeset/137488
Author:   chunyang at macports.org
Date:     2015-06-12 10:40:33 -0700 (Fri, 12 Jun 2015)
Log Message:
-----------
users/chunyang: helm-ls-svn.el: Create helm-ls-svn-source class

Modified Paths:
--------------
    users/chunyang/helm-ls-svn.el/helm-ls-svn.el

Modified: users/chunyang/helm-ls-svn.el/helm-ls-svn.el
===================================================================
--- users/chunyang/helm-ls-svn.el/helm-ls-svn.el	2015-06-12 17:31:49 UTC (rev 137487)
+++ users/chunyang/helm-ls-svn.el/helm-ls-svn.el	2015-06-12 17:40:33 UTC (rev 137488)
@@ -32,7 +32,6 @@
 ;; TODO
 ;; ====
 ;;
-;; - Create my own class inheriting from one of helm main classes
 ;; - Create svn status source
 
 
@@ -40,6 +39,11 @@
 
 (require 'helm-files)
 
+;; Define the sources.
+(defvar helm-source-ls-svn nil)
+(defvar helm-source-ls-svn-buffers nil)
+
+
 (defgroup helm-ls-svn nil
   "Helm completion for svn repos."
   :group 'helm)
@@ -59,14 +63,28 @@
   (shell-command-to-string
    "svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$' | tr -d '\n'"))
 
-(defvar helm-source-ls-svn-buffers nil)
-
 (defun helm-ls-svn-header-name (name)
   (let ((branch (helm-ls-svn-branch)))
     (format "%s (%s)"
             name (if (string-empty-p branch)
                      (helm-ls-svn-root-dir) branch))))
 
+(defun helm-ls-svn-init ()
+  (let ((root (helm-ls-svn-root-dir)))
+    (with-current-buffer (helm-candidate-buffer 'global)
+      (call-process-shell-command
+       (format "find %s -type f -not -iwholename '*.svn/*'"
+               root)
+       nil t ))))
+
+(defclass helm-ls-svn-source (helm-source-in-buffer)
+  ((header-name :initform 'helm-ls-svn-header-name)
+   (init :initform 'helm-ls-svn-init)
+   (keymap :initform helm-ls-svn-map)
+   (help-message :initform helm-generic-file-help-message)
+   (candidate-number-limit :initform 9999)
+   (action :initform (helm-actions-from-type-file))))
+
 ;;;###autoload
 (defun helm-ls-svn-ls ()
   (interactive)
@@ -78,23 +96,11 @@
             :header-name #'helm-ls-svn-header-name
             :buffer-list (lambda () (helm-browse-project-get-buffers
                                      (helm-ls-svn-root-dir))))))
-  (helm :sources
-        (list
-         helm-source-ls-svn-buffers
-         (helm-build-in-buffer-source "SVN files"
-           :header-name #'helm-ls-svn-header-name
-           :init
-           (lambda ()
-             (let ((root (helm-ls-svn-root-dir)))
-               (with-current-buffer (helm-candidate-buffer 'global)
-                 (call-process-shell-command
-                  (format "find %s -type f -not -iwholename '*.svn/*'"
-                          root)
-                  nil t ))))
-           :help-message helm-generic-file-help-message
-           :keymap helm-ls-svn-map
-           :candidate-number-limit 9999
-           :action (helm-actions-from-type-file)))
+  (unless helm-source-ls-svn
+    (setq helm-source-ls-svn
+          (helm-make-source "SVN files" 'helm-ls-svn-source)))
+  (helm :sources '(helm-source-ls-svn-buffers
+                   helm-source-ls-svn)
         :buffer "*helm ls svn*"))
 
 (provide 'helm-ls-svn)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150612/4877c999/attachment.html>


More information about the macports-changes mailing list