]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/srecode/find.el
Update copyright year to 2016
[gnu-emacs] / lisp / cedet / srecode / find.el
index befdb4731c226f4b5770f4fe0d207d717e8f93b0..4c0b506a2319b24588028710826083935ff81277 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; srecode/find.el --- Tools for finding templates in the database.
 
-;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2016 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
 
@@ -96,7 +96,7 @@ all template files for that application will be loaded."
 ;;
 ;; Find if a template table has a project set, and if so, is the
 ;; current buffer in that project.
-(defmethod srecode-template-table-in-project-p ((tab srecode-template-table))
+(cl-defmethod srecode-template-table-in-project-p ((tab srecode-template-table))
   "Return non-nil if the table TAB can be used in the current project.
 If TAB has a :project set, check that the directories match.
 If TAB is nil, then always return t."
@@ -113,7 +113,7 @@ If TAB is nil, then always return t."
 ;;
 ;; Find a given template based on name, and features of the current
 ;; buffer.
-(defmethod srecode-template-get-table ((tab srecode-template-table)
+(cl-defmethod srecode-template-get-table ((tab srecode-template-table)
                                       template-name &optional
                                       context application)
   "Find in the template in table TAB, the template with TEMPLATE-NAME.
@@ -129,7 +129,7 @@ The APPLICATION argument is unused."
       ;; No context, perhaps a merged name?
       (gethash template-name (oref tab namehash)))))
 
-(defmethod srecode-template-get-table ((tab srecode-mode-table)
+(cl-defmethod srecode-template-get-table ((tab srecode-mode-table)
                                       template-name &optional
                                       context application)
   "Find in the template in mode table TAB, the template with TEMPLATE-NAME.
@@ -157,7 +157,7 @@ tables that do not belong to an application will be searched."
 ;;
 ;; Find a given template based on a key binding.
 ;;
-(defmethod srecode-template-get-table-for-binding
+(cl-defmethod srecode-template-get-table-for-binding
   ((tab srecode-template-table) binding &optional context)
   "Find in the template name in table TAB, the template with BINDING.
 Optional argument CONTEXT specifies that the template should part
@@ -190,7 +190,7 @@ of a particular context."
        (maphash hashfcn (oref tab namehash)))
       keyout)))
 
-(defmethod srecode-template-get-table-for-binding
+(cl-defmethod srecode-template-get-table-for-binding
   ((tab srecode-mode-table) binding &optional context application)
   "Find in the template name in mode table TAB, the template with BINDING.
 Optional argument CONTEXT specifies a context a particular template
@@ -220,32 +220,37 @@ tables that do not belong to an application will be searched."
 (defvar srecode-read-template-name-history nil
   "History for completing reads for template names.")
 
-(defun srecode-all-template-hash (&optional mode hash)
+(defun srecode-user-template-p (template)
+  "Non-nil if TEMPLATE is intended for user insertion.
+Templates not matching this predicate are used for code
+generation or other internal purposes."
+  t)
+
+(defun srecode-all-template-hash (&optional mode hash predicate)
   "Create a hash table of all the currently available templates.
 Optional argument MODE is the major mode to look for.
-Optional argument HASH is the hash table to fill in."
-  (let* ((mhash (or hash (make-hash-table :test 'equal)))
-        (mmode (or mode major-mode))
-        (mp (get-mode-local-parent mmode))
-        )
+Optional argument HASH is the hash table to fill in.
+Optional argument PREDICATE can be used to filter the returned
+templates."
+  (let* ((mhash       (or hash (make-hash-table :test 'equal)))
+        (mmode       (or mode major-mode))
+        (parent-mode (get-mode-local-parent mmode)))
     ;; Get the parent hash table filled into our current hash.
-    (when (not (eq mode 'default))
-      (if mp
-         (srecode-all-template-hash mp mhash)
-       (srecode-all-template-hash 'default mhash)))
+    (unless (eq mode 'default)
+      (srecode-all-template-hash (or parent-mode 'default) mhash))
+
     ;; Load up the hash table for our current mode.
-    (let* ((mt (srecode-get-mode-table mmode))
-          (tabs (when mt (oref mt :tables)))
-          )
-      (while tabs
+    (let* ((mt   (srecode-get-mode-table mmode))
+          (tabs (when mt (oref mt :tables))))
+      (dolist (tab tabs)
        ;; Exclude templates for a particular application.
-       (when (and (not (oref (car tabs) :application))
-                  (srecode-template-table-in-project-p (car tabs)))
+       (when (and (not (oref tab :application))
+                  (srecode-template-table-in-project-p tab))
          (maphash (lambda (key temp)
-                    (puthash key temp mhash)
-                    )
-                  (oref (car tabs) namehash)))
-       (setq tabs (cdr tabs)))
+                    (when (or (not predicate)
+                              (funcall predicate temp))
+                      (puthash key temp mhash)))
+                  (oref tab namehash))))
       mhash)))
 
 (defun srecode-calculate-default-template-string (hash)