emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/last-cedet-merge b4d1399 14/37: EDE: Rework config


From: David Engster
Subject: [Emacs-diffs] scratch/last-cedet-merge b4d1399 14/37: EDE: Rework config file detection
Date: Sun, 22 Jan 2017 21:26:32 +0000 (UTC)

branch: scratch/last-cedet-merge
commit b4d1399dc6a3f5493ce62b5231a065ba82d1012b
Author: Eric Ludlam <address@hidden>
Commit: David Engster <address@hidden>

    EDE: Rework config file detection
    
    * lisp/cedet/ede/auto.el (ede-calc-fromconfig): New.
      (ede-dirmatch-installed, ede-do-dirmatch): Use above to find config
      file.
---
 lisp/cedet/ede/auto.el |  111 +++++++++++++++++++++---------------------------
 1 file changed, 49 insertions(+), 62 deletions(-)

diff --git a/lisp/cedet/ede/auto.el b/lisp/cedet/ede/auto.el
index 6c0e588..a77de92 100644
--- a/lisp/cedet/ede/auto.el
+++ b/lisp/cedet/ede/auto.el
@@ -63,74 +63,61 @@ location is varied dependent on other complex criteria, 
this class
 can be used to define that match without loading the specific project
 into memory.")
 
-(cl-defmethod ede-dirmatch-installed ((dirmatch ede-project-autoload-dirmatch))
-  "Return non-nil if the tool DIRMATCH might match is installed on the system."
+(cl-defmethod ede-calc-fromconfig ((dirmatch ede-project-autoload-dirmatch))
+  "Calculate the value of :fromconfig from DIRMATCH."
   (let ((fc (oref dirmatch fromconfig)))
+    (cond ((stringp fc) fc)
+         ((functionp fc) (funcall fc))
+         (t (error "Unknown dirmatch object match style.")))
+    ))
 
-    (cond
-     ;; If the thing to match is stored in a config file.
-     ((stringp fc)
-      (file-exists-p fc))
-
-     ;; Add new types of dirmatches here.
-
-     ;; Error for weird stuff
-     (t (error "Unknown dirmatch type.")))))
 
+(cl-defmethod ede-dirmatch-installed ((dirmatch ede-project-autoload-dirmatch))
+  "Return non-nil if the tool DIRMATCH might match is installed on the system."
+  (file-exists-p (ede-calc-fromconfig dirmatch)))
 
 (cl-defmethod ede-do-dirmatch ((dirmatch ede-project-autoload-dirmatch) file)
   "Does DIRMATCH match the filename FILE."
-  (let ((fc (oref dirmatch fromconfig)))
-
-    (cond
-     ;; If the thing to match is stored in a config file.
-     ((stringp fc)
-      (when (file-exists-p fc)
-       (let ((matchstring
-              (if (slot-boundp dirmatch 'configdatastash)
-                  (oref dirmatch configdatastash)
-                nil)))
-         (when (and (not matchstring) (not (slot-boundp dirmatch 
'configdatastash)))
-           (save-current-buffer
-             (let* ((buff (get-file-buffer fc))
-                    (readbuff
-                     (let ((find-file-hook nil)) ;; Disable ede from recursing
-                       (find-file-noselect fc))))
-               (set-buffer readbuff)
-               (save-excursion
-                 (goto-char (point-min))
-                 (when (re-search-forward (oref dirmatch configregex) nil t)
-                   (setq matchstring
-                         (match-string (or (oref dirmatch configregexidx) 
0)))))
-               (if (not buff) (kill-buffer readbuff))))
-           (when matchstring
-             ;; If this dirmatch only finds subdirs of matchstring, then
-             ;; force matchstring to be a directory.
-             (when (oref dirmatch subdir-only)
-               (setq matchstring (file-name-as-directory matchstring)))
-             ;; Convert matchstring to a regexp
-             (setq matchstring (concat "^" (regexp-quote matchstring)))
-             ;; Stash it for later.
-             (oset dirmatch configdatastash matchstring))
-           ;; Debug
-           ;;(message "Stashing config data for dirmatch %S as %S" 
(eieio-object-name dirmatch) matchstring)
-           )
-         ;;(message "dirmatch %s against %s" matchstring (expand-file-name 
file))
-         ;; Match against our discovered string
-         (setq file (file-name-as-directory (expand-file-name file)))
-         (and matchstring (string-match matchstring (expand-file-name file))
-              (or (not (oref dirmatch subdir-only))
-                  (not (= (match-end 0) (length file))))
-              )
-         )))
-
-     ;; Add new matches here
-     ;; ((stringp somenewslot ...)
-     ;;   )
-
-     ;; Error if none others known
-     (t
-      (error "Unknown dirmatch object match style.")))
+  (let ((fc (ede-calc-fromconfig dirmatch)))
+
+    (when (file-exists-p fc)
+      (let ((matchstring
+            (if (slot-boundp dirmatch 'configdatastash)
+                (oref dirmatch configdatastash)
+              nil)))
+       (when (and (not matchstring) (not (slot-boundp dirmatch 
'configdatastash)))
+         (save-current-buffer
+           (let* ((buff (get-file-buffer fc))
+                  (readbuff
+                   (let ((find-file-hook nil)) ;; Disable ede from recursing
+                     (find-file-noselect fc))))
+             (set-buffer readbuff)
+             (save-excursion
+               (goto-char (point-min))
+               (when (re-search-forward (oref dirmatch configregex) nil t)
+                 (setq matchstring
+                       (match-string (or (oref dirmatch configregexidx) 0)))))
+             (if (not buff) (kill-buffer readbuff))))
+         (when matchstring
+           ;; If this dirmatch only finds subdirs of matchstring, then
+           ;; force matchstring to be a directory.
+           (when (oref dirmatch subdir-only)
+             (setq matchstring (file-name-as-directory matchstring)))
+           ;; Convert matchstring to a regexp
+           (setq matchstring (concat "^" (regexp-quote matchstring)))
+           ;; Stash it for later.
+           (oset dirmatch configdatastash matchstring))
+         ;; Debug
+         ;;(message "Stashing config data for dirmatch %S as %S" 
(eieio-object-name dirmatch) matchstring)
+         )
+       ;;(message "dirmatch %s against %s" matchstring (expand-file-name file))
+       ;; Match against our discovered string
+       (setq file (file-name-as-directory (expand-file-name file)))
+       (and matchstring (string-match matchstring (expand-file-name file))
+            (or (not (oref dirmatch subdir-only))
+                (not (= (match-end 0) (length file))))
+            )
+       ))
     ))
 
 (declare-function ede-directory-safe-p "ede")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]