aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/cedet/srecode
diff options
context:
space:
mode:
authorStefan Monnier2023-11-06 19:05:40 -0500
committerStefan Monnier2023-11-09 00:33:52 -0500
commit8323394bc801e01dedd95e0ff8d573dd1f5e34ba (patch)
treea895207eafd180e6c9b7ff056e04b74ff1ab495d /lisp/cedet/srecode
parent5afa55a946a0271c624359e9de5d62bcaf39729b (diff)
downloademacs-8323394bc801e01dedd95e0ff8d573dd1f5e34ba.tar.gz
emacs-8323394bc801e01dedd95e0ff8d573dd1f5e34ba.zip
Use `derived-mode-add-parents` in remaining uses of `derived-mode-parent`
Until now multiple inheritance wasn't really used, but some ad-hoc code went a bit beyond the normal uses of the mode hierarchy. Use the new multiple inheritance code to replace that ad-hoc code, thereby eliminating basically all remaining direct uses of the `derived-mode-parent` property. CEDET had its own notion of mode hierrchy using `derived-mode-parent` as well as its own `mode-local-parent` property set via `define-child-mode`. `derived-mode-add-parents` lets us reimplement `define-child-mode` such that CEDET can now use the normal API functions. * lisp/locate.el (locate-mode): Use `derived-mode-add-parents`. * lisp/cedet/mode-local.el (get-mode-local-parent): Declare obsolete. (mode-local-equivalent-mode-p, mode-local-use-bindings-p): Make them obsolete aliases. (mode-local--set-parent): Rewrite to use `derived-mode-add-parents`. Declare as obsolete. (mode-local-map-mode-buffers): Use `derived-mode-p`. (mode-local-symbol, mode-local--activate-bindings) (mode-local--deactivate-bindings, mode-local-describe-bindings-2): Use `derived-mode-all-parents`. * lisp/cedet/srecode/table.el (srecode-get-mode-table): * lisp/cedet/srecode/find.el (srecode-table, srecode-load-tables-for-mode) (srecode-all-template-hash): Use `derived-mode-all-parents`. * lisp/cedet/srecode/map.el (srecode-map-entries-for-mode): * lisp/cedet/semantic/db.el (semanticdb-equivalent-mode): Use `provided-mode-derived-p` now that it obeys `define-child-mode`.
Diffstat (limited to 'lisp/cedet/srecode')
-rw-r--r--lisp/cedet/srecode/find.el64
-rw-r--r--lisp/cedet/srecode/map.el2
-rw-r--r--lisp/cedet/srecode/table.el51
3 files changed, 50 insertions, 67 deletions
diff --git a/lisp/cedet/srecode/find.el b/lisp/cedet/srecode/find.el
index cfd64edfc98..6d64a26e46c 100644
--- a/lisp/cedet/srecode/find.el
+++ b/lisp/cedet/srecode/find.el
@@ -34,12 +34,12 @@
34(defun srecode-table (&optional mode) 34(defun srecode-table (&optional mode)
35 "Return the currently active Semantic Recoder table for this buffer. 35 "Return the currently active Semantic Recoder table for this buffer.
36Optional argument MODE specifies the mode table to use." 36Optional argument MODE specifies the mode table to use."
37 (let* ((modeq (or mode major-mode)) 37 (let ((modes (derived-mode-all-parents (or mode major-mode)))
38 (table (srecode-get-mode-table modeq))) 38 (table nil))
39 39
40 ;; If there isn't one, keep searching backwards for a table. 40 ;; If there isn't one, keep searching backwards for a table.
41 (while (and (not table) (setq modeq (get-mode-local-parent modeq))) 41 (while (and modes (not (setq table (srecode-get-mode-table (car modes)))))
42 (setq table (srecode-get-mode-table modeq))) 42 (setq modes (cdr modes)))
43 43
44 ;; Last ditch effort. 44 ;; Last ditch effort.
45 (when (not table) 45 (when (not table)
@@ -57,35 +57,23 @@ Templates are found in the SRecode Template Map.
57See `srecode-get-maps' for more. 57See `srecode-get-maps' for more.
58APPNAME is the name of an application. In this case, 58APPNAME is the name of an application. In this case,
59all template files for that application will be loaded." 59all template files for that application will be loaded."
60 (let ((files 60 (dolist (mmode (cons 'default (reverse (derived-mode-all-parents mmode))))
61 (apply #'append 61 (let ((files
62 (mapcar 62 (apply #'append
63 (if appname 63 (mapcar
64 (if appname
65 (lambda (map)
66 (srecode-map-entries-for-app-and-mode map appname mmode))
64 (lambda (map) 67 (lambda (map)
65 (srecode-map-entries-for-app-and-mode map appname mmode)) 68 (srecode-map-entries-for-mode map mmode)))
66 (lambda (map) 69 (srecode-get-maps)))))
67 (srecode-map-entries-for-mode map mmode)))
68 (srecode-get-maps))))
69 )
70 ;; Don't recurse if we are already the 'default state.
71 (when (not (eq mmode 'default))
72 ;; Are we a derived mode? If so, get the parent mode's
73 ;; templates loaded too.
74 (if (get-mode-local-parent mmode)
75 (srecode-load-tables-for-mode (get-mode-local-parent mmode)
76 appname)
77 ;; No parent mode, all templates depend on the defaults being
78 ;; loaded in, so get that in instead.
79 (srecode-load-tables-for-mode 'default appname)))
80 70
81 ;; Load in templates for our major mode. 71 ;; Load in templates for our major mode.
82 (dolist (f files) 72 (when files
83 (let ((mt (srecode-get-mode-table mmode)) 73 (let ((mt (srecode-get-mode-table mmode)))
84 ) 74 (dolist (f files)
85 (when (or (not mt) (not (srecode-mode-table-find mt (car f)))) 75 (when (not (and mt (srecode-mode-table-find mt (car f))))
86 (srecode-compile-file (car f))) 76 (srecode-compile-file (car f)))))))))
87 ))
88 ))
89 77
90;;; PROJECT 78;;; PROJECT
91;; 79;;
@@ -227,12 +215,12 @@ Optional argument MODE is the major mode to look for.
227Optional argument HASH is the hash table to fill in. 215Optional argument HASH is the hash table to fill in.
228Optional argument PREDICATE can be used to filter the returned 216Optional argument PREDICATE can be used to filter the returned
229templates." 217templates."
230 (let* ((mhash (or hash (make-hash-table :test 'equal))) 218 (let* ((mhash (or hash (make-hash-table :test 'equal))))
231 (mmode (or mode major-mode)) 219 (dolist (mmode (cons 'default
232 (parent-mode (get-mode-local-parent mmode))) 220 ;; Get the parent hash table filled into our
233 ;; Get the parent hash table filled into our current hash. 221 ;; current hash.
234 (unless (eq mode 'default) 222 (reverse (derived-mode-all-parents
235 (srecode-all-template-hash (or parent-mode 'default) mhash)) 223 (or mode major-mode)))))
236 224
237 ;; Load up the hash table for our current mode. 225 ;; Load up the hash table for our current mode.
238 (let* ((mt (srecode-get-mode-table mmode)) 226 (let* ((mt (srecode-get-mode-table mmode))
@@ -246,7 +234,7 @@ templates."
246 (funcall predicate temp)) 234 (funcall predicate temp))
247 (puthash key temp mhash))) 235 (puthash key temp mhash)))
248 (oref tab namehash)))) 236 (oref tab namehash))))
249 mhash))) 237 mhash))))
250 238
251(defun srecode-calculate-default-template-string (hash) 239(defun srecode-calculate-default-template-string (hash)
252 "Calculate the name of the template to use as a DEFAULT. 240 "Calculate the name of the template to use as a DEFAULT.
diff --git a/lisp/cedet/srecode/map.el b/lisp/cedet/srecode/map.el
index 004bb7adddb..44e465c69b1 100644
--- a/lisp/cedet/srecode/map.el
+++ b/lisp/cedet/srecode/map.el
@@ -76,7 +76,7 @@ Each app keys to an alist of files and modes (as above.)")
76 "Return the entries in MAP for major MODE." 76 "Return the entries in MAP for major MODE."
77 (let ((ans nil)) 77 (let ((ans nil))
78 (dolist (f (oref map files)) 78 (dolist (f (oref map files))
79 (when (mode-local-use-bindings-p mode (cdr f)) 79 (when (provided-mode-derived-p mode (cdr f))
80 (setq ans (cons f ans)))) 80 (setq ans (cons f ans))))
81 ans)) 81 ans))
82 82
diff --git a/lisp/cedet/srecode/table.el b/lisp/cedet/srecode/table.el
index de151049f7f..e5ab53dd253 100644
--- a/lisp/cedet/srecode/table.el
+++ b/lisp/cedet/srecode/table.el
@@ -137,41 +137,36 @@ Tracks all the template-tables for a specific major mode.")
137 "Get the SRecoder mode table for the major mode MODE. 137 "Get the SRecoder mode table for the major mode MODE.
138This will find the mode table specific to MODE, and then 138This will find the mode table specific to MODE, and then
139calculate all inherited templates from parent modes." 139calculate all inherited templates from parent modes."
140 (let ((table nil) 140 (let ((table nil))
141 (tmptable nil)) 141 (dolist (mode (derived-mode-all-parents mode))
142 (while mode 142 (let ((tmptable (eieio-instance-tracker-find
143 (setq tmptable (eieio-instance-tracker-find 143 mode 'major-mode 'srecode-mode-table-list)))
144 mode 'major-mode 'srecode-mode-table-list) 144 (when tmptable
145 mode (get-mode-local-parent mode)) 145 (if (not table)
146 (when tmptable 146 (progn
147 (if (not table) 147 ;; If this is the first, update tables to have
148 (progn 148 ;; all the mode specific tables in it.
149 ;; If this is the first, update tables to have 149 (setq table tmptable)
150 ;; all the mode specific tables in it. 150 (oset table tables (oref table modetables)))
151 (setq table tmptable) 151 ;; If there already is a table, then reset the tables
152 (oset table tables (oref table modetables))) 152 ;; slot to include all the tables belonging to this new child node.
153 ;; If there already is a table, then reset the tables 153 (oset table tables (append (oref table modetables)
154 ;; slot to include all the tables belonging to this new child node. 154 (oref tmptable modetables)))))
155 (oset table tables (append (oref table modetables) 155 ))
156 (oref tmptable modetables)))))
157 )
158 table)) 156 table))
159 157
160(defun srecode-make-mode-table (mode) 158(defun srecode-make-mode-table (mode)
161 "Get the SRecoder mode table for the major mode MODE." 159 "Get the SRecoder mode table for the major mode MODE."
162 (let ((old (eieio-instance-tracker-find 160 (let ((old (eieio-instance-tracker-find
163 mode 'major-mode 'srecode-mode-table-list))) 161 mode 'major-mode 'srecode-mode-table-list)))
164 (if old 162 (or old
165 old 163 (let* ((new (srecode-mode-table :major-mode mode
166 (let* ((ms (if (stringp mode) mode (symbol-name mode))) 164 :modetables nil
167 (new (srecode-mode-table ms 165 :tables nil)))
168 :major-mode mode 166 ;; Save this new mode table in that mode's variable.
169 :modetables nil 167 (eval `(setq-mode-local ,mode srecode-table ,new) t)
170 :tables nil)))
171 ;; Save this new mode table in that mode's variable.
172 (eval `(setq-mode-local ,mode srecode-table ,new) t)
173 168
174 new)))) 169 new))))
175 170
176(cl-defmethod srecode-mode-table-find ((mt srecode-mode-table) file) 171(cl-defmethod srecode-mode-table-find ((mt srecode-mode-table) file)
177 "Look in the mode table MT for a template table from FILE. 172 "Look in the mode table MT for a template table from FILE.