aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDavid Engster2013-06-02 15:33:09 +0200
committerDavid Engster2013-06-02 15:33:09 +0200
commit890f78904a8eb787cf1559c6e9ddac395b49a09e (patch)
treed009118a8ca081486f3cafa892918f79f0753375 /lisp
parent336d7284648810ce48a88d22515809f84415b5c1 (diff)
downloademacs-890f78904a8eb787cf1559c6e9ddac395b49a09e.tar.gz
emacs-890f78904a8eb787cf1559c6e9ddac395b49a09e.zip
Merge from CEDET upstream (8564).
* lisp/emacs-lisp: * emacs-lisp/eieio.el (eieio--defalias, eieio-hook) (eieio-error-unsupported-class-tags, eieio-skip-typecheck) (eieio-optimize-primary-methods-flag, eieio-initializing-object) (eieio-unbound, eieio-default-superclass) (eieio--define-field-accessors, method-static, method-before) (method-primary, method-after, method-num-lists) (method-generic-before, method-generic-primary) (method-generic-after, method-num-slots) (eieio-specialized-key-to-generic-key) (eieio--check-type, class-v, class-p) (eieio-class-name, define-obsolete-function-alias) (eieio-class-parents-fast, eieio-class-children-fast) (same-class-fast-p, class-constructor, generic-p) (generic-primary-only-p, generic-primary-only-one-p) (class-option-assoc, class-option, eieio-object-p) (class-abstract-p, class-method-invocation-order) (eieio-defclass-autoload-map, eieio-defclass-autoload) (eieio-class-un-autoload, eieio-defclass) (eieio-eval-default-p, eieio-perform-slot-validation-for-default) (eieio-add-new-slot, eieio-copy-parents-into-subclass) (eieio--defgeneric-init-form, eieio-defgeneric-form) (eieio-defgeneric-reset-generic-form) (eieio-defgeneric-form-primary-only) (eieio-defgeneric-reset-generic-form-primary-only) (eieio-defgeneric-form-primary-only-one) (eieio-defgeneric-reset-generic-form-primary-only-one) (eieio-unbind-method-implementations) (eieio--defmethod, eieio--typep) (eieio-perform-slot-validation, eieio-validate-slot-value) (eieio-validate-class-slot-value, eieio-barf-if-slot-unbound) (eieio-oref, eieio-oref-default, eieio-default-eval-maybe) (eieio-oset, eieio-oset-default, eieio-slot-originating-class-p) (eieio-slot-name-index, eieio-class-slot-name-index) (eieio-set-defaults, eieio-initarg-to-attribute) (eieio-attribute-to-initarg, eieio-c3-candidate) (eieio-c3-merge-lists, eieio-class-precedence-c3) (eieio-class-precedence-dfs, eieio-class-precedence-bfs) (eieio-class-precedence-list, eieio-generic-call-methodname) (eieio-generic-call-arglst, eieio-generic-call-key) (eieio-generic-call-next-method-list) (eieio-pre-method-execution-functions, eieio-generic-call) (eieio-generic-call-primary-only, eieiomt-method-list) (eieiomt-optimizing-obarray, eieiomt-install) (eieiomt-add, eieiomt-next, eieiomt-sym-optimize) (eieio-generic-form, eieio-defmethod, make-obsolete) (eieio-defgeneric, make-obsolete): Moved to eieio-core.el (defclass): Remove `eval-and-compile' from macro. (call-next-method, shared-initialize): Instead of using `scoped-class' variable, use new eieio--scoped-class, and eieio--with-scoped-class. (initialize-instance): Rename local variable 'scoped-class' to 'this-class' to remove ambiguitity from old global. * emacs-lisp/eieio-core.el: New file. Derived from key parts of eieio.el. (eieio--scoped-class-stack): New variable (eieio--scoped-class): New fcn (eieio--with-scoped-class): New scoping macro. (eieio-defclass): Use pushnew instead of add-to-list. (eieio-defgeneric-form-primary-only-one, eieio-oset-default) (eieio-slot-name-index, eieio-set-defaults, eieio-generic-call) (eieio-generic-call-primary-only, eieiomt-add): Instead of using `scoped-class' variable, use new eieio--scoped-class, and eieio--with-scoped-class. * emacs-lisp/eieio-base.el (cl-lib): Require during compile. * admin/grammars: * grammars/srecode-template.wy (variable): Accept a single number as a variable value. Allows the 'priority' to be set to a number. (wisent-srecode-template-lexer): Move number up so it can be created. * etc/srecode: * srecode/c.srt (header_guard): Add :c parameter so it works standalone * lisp/cedet: * semantic/edit.el (semantic-change-function): Use `save-match-data' around running hooks. * semantic/decorate/mode.el (semantic-decorate-style-predicate-default) (semantic-decorate-style-highlighter-default): New. (semantic-decoration-mode): Do not require `semantic/decorate/include' anymore. (semantic-toggle-decoration-style): Error if an unknown decoration style is toggled. (define-semantic-decoration-style): Add new :load option. When :load is specified, add autoload tokens for the definition functions so that code is loaded when the mode is used. (semantic-decoration-on-includes): New autoload definition for highlighting includes. * semantic/bovine/c.el (semantic-lex-c-ifdef): Allow some misc characters to appear after the tested variable. * semantic/ede-grammar.el (project-compile-target): Calculate full src name via ede-expand-filename instead of the crutch of the current buffer. Enables this target to compile in batch mode. * semantic/idle.el (semantic-idle-symbol-maybe-highlight): Wrap highlighting of remote symbol with `save-excursion'. (semantic-idle-scheduler-work-parse-neighboring-files): Instead of using directory-files on each found mode pattern, collect all the patterns for the current mode, and then for each file, see if it matches any of them. If it does, parse the file. (Patch inspiration from Tomasz Gajewski.) * semantic/ctxt.el (semantic-ctxt-end-of-symbol): New. (semantic-ctxt-current-symbol-default): New. * semantic/bovine/el.el (semantic-default-elisp-setup): Add autoload cookie. Explain existence. (footer): Add local variable for loaddefs. * semantic/db.el (semanticdb-file-table-object): Add new filter, only checking for regular files too. * semantic/wisent/python.el (semantic-format-tag-abbreviate): New override. Cuts back on size of code tags. * srecode/compile.el (srecode-compile-templates): Fix warning punctuation. Remove status messages to clean up testing output * ede/base.el (ede-project-placeholder-cache-file): Update doc to mention 'nil' value. (ede-save-cache): Disable cache save if file is nil. * ede.el (ede-initialize-state-current-buffer): Flush deleted projects. (global-ede-mode): Always append our find-file-hook to the end. (ede-flush-deleted-projects): New command. * ede/cpp-root.el (ede-preprocessor-map): Protect against init problems. * ede/proj.el (ede-proj-target): Added a new "custom" option for custom symbols representing a compiler or linker instead of restricting things to only the predefined compilers and linkers. * semantic.el (semantic-mode-map): To avoid showing showing Development menu twice, only disable menu item if menu-bar is actually enabled, otherwise the popup 'global menu' might display a disabled Development menu. * semantic/complete.el (semantic-displayor-show-request): Fix which slot in obj is set to the max tags.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog69
-rw-r--r--lisp/cedet/ChangeLog80
-rw-r--r--lisp/cedet/ede.el21
-rw-r--r--lisp/cedet/ede/base.el66
-rw-r--r--lisp/cedet/ede/cpp-root.el5
-rw-r--r--lisp/cedet/ede/proj.el2
-rw-r--r--lisp/cedet/semantic.el3
-rw-r--r--lisp/cedet/semantic/bovine/c.el2
-rw-r--r--lisp/cedet/semantic/bovine/el.el9
-rw-r--r--lisp/cedet/semantic/complete.el2
-rw-r--r--lisp/cedet/semantic/ctxt.el83
-rw-r--r--lisp/cedet/semantic/db.el2
-rw-r--r--lisp/cedet/semantic/decorate/mode.el44
-rw-r--r--lisp/cedet/semantic/ede-grammar.el2
-rw-r--r--lisp/cedet/semantic/edit.el5
-rw-r--r--lisp/cedet/semantic/idle.el54
-rw-r--r--lisp/cedet/semantic/wisent/python.el14
-rw-r--r--lisp/cedet/srecode/compile.el28
-rw-r--r--lisp/emacs-lisp/eieio-base.el1
-rw-r--r--lisp/emacs-lisp/eieio-core.el2264
-rw-r--r--lisp/emacs-lisp/eieio.el2234
21 files changed, 2706 insertions, 2284 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9f9302680be..4d44a291483 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,72 @@
12013-06-02 Eric Ludlam <zappo@gnu.org>
2
3 * emacs-lisp/eieio.el (eieio--defalias, eieio-hook)
4 (eieio-error-unsupported-class-tags, eieio-skip-typecheck)
5 (eieio-optimize-primary-methods-flag, eieio-initializing-object)
6 (eieio-unbound, eieio-default-superclass)
7 (eieio--define-field-accessors, method-static, method-before)
8 (method-primary, method-after, method-num-lists)
9 (method-generic-before, method-generic-primary)
10 (method-generic-after, method-num-slots)
11 (eieio-specialized-key-to-generic-key)
12 (eieio--check-type, class-v, class-p)
13 (eieio-class-name, define-obsolete-function-alias)
14 (eieio-class-parents-fast, eieio-class-children-fast)
15 (same-class-fast-p, class-constructor, generic-p)
16 (generic-primary-only-p, generic-primary-only-one-p)
17 (class-option-assoc, class-option, eieio-object-p)
18 (class-abstract-p, class-method-invocation-order)
19 (eieio-defclass-autoload-map, eieio-defclass-autoload)
20 (eieio-class-un-autoload, eieio-defclass)
21 (eieio-eval-default-p, eieio-perform-slot-validation-for-default)
22 (eieio-add-new-slot, eieio-copy-parents-into-subclass)
23 (eieio--defgeneric-init-form, eieio-defgeneric-form)
24 (eieio-defgeneric-reset-generic-form)
25 (eieio-defgeneric-form-primary-only)
26 (eieio-defgeneric-reset-generic-form-primary-only)
27 (eieio-defgeneric-form-primary-only-one)
28 (eieio-defgeneric-reset-generic-form-primary-only-one)
29 (eieio-unbind-method-implementations)
30 (eieio--defmethod, eieio--typep)
31 (eieio-perform-slot-validation, eieio-validate-slot-value)
32 (eieio-validate-class-slot-value, eieio-barf-if-slot-unbound)
33 (eieio-oref, eieio-oref-default, eieio-default-eval-maybe)
34 (eieio-oset, eieio-oset-default, eieio-slot-originating-class-p)
35 (eieio-slot-name-index, eieio-class-slot-name-index)
36 (eieio-set-defaults, eieio-initarg-to-attribute)
37 (eieio-attribute-to-initarg, eieio-c3-candidate)
38 (eieio-c3-merge-lists, eieio-class-precedence-c3)
39 (eieio-class-precedence-dfs, eieio-class-precedence-bfs)
40 (eieio-class-precedence-list, eieio-generic-call-methodname)
41 (eieio-generic-call-arglst, eieio-generic-call-key)
42 (eieio-generic-call-next-method-list)
43 (eieio-pre-method-execution-functions, eieio-generic-call)
44 (eieio-generic-call-primary-only, eieiomt-method-list)
45 (eieiomt-optimizing-obarray, eieiomt-install)
46 (eieiomt-add, eieiomt-next, eieiomt-sym-optimize)
47 (eieio-generic-form, eieio-defmethod, make-obsolete)
48 (eieio-defgeneric, make-obsolete): Moved to eieio-core.el
49 (defclass): Remove `eval-and-compile' from macro.
50 (call-next-method, shared-initialize): Instead of using
51 `scoped-class' variable, use new eieio--scoped-class, and
52 eieio--with-scoped-class.
53 (initialize-instance): Rename local variable 'scoped-class' to
54 'this-class' to remove ambiguitity from old global.
55
56 * emacs-lisp/eieio-core.el: New file. Derived from key parts of
57 eieio.el.
58 (eieio--scoped-class-stack): New variable
59 (eieio--scoped-class): New fcn
60 (eieio--with-scoped-class): New scoping macro.
61 (eieio-defclass): Use pushnew instead of add-to-list.
62 (eieio-defgeneric-form-primary-only-one, eieio-oset-default)
63 (eieio-slot-name-index, eieio-set-defaults, eieio-generic-call)
64 (eieio-generic-call-primary-only, eieiomt-add): Instead of using
65 `scoped-class' variable, use new eieio--scoped-class, and
66 eieio--with-scoped-class.
67
68 * emacs-lisp/eieio-base.el (cl-lib): Require during compile.
69
12013-05-28 Alan Mackenzie <acm@muc.de> 702013-05-28 Alan Mackenzie <acm@muc.de>
2 71
3 Handle "capitalised keywords" correctly. 72 Handle "capitalised keywords" correctly.
diff --git a/lisp/cedet/ChangeLog b/lisp/cedet/ChangeLog
index 25f966362ce..c662f5e817c 100644
--- a/lisp/cedet/ChangeLog
+++ b/lisp/cedet/ChangeLog
@@ -1,3 +1,83 @@
12013-06-02 Eric Ludlam <zappo@gnu.org>
2
3 * semantic/edit.el (semantic-change-function): Use
4 `save-match-data' around running hooks.
5
6 * semantic/decorate/mode.el
7 (semantic-decorate-style-predicate-default)
8 (semantic-decorate-style-highlighter-default): New.
9 (semantic-decoration-mode): Do not require
10 `semantic/decorate/include' anymore.
11 (semantic-toggle-decoration-style): Error if an unknown decoration
12 style is toggled.
13 (define-semantic-decoration-style): Add new :load option. When
14 :load is specified, add autoload tokens for the definition
15 functions so that code is loaded when the mode is used.
16 (semantic-decoration-on-includes): New autoload definition for
17 highlighting includes.
18
19 * semantic/bovine/c.el (semantic-lex-c-ifdef): Allow some misc
20 characters to appear after the tested variable.
21
22 * semantic/ede-grammar.el (project-compile-target): Calculate full
23 src name via ede-expand-filename instead of the crutch of the
24 current buffer. Enables this target to compile in batch mode.
25
26 * semantic/idle.el
27 (semantic-idle-symbol-maybe-highlight): Wrap highlighting of
28 remote symbol with `save-excursion'.
29 (semantic-idle-scheduler-work-parse-neighboring-files): Instead of
30 using directory-files on each found mode pattern, collect all the
31 patterns for the current mode, and then for each file, see if it
32 matches any of them. If it does, parse the file. (Patch
33 inspiration from Tomasz Gajewski.)
34
35 * semantic/ctxt.el (semantic-ctxt-end-of-symbol): New.
36 (semantic-ctxt-current-symbol-default): New.
37
38 * semantic/bovine/el.el (semantic-default-elisp-setup): Add
39 autoload cookie. Explain existence.
40 (footer): Add local variable for loaddefs.
41
42 * semantic/db.el (semanticdb-file-table-object): Add new filter,
43 only checking for regular files too.
44
45 * semantic/wisent/python.el
46 (semantic-format-tag-abbreviate): New override. Cuts back on size
47 of code tags.
48
49 * srecode/compile.el (srecode-compile-templates): Fix warning
50 punctuation. Remove status messages to clean up testing output
51
52 * ede/base.el (ede-project-placeholder-cache-file): Update doc to
53 mention 'nil' value.
54 (ede-save-cache): Disable cache save if file is nil.
55
56 * ede.el (ede-initialize-state-current-buffer): Flush deleted
57 projects.
58 (global-ede-mode): Always append our find-file-hook to the end.
59 (ede-flush-deleted-projects): New command.
60
61 * ede/cpp-root.el (ede-preprocessor-map): Protect against init
62 problems.
63
64 * ede/proj.el (ede-proj-target): Added a new "custom" option for
65 custom symbols representing a compiler or linker instead of
66 restricting things to only the predefined compilers and linkers.
67
682013-06-02 David Engster <dengste@eml.cc>
69
70 * semantic.el (semantic-mode-map): To avoid showing showing
71 Development menu twice, only disable menu item if menu-bar is
72 actually enabled, otherwise the popup 'global menu' might display
73 a disabled Development menu.
74
752013-06-02 Pete Beardmore <elbeardmorez@msn.com>
76
77 * semantic/complete.el
78 (semantic-displayor-show-request): Fix which slot in obj is set to
79 the max tags.
80
12013-05-24 Glenn Morris <rgm@gnu.org> 812013-05-24 Glenn Morris <rgm@gnu.org>
2 82
3 * semantic/bovine/grammar.el (bovine-make-parsers): 83 * semantic/bovine/grammar.el (bovine-make-parsers):
diff --git a/lisp/cedet/ede.el b/lisp/cedet/ede.el
index 5fecd8b994f..3483d541122 100644
--- a/lisp/cedet/ede.el
+++ b/lisp/cedet/ede.el
@@ -494,6 +494,11 @@ provided `global-ede-mode' is enabled."
494(defun ede-initialize-state-current-buffer () 494(defun ede-initialize-state-current-buffer ()
495 "Initialize the current buffer's state for EDE. 495 "Initialize the current buffer's state for EDE.
496Sets buffer local variables for EDE." 496Sets buffer local variables for EDE."
497 ;; due to inode recycling, make sure we don't
498 ;; we flush projects deleted off the system.
499 (ede-flush-deleted-projects)
500
501 ;; Init the buffer.
497 (let* ((ROOT nil) 502 (let* ((ROOT nil)
498 (proj (ede-directory-get-open-project default-directory 503 (proj (ede-directory-get-open-project default-directory
499 'ROOT)) 504 'ROOT))
@@ -569,7 +574,9 @@ an EDE controlled project."
569 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p) 574 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
570 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil) 575 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
571 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths) 576 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
572 (add-hook 'find-file-hook 'ede-turn-on-hook) 577 ;; Append our hook to the end. This allows mode-local to finish
578 ;; it's stuff before we start doing misc file loads, etc.
579 (add-hook 'find-file-hook 'ede-turn-on-hook t)
573 (add-hook 'dired-mode-hook 'ede-turn-on-hook) 580 (add-hook 'dired-mode-hook 'ede-turn-on-hook)
574 (add-hook 'kill-emacs-hook 'ede-save-cache) 581 (add-hook 'kill-emacs-hook 'ede-save-cache)
575 (ede-load-cache) 582 (ede-load-cache)
@@ -1057,6 +1064,18 @@ On success, return the added project."
1057 (add-to-list 'ede-projects proj) 1064 (add-to-list 'ede-projects proj)
1058 proj) 1065 proj)
1059 1066
1067(defun ede-flush-deleted-projects ()
1068 "Scan the projects list for projects which no longer exist.
1069Flush the dead projects from the project cache."
1070 (interactive)
1071 (let ((dead nil))
1072 (dolist (P ede-projects)
1073 (when (not (file-exists-p (oref P :file)))
1074 (add-to-list 'dead P)))
1075 (dolist (D dead)
1076 (setq ede-projects (remove D ede-projects)))
1077 ))
1078
1060(defun ede-load-project-file (dir &optional rootreturn) 1079(defun ede-load-project-file (dir &optional rootreturn)
1061 "Project file independent way to read a project in from DIR. 1080 "Project file independent way to read a project in from DIR.
1062Optional ROOTRETURN will return the root project for DIR." 1081Optional ROOTRETURN will return the root project for DIR."
diff --git a/lisp/cedet/ede/base.el b/lisp/cedet/ede/base.el
index 5302ac3207a..a94ce8f1868 100644
--- a/lisp/cedet/ede/base.el
+++ b/lisp/cedet/ede/base.el
@@ -306,7 +306,8 @@ All specific project types must derive from this project."
306;; 306;;
307(defcustom ede-project-placeholder-cache-file 307(defcustom ede-project-placeholder-cache-file
308 (locate-user-emacs-file "ede-projects.el" ".projects.ede") 308 (locate-user-emacs-file "ede-projects.el" ".projects.ede")
309 "File containing the list of projects EDE has viewed." 309 "File containing the list of projects EDE has viewed.
310If set to nil, then the cache is not saved."
310 :group 'ede 311 :group 'ede
311 :type 'file) 312 :type 'file)
312 313
@@ -316,38 +317,39 @@ All specific project types must derive from this project."
316(defun ede-save-cache () 317(defun ede-save-cache ()
317 "Save a cache of EDE objects that Emacs has seen before." 318 "Save a cache of EDE objects that Emacs has seen before."
318 (interactive) 319 (interactive)
319 (let ((p ede-projects) 320 (when ede-project-placeholder-cache-file
320 (c ede-project-cache-files) 321 (let ((p ede-projects)
321 (recentf-exclude '( (lambda (f) t) )) 322 (c ede-project-cache-files)
322 ) 323 (recentf-exclude '( (lambda (f) t) ))
323 (condition-case nil
324 (progn
325 (set-buffer (find-file-noselect ede-project-placeholder-cache-file t))
326 (erase-buffer)
327 (insert ";; EDE project cache file.
328;; This contains a list of projects you have visited.\n(")
329 (while p
330 (when (and (car p) (ede-project-p p))
331 (let ((f (oref (car p) file)))
332 (when (file-exists-p f)
333 (insert "\n \"" f "\""))))
334 (setq p (cdr p)))
335 (while c
336 (insert "\n \"" (car c) "\"")
337 (setq c (cdr c)))
338 (insert "\n)\n")
339 (condition-case nil
340 (save-buffer 0)
341 (error
342 (message "File %s could not be saved."
343 ede-project-placeholder-cache-file)))
344 (kill-buffer (current-buffer))
345 ) 324 )
346 (error 325 (condition-case nil
347 (message "File %s could not be read." 326 (progn
348 ede-project-placeholder-cache-file)) 327 (set-buffer (find-file-noselect ede-project-placeholder-cache-file t))
349 328 (erase-buffer)
350 ))) 329 (insert ";; EDE project cache file.
330;; This contains a list of projects you have visited.\n(")
331 (while p
332 (when (and (car p) (ede-project-p p))
333 (let ((f (oref (car p) file)))
334 (when (file-exists-p f)
335 (insert "\n \"" f "\""))))
336 (setq p (cdr p)))
337 (while c
338 (insert "\n \"" (car c) "\"")
339 (setq c (cdr c)))
340 (insert "\n)\n")
341 (condition-case nil
342 (save-buffer 0)
343 (error
344 (message "File %s could not be saved."
345 ede-project-placeholder-cache-file)))
346 (kill-buffer (current-buffer))
347 )
348 (error
349 (message "File %s could not be read."
350 ede-project-placeholder-cache-file))
351
352 ))))
351 353
352(defun ede-load-cache () 354(defun ede-load-cache ()
353 "Load the cache of EDE projects." 355 "Load the cache of EDE projects."
diff --git a/lisp/cedet/ede/cpp-root.el b/lisp/cedet/ede/cpp-root.el
index 47ba16ade7f..719289765a3 100644
--- a/lisp/cedet/ede/cpp-root.el
+++ b/lisp/cedet/ede/cpp-root.el
@@ -507,7 +507,10 @@ This is for project include paths and spp source files."
507 (lambda (F) 507 (lambda (F)
508 (let* ((expfile (ede-expand-filename root F)) 508 (let* ((expfile (ede-expand-filename root F))
509 (table (when expfile 509 (table (when expfile
510 (semanticdb-file-table-object expfile))) 510 ;; Disable EDE init on preprocessor file load
511 ;; otherwise we recurse, cause errs, etc.
512 (let ((ede-constructing t))
513 (semanticdb-file-table-object expfile))))
511 ) 514 )
512 (cond 515 (cond
513 ((not (file-exists-p expfile)) 516 ((not (file-exists-p expfile))
diff --git a/lisp/cedet/ede/proj.el b/lisp/cedet/ede/proj.el
index 702e35f0b1f..99a5978b005 100644
--- a/lisp/cedet/ede/proj.el
+++ b/lisp/cedet/ede/proj.el
@@ -104,6 +104,7 @@ distributed, and each should have a corresponding rule to build it.")
104 :initform nil 104 :initform nil
105 :type (or null symbol) 105 :type (or null symbol)
106 :custom (choice (const :tag "None" nil) 106 :custom (choice (const :tag "None" nil)
107 (symbol :tag "Custom Compiler Symbol")
107 :slotofchoices availablecompilers) 108 :slotofchoices availablecompilers)
108 :label "Compiler for building sources" 109 :label "Compiler for building sources"
109 :group make 110 :group make
@@ -116,6 +117,7 @@ of these compiler resources, and global customization thereof.")
116 :initform nil 117 :initform nil
117 :type (or null symbol) 118 :type (or null symbol)
118 :custom (choice (const :tag "None" nil) 119 :custom (choice (const :tag "None" nil)
120 (symbol :tag "Custom Linker Symbol")
119 :slotofchoices availablelinkers) 121 :slotofchoices availablelinkers)
120 :label "Linker for combining intermediate object files." 122 :label "Linker for combining intermediate object files."
121 :group make 123 :group make
diff --git a/lisp/cedet/semantic.el b/lisp/cedet/semantic.el
index 3c93a8794b1..909902a71fe 100644
--- a/lisp/cedet/semantic.el
+++ b/lisp/cedet/semantic.el
@@ -899,7 +899,8 @@ Throw away all the old tags, and recreate the tag database."
899 ;; and Semantic are both enabled. Is there a better way? 899 ;; and Semantic are both enabled. Is there a better way?
900 (define-key map [menu-bar cedet-menu] 900 (define-key map [menu-bar cedet-menu]
901 (list 'menu-item "Development" cedet-menu-map 901 (list 'menu-item "Development" cedet-menu-map
902 :enable (quote (not (bound-and-true-p global-ede-mode))))) 902 :enable (quote (not (and menu-bar-mode
903 (bound-and-true-p global-ede-mode))))))
903 ;; (define-key km "-" 'senator-fold-tag) 904 ;; (define-key km "-" 'senator-fold-tag)
904 ;; (define-key km "+" 'senator-unfold-tag) 905 ;; (define-key km "+" 'senator-unfold-tag)
905 map)) 906 map))
diff --git a/lisp/cedet/semantic/bovine/c.el b/lisp/cedet/semantic/bovine/c.el
index 2f8cf08af3e..3c991ea8555 100644
--- a/lisp/cedet/semantic/bovine/c.el
+++ b/lisp/cedet/semantic/bovine/c.el
@@ -529,7 +529,7 @@ code to parse."
529(define-lex-regex-analyzer semantic-lex-c-ifdef 529(define-lex-regex-analyzer semantic-lex-c-ifdef
530 "Code blocks wrapped up in #ifdef. 530 "Code blocks wrapped up in #ifdef.
531Uses known macro tables in SPP to determine what block to skip." 531Uses known macro tables in SPP to determine what block to skip."
532 "^\\s-*#\\s-*\\(ifndef\\|ifdef\\)\\s-+\\(\\(\\sw\\|\\s_\\)+\\)$" 532 "^\\s-*#\\s-*\\(ifndef\\|ifdef\\)\\s-+\\(\\(\\sw\\|\\s_\\)+\\)\\([ \t\C-m].*\\)?$"
533 (semantic-c-do-lex-ifdef)) 533 (semantic-c-do-lex-ifdef))
534 534
535(defun semantic-c-do-lex-ifdef () 535(defun semantic-c-do-lex-ifdef ()
diff --git a/lisp/cedet/semantic/bovine/el.el b/lisp/cedet/semantic/bovine/el.el
index a8ddbe106f7..07e0e08bbaf 100644
--- a/lisp/cedet/semantic/bovine/el.el
+++ b/lisp/cedet/semantic/bovine/el.el
@@ -940,8 +940,11 @@ ELisp variables can be pretty long, so track this one too.")
940(define-child-mode lisp-mode emacs-lisp-mode 940(define-child-mode lisp-mode emacs-lisp-mode
941 "Make `lisp-mode' inherit mode local behavior from `emacs-lisp-mode'.") 941 "Make `lisp-mode' inherit mode local behavior from `emacs-lisp-mode'.")
942 942
943;;;###autoload
943(defun semantic-default-elisp-setup () 944(defun semantic-default-elisp-setup ()
944 "Setup hook function for Emacs Lisp files and Semantic." 945 "Setup hook function for Emacs Lisp files and Semantic."
946 ;; This is here mostly to get this file loaded when a .el file is
947 ;; loaded into Emacs.
945 ) 948 )
946 949
947(add-hook 'emacs-lisp-mode-hook 'semantic-default-elisp-setup) 950(add-hook 'emacs-lisp-mode-hook 'semantic-default-elisp-setup)
@@ -960,6 +963,12 @@ ELisp variables can be pretty long, so track this one too.")
960 '(require 'semantic/db-el) 963 '(require 'semantic/db-el)
961 ) 964 )
962 965
966
963(provide 'semantic/bovine/el) 967(provide 'semantic/bovine/el)
964 968
969;; Local variables:
970;; generated-autoload-file: "../loaddefs.el"
971;; generated-autoload-load-name: "semantic/bovine/el"
972;; End:
973
965;;; semantic/bovine/el.el ends here 974;;; semantic/bovine/el.el ends here
diff --git a/lisp/cedet/semantic/complete.el b/lisp/cedet/semantic/complete.el
index 6c2b97a677a..b42e24fb9c0 100644
--- a/lisp/cedet/semantic/complete.el
+++ b/lisp/cedet/semantic/complete.el
@@ -1667,7 +1667,7 @@ Display mechanism using tooltip for a list of possible completions.")
1667 (setq msg "..."))) 1667 (setq msg "...")))
1668 ((eq mode 'verbose) 1668 ((eq mode 'verbose)
1669 ;; Always show extended match set. 1669 ;; Always show extended match set.
1670 (oset obj max-tags semantic-displayor-tooltip-max-tags) 1670 (oset obj max-tags-initial semantic-displayor-tooltip-max-tags)
1671 (setq max-tags semantic-displayor-tooltip-max-tags))) 1671 (setq max-tags semantic-displayor-tooltip-max-tags)))
1672 (unless msg 1672 (unless msg
1673 (oset obj shown t) 1673 (oset obj shown t)
diff --git a/lisp/cedet/semantic/ctxt.el b/lisp/cedet/semantic/ctxt.el
index 2c0b428c195..efaec4f63b4 100644
--- a/lisp/cedet/semantic/ctxt.el
+++ b/lisp/cedet/semantic/ctxt.el
@@ -357,6 +357,87 @@ beginning and end of a command."
357 (def-edebug-spec semantic-with-buffer-narrowed-to-command 357 (def-edebug-spec semantic-with-buffer-narrowed-to-command
358 (def-body)))) 358 (def-body))))
359 359
360(define-overloadable-function semantic-ctxt-end-of-symbol (&optional point)
361 "Move point to the end of the current symbol under POINT.
362This skips forward over symbols in a complex reference.
363For example, in the C statement:
364 this.that().entry;
365
366If the cursor is on 'this', will move point to the ; after entry.")
367
368(defun semantic-ctxt-end-of-symbol-default (&optional point)
369 "Move poin to the end of the current symbol under POINT.
370This will move past type/field names when applicable.
371Depends on `semantic-type-relation-separator-character', and will
372work on C like languages."
373 (if point (goto-char point))
374 (let* ((fieldsep1 (mapconcat (lambda (a) (regexp-quote a))
375 semantic-type-relation-separator-character
376 "\\|"))
377 ;; NOTE: The [ \n] expression below should used \\s-, but that
378 ;; doesn't work in C since \n means end-of-comment, and isn't
379 ;; really whitespace.
380 (fieldsep (concat "[ \t\n\r]*\\(" fieldsep1 "\\)[ \t\n\r]*\\(\\w\\|\\s_\\)"))
381 (case-fold-search semantic-case-fold)
382 (continuesearch t)
383 (end nil)
384 )
385 (with-syntax-table semantic-lex-syntax-table
386 (cond ((looking-at "\\w\\|\\s_")
387 ;; In the middle of a symbol, move to the end.
388 (forward-sexp 1))
389 ((looking-at fieldsep1)
390 ;; We are in a fine spot.. do nothing.
391 nil
392 )
393 ((save-excursion
394 (and (condition-case nil
395 (progn (forward-sexp -1)
396 (forward-sexp 1)
397 t)
398 (error nil))
399 (looking-at fieldsep1)))
400 (setq symlist (list ""))
401 (forward-sexp -1)
402 ;; Skip array expressions.
403 (while (looking-at "\\s(") (forward-sexp -1))
404 (forward-sexp 1))
405 )
406 ;; Set the current end marker.
407 (setq end (point))
408
409 ;; Cursor is at the safe end of some symbol. Look until we
410 ;; find the logical end of this current complex symbol.
411 (condition-case nil
412 (while continuesearch
413 ;; If there are functional arguments, arrays, etc, skip them.
414 (when (looking-at "\\s(")
415 (forward-sexp 1))
416
417 ;; If there is a field separator, then skip that, plus
418 ;; the next expected symbol.
419 (if (not (looking-at fieldsep1))
420 ;; We hit the end.
421 (error nil)
422
423 ;; Skip the separator and the symbol.
424 (goto-char (match-end 0))
425
426 (if (looking-at "\\w\\|\\s_")
427 ;; Skip symbols
428 (forward-sexp 1)
429 ;; No symbol, exit the search...
430 (setq continuesearch nil))
431
432 (setq end (point)))
433
434 ;; Cont...
435 )
436
437 ;; Restore position if we go to far....
438 (error (goto-char end)) )
439
440 )))
360 441
361(define-overloadable-function semantic-ctxt-current-symbol (&optional point) 442(define-overloadable-function semantic-ctxt-current-symbol (&optional point)
362 "Return the current symbol the cursor is on at POINT in a list. 443 "Return the current symbol the cursor is on at POINT in a list.
@@ -391,7 +472,7 @@ Depends on `semantic-type-relation-separator-character'."
391 ;; In the middle of a symbol, move to the end. 472 ;; In the middle of a symbol, move to the end.
392 (forward-sexp 1)) 473 (forward-sexp 1))
393 ((looking-at fieldsep1) 474 ((looking-at fieldsep1)
394 ;; We are in a find spot.. do nothing. 475 ;; We are in a fine spot.. do nothing.
395 nil 476 nil
396 ) 477 )
397 ((save-excursion 478 ((save-excursion
diff --git a/lisp/cedet/semantic/db.el b/lisp/cedet/semantic/db.el
index e8784c4f85c..8d9cfcccd7d 100644
--- a/lisp/cedet/semantic/db.el
+++ b/lisp/cedet/semantic/db.el
@@ -899,7 +899,7 @@ If file does not have tags available, and DONTLOAD is nil,
899then load the tags for FILE, and create a new table object for it. 899then load the tags for FILE, and create a new table object for it.
900DONTLOAD does not affect the creation of new database objects." 900DONTLOAD does not affect the creation of new database objects."
901 ;; (message "Object Translate: %s" file) 901 ;; (message "Object Translate: %s" file)
902 (when (and file (file-exists-p file)) 902 (when (and file (file-exists-p file) (file-regular-p file))
903 (let* ((default-directory (file-name-directory file)) 903 (let* ((default-directory (file-name-directory file))
904 (tab (semanticdb-file-table-object-from-hash file)) 904 (tab (semanticdb-file-table-object-from-hash file))
905 (fullfile nil)) 905 (fullfile nil))
diff --git a/lisp/cedet/semantic/decorate/mode.el b/lisp/cedet/semantic/decorate/mode.el
index fc791f52da1..3487e615168 100644
--- a/lisp/cedet/semantic/decorate/mode.el
+++ b/lisp/cedet/semantic/decorate/mode.el
@@ -64,6 +64,14 @@ add items to this list."
64 "Return the STYLE's highlighter function." 64 "Return the STYLE's highlighter function."
65 (intern (format "%s-highlight" style))) 65 (intern (format "%s-highlight" style)))
66 66
67(defsubst semantic-decorate-style-predicate-default (style)
68 "Return the STYLE's predicate function."
69 (intern (format "%s-p-default" style)))
70
71(defsubst semantic-decorate-style-highlighter-default (style)
72 "Return the STYLE's highlighter function."
73 (intern (format "%s-highlight-default" style)))
74
67;;; Base decoration API 75;;; Base decoration API
68;; 76;;
69(defsubst semantic-decoration-p (object) 77(defsubst semantic-decoration-p (object)
@@ -265,8 +273,6 @@ minor mode is enabled."
265 (semantic-make-local-hook 'semantic-after-toplevel-cache-change-hook) 273 (semantic-make-local-hook 'semantic-after-toplevel-cache-change-hook)
266 (add-hook 'semantic-after-toplevel-cache-change-hook 274 (add-hook 'semantic-after-toplevel-cache-change-hook
267 'semantic-decorate-tags-after-full-reparse nil t) 275 'semantic-decorate-tags-after-full-reparse nil t)
268 ;; Decorate includes by default
269 (require 'semantic/decorate/include)
270 ;; Add decorations to available tags. The above hooks ensure 276 ;; Add decorations to available tags. The above hooks ensure
271 ;; that new tags will be decorated when they become available. 277 ;; that new tags will be decorated when they become available.
272 (semantic-decorate-add-decorations (semantic-fetch-available-tags))) 278 (semantic-decorate-add-decorations (semantic-fetch-available-tags)))
@@ -325,6 +331,8 @@ Return non-nil if the decoration style is enabled."
325 (flag (if arg 331 (flag (if arg
326 (> (prefix-numeric-value arg) 0) 332 (> (prefix-numeric-value arg) 0)
327 (not (cdr style))))) 333 (not (cdr style)))))
334 (when (null style)
335 (error "Unknown decoration style %s" name))
328 (unless (eq (cdr style) flag) 336 (unless (eq (cdr style) flag)
329 ;; Store the new flag. 337 ;; Store the new flag.
330 (setcdr style flag) 338 (setcdr style flag)
@@ -368,7 +376,8 @@ DOC is a documentation string describing the decoration style NAME.
368It is appended to auto-generated doc strings. 376It is appended to auto-generated doc strings.
369An Optional list of FLAGS can also be specified. Flags are: 377An Optional list of FLAGS can also be specified. Flags are:
370 :enabled <value> - specify the default enabled value for NAME. 378 :enabled <value> - specify the default enabled value for NAME.
371 379 :load <value> - specify a feature (as a string) with the rest of
380 the definition for decoration mode NAME.
372 381
373This defines two new overload functions respectively called `NAME-p' 382This defines two new overload functions respectively called `NAME-p'
374and `NAME-highlight', for which you must provide a default 383and `NAME-highlight', for which you must provide a default
@@ -386,9 +395,14 @@ To add other kind of decorations on a tag, `NAME-highlight' must use
386decoration API found in this library." 395decoration API found in this library."
387 (let ((predicate (semantic-decorate-style-predicate name)) 396 (let ((predicate (semantic-decorate-style-predicate name))
388 (highlighter (semantic-decorate-style-highlighter name)) 397 (highlighter (semantic-decorate-style-highlighter name))
398 (predicatedef (semantic-decorate-style-predicate-default name))
399 (highlighterdef (semantic-decorate-style-highlighter-default name))
389 (defaultenable (if (plist-member flags :enabled) 400 (defaultenable (if (plist-member flags :enabled)
390 (plist-get flags :enabled) 401 (plist-get flags :enabled)
391 t)) 402 t))
403 (loadfile (if (plist-member flags :load)
404 (plist-get flags :load)
405 nil))
392 ) 406 )
393 `(progn 407 `(progn
394 ;; Clear the menu cache so that new items are added when 408 ;; Clear the menu cache so that new items are added when
@@ -408,7 +422,19 @@ decoration API found in this library."
408 (add-to-list 'semantic-decoration-styles 422 (add-to-list 'semantic-decoration-styles
409 (cons ',(symbol-name name) 423 (cons ',(symbol-name name)
410 ,defaultenable)) 424 ,defaultenable))
411 ))) 425 ;; If there is a load file, then create the autload tokens for
426 ;; those functions to load the token, but only if the fsym
427 ;; doesn't exist yet.
428 (when (stringp ,loadfile)
429 (unless (fboundp ',predicatedef)
430 (autoload ',predicatedef ',loadfile "Return non-nil to decorate TAG."
431 nil 'function))
432
433 (unless (fboundp ',highlighterdef)
434 (autoload ',highlighterdef ',loadfile "Decorate TAG."
435 nil 'function))
436 ))
437 ))
412 438
413;;; Predefined decoration styles 439;;; Predefined decoration styles
414;; 440;;
@@ -514,6 +540,16 @@ Use a primary decoration."
514 (semantic-set-tag-face 540 (semantic-set-tag-face
515 tag 'semantic-decoration-on-protected-members-face)) 541 tag 'semantic-decoration-on-protected-members-face))
516 542
543;;; Decoration Modes in other files
544;;
545(define-semantic-decoration-style semantic-decoration-on-includes
546 "Highlight class members that are includes.
547This mode provides a nice context menu on the include statements."
548 :enabled t
549 :load "semantic/decorate/include")
550
551
552
517(provide 'semantic/decorate/mode) 553(provide 'semantic/decorate/mode)
518 554
519;; Local variables: 555;; Local variables:
diff --git a/lisp/cedet/semantic/ede-grammar.el b/lisp/cedet/semantic/ede-grammar.el
index cb2a1faaac0..17859e232a3 100644
--- a/lisp/cedet/semantic/ede-grammar.el
+++ b/lisp/cedet/semantic/ede-grammar.el
@@ -146,7 +146,7 @@ Lays claim to all -by.el, and -wy.el files."
146 (let* ((package (semantic-grammar-create-package)) 146 (let* ((package (semantic-grammar-create-package))
147 (fname (progn (string-match ".*/\\(.+\\.el\\)" package) 147 (fname (progn (string-match ".*/\\(.+\\.el\\)" package)
148 (match-string 1 package))) 148 (match-string 1 package)))
149 (src (with-current-buffer fname (buffer-file-name))) 149 (src (ede-expand-filename obj fname))
150 (csrc (concat (file-name-sans-extension src) ".elc"))) 150 (csrc (concat (file-name-sans-extension src) ".elc")))
151 (if (< emacs-major-version 24) 151 (if (< emacs-major-version 24)
152 ;; Does not have `byte-recompile-file' 152 ;; Does not have `byte-recompile-file'
diff --git a/lisp/cedet/semantic/edit.el b/lisp/cedet/semantic/edit.el
index b0540af373d..a27eab5404c 100644
--- a/lisp/cedet/semantic/edit.el
+++ b/lisp/cedet/semantic/edit.el
@@ -141,8 +141,9 @@ Argument START, END, and LENGTH specify the bounds of the change."
141 (setq semantic-unmatched-syntax-cache-check t) 141 (setq semantic-unmatched-syntax-cache-check t)
142 (let ((inhibit-point-motion-hooks t) 142 (let ((inhibit-point-motion-hooks t)
143 ) 143 )
144 (run-hook-with-args 'semantic-change-functions start end length) 144 (save-match-data
145 )) 145 (run-hook-with-args 'semantic-change-functions start end length)
146 )))
146 147
147(defun semantic-changes-in-region (start end &optional buffer) 148(defun semantic-changes-in-region (start end &optional buffer)
148 "Find change overlays which exist in whole or in part between START and END. 149 "Find change overlays which exist in whole or in part between START and END.
diff --git a/lisp/cedet/semantic/idle.el b/lisp/cedet/semantic/idle.el
index 9899ab974f7..6c223c2b9f2 100644
--- a/lisp/cedet/semantic/idle.el
+++ b/lisp/cedet/semantic/idle.el
@@ -434,16 +434,27 @@ datasets."
434 434
435(defun semantic-idle-scheduler-work-parse-neighboring-files () 435(defun semantic-idle-scheduler-work-parse-neighboring-files ()
436 "Parse all the files in similar directories to buffers being edited." 436 "Parse all the files in similar directories to buffers being edited."
437 ;; Let's check to see if EDE matters. 437 ;; Let's tell EDE to ignore all the files we're about to load
438 (let ((ede-auto-add-method 'never)) 438 (let ((ede-auto-add-method 'never)
439 (dolist (a auto-mode-alist) 439 (matching-auto-mode-patterns nil))
440 (when (eq (cdr a) major-mode) 440 ;; Collect all patterns matching files of the same mode we edit.
441 (dolist (file (directory-files default-directory t (car a) t)) 441 (mapc (lambda (pat) (and (eq (cdr pat) major-mode)
442 (semantic-throw-on-input 'parsing-mode-buffers) 442 (push (car pat) matching-auto-mode-patterns)))
443 (save-excursion 443 auto-mode-alist)
444 (semanticdb-file-table-object file) 444 ;; Loop over all files, and if one matches our mode, we force its
445 )))) 445 ;; table to load.
446 )) 446 (dolist (file (directory-files default-directory t ".*" t))
447 (catch 'found
448 (mapc (lambda (pat)
449 (semantic-throw-on-input 'parsing-mode-buffers)
450 ;; We use string-match instead of passing the pattern
451 ;; into directory files, because some patterns don't
452 ;; work with directory files.
453 (and (string-match pat file)
454 (save-excursion
455 (semanticdb-file-table-object file))
456 (throw 'found t)))
457 matching-auto-mode-patterns)))))
447 458
448 459
449;;; REPARSING 460;;; REPARSING
@@ -840,17 +851,18 @@ visible, then highlight it."
840 ) 851 )
841 (cond ((semantic-overlay-p region) 852 (cond ((semantic-overlay-p region)
842 (with-current-buffer (semantic-overlay-buffer region) 853 (with-current-buffer (semantic-overlay-buffer region)
843 (goto-char (semantic-overlay-start region)) 854 (save-excursion
844 (when (pos-visible-in-window-p 855 (goto-char (semantic-overlay-start region))
845 (point) (get-buffer-window (current-buffer) 'visible)) 856 (when (pos-visible-in-window-p
846 (if (< (semantic-overlay-end region) (point-at-eol)) 857 (point) (get-buffer-window (current-buffer) 'visible))
847 (pulse-momentary-highlight-overlay 858 (if (< (semantic-overlay-end region) (point-at-eol))
848 region semantic-idle-symbol-highlight-face) 859 (pulse-momentary-highlight-overlay
849 ;; Not the same 860 region semantic-idle-symbol-highlight-face)
850 (pulse-momentary-highlight-region 861 ;; Not the same
851 (semantic-overlay-start region) 862 (pulse-momentary-highlight-region
852 (point-at-eol) 863 (semantic-overlay-start region)
853 semantic-idle-symbol-highlight-face))) 864 (point-at-eol)
865 semantic-idle-symbol-highlight-face))))
854 )) 866 ))
855 ((vectorp region) 867 ((vectorp region)
856 (let ((start (aref region 0)) 868 (let ((start (aref region 0))
diff --git a/lisp/cedet/semantic/wisent/python.el b/lisp/cedet/semantic/wisent/python.el
index 8ca398ef271..719868f7635 100644
--- a/lisp/cedet/semantic/wisent/python.el
+++ b/lisp/cedet/semantic/wisent/python.el
@@ -485,6 +485,20 @@ Return a list as per `semantic-ctxt-current-symbol'.
485Return nil if there is nothing relevant." 485Return nil if there is nothing relevant."
486 nil) 486 nil)
487 487
488;;; Tag Formatting
489;;
490(define-mode-local-override semantic-format-tag-abbreviate python-mode (tag &optional parent color)
491 "Format an abbreviated tag for python.
492Shortens 'code' tags, but passes through for others."
493 (cond ((semantic-tag-of-class-p tag 'code)
494 ;; Just take the first line.
495 (let ((name (semantic-tag-name tag)))
496 (when (string-match "\n" name)
497 (setq name (substring name 0 (match-beginning 0))))
498 name))
499 (t
500 (semantic-format-tag-abbreviate-default tag parent color))))
501
488;;; Enable Semantic in `python-mode'. 502;;; Enable Semantic in `python-mode'.
489;; 503;;
490 504
diff --git a/lisp/cedet/srecode/compile.el b/lisp/cedet/srecode/compile.el
index 0d68036c433..542fd49f8e5 100644
--- a/lisp/cedet/srecode/compile.el
+++ b/lisp/cedet/srecode/compile.el
@@ -200,10 +200,11 @@ Arguments ESCAPE-START and ESCAPE-END are the current escape sequences in use."
200 "Compile a semantic recode template file into a mode-local variable." 200 "Compile a semantic recode template file into a mode-local variable."
201 (interactive) 201 (interactive)
202 (unless (semantic-active-p) 202 (unless (semantic-active-p)
203 (error "You have to activate semantic-mode to compile SRecode templates.")) 203 (error "You have to activate semantic-mode to compile SRecode templates"))
204 (require 'srecode/insert) 204 (require 'srecode/insert)
205 (message "Compiling template %s..." 205 (when (called-interactively-p 'interactive)
206 (file-name-nondirectory (buffer-file-name))) 206 (message "Compiling template %s..."
207 (file-name-nondirectory (buffer-file-name))))
207 (let ((tags (semantic-fetch-tags)) 208 (let ((tags (semantic-fetch-tags))
208 (tag nil) 209 (tag nil)
209 (class nil) 210 (class nil)
@@ -288,10 +289,11 @@ Arguments ESCAPE-START and ESCAPE-END are the current escape sequences in use."
288 ) 289 )
289 ;; Continue 290 ;; Continue
290 (setq tags (cdr tags))) 291 (setq tags (cdr tags)))
291 292
292 ;; MSG - Before install since nreverse whacks our list. 293 ;; MSG - Before install since nreverse whacks our list.
293 (message "%d templates compiled for %s" 294 (when (called-interactively-p 'interactive)
294 (length table) mode) 295 (message "%d templates compiled for %s"
296 (length table) mode))
295 297
296 ;; 298 ;;
297 ;; APPLY TO MODE 299 ;; APPLY TO MODE
@@ -316,12 +318,14 @@ Arguments ESCAPE-START and ESCAPE-END are the current escape sequences in use."
316 (if (stringp project) 318 (if (stringp project)
317 (setq priority (+ 50 defaultdelta)) 319 (setq priority (+ 50 defaultdelta))
318 (setq priority (+ 80 defaultdelta)))) 320 (setq priority (+ 80 defaultdelta))))
319 (message "Templates %s has estimated priority of %d" 321 (when (called-interactively-p 'interactive)
320 (file-name-nondirectory (buffer-file-name)) 322 (message "Templates %s has estimated priority of %d"
321 priority)) 323 (file-name-nondirectory (buffer-file-name))
322 (message "Compiling templates %s priority %d... done!" 324 priority)))
323 (file-name-nondirectory (buffer-file-name)) 325 (when (called-interactively-p 'interactive)
324 priority)) 326 (message "Compiling templates %s priority %d... done!"
327 (file-name-nondirectory (buffer-file-name))
328 priority)))
325 329
326 ;; Save it up! 330 ;; Save it up!
327 (srecode-compile-template-table table mode priority application framework project vars) 331 (srecode-compile-template-table table mode priority application framework project vars)
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index c8ae3f4bf1a..21190446624 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -31,6 +31,7 @@
31;;; Code: 31;;; Code:
32 32
33(require 'eieio) 33(require 'eieio)
34(eval-when-compile (require 'cl)) ;FIXME: Use cl-lib!
34 35
35;;; eieio-instance-inheritor 36;;; eieio-instance-inheritor
36;; 37;;
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
new file mode 100644
index 00000000000..da475638bb7
--- /dev/null
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -0,0 +1,2264 @@
1;;; eieio-core.el --- Core implementation for eieio
2
3;; Copyright (C) 1995-1996, 1998-2013 Free Software Foundation, Inc.
4
5;; Author: Eric M. Ludlam <zappo@gnu.org>
6;; Version: 1.4
7;; Keywords: OO, lisp
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25;;
26;; The "core" part of EIEIO is the implementation for the object
27;; system (such as eieio-defclass, or eieio-defmethod) but not the
28;; base classes for the object system, which are defined in EIEIO.
29;;
30;; See the commentary for eieio.el for more about EIEIO itself.
31
32;;; Code:
33
34(eval-when-compile (require 'cl)) ;FIXME: Use cl-lib!
35
36;; Compatibility
37(if (fboundp 'compiled-function-arglist)
38
39 ;; XEmacs can only access a compiled functions arglist like this:
40 (defalias 'eieio-compiled-function-arglist 'compiled-function-arglist)
41
42 ;; Emacs doesn't have this function, but since FUNC is a vector, we can just
43 ;; grab the appropriate element.
44 (defun eieio-compiled-function-arglist (func)
45 "Return the argument list for the compiled function FUNC."
46 (aref func 0))
47
48 )
49
50(put 'eieio--defalias 'byte-hunk-handler
51 #'byte-compile-file-form-defalias) ;;(get 'defalias 'byte-hunk-handler)
52(defun eieio--defalias (name body)
53 "Like `defalias', but with less side-effects.
54More specifically, it has no side-effects at all when the new function
55definition is the same (`eq') as the old one."
56 (unless (and (fboundp name)
57 (eq (symbol-function name) body))
58 (defalias name body)))
59
60;;;
61;; A few functions that are better in the official EIEIO src, but
62;; used from the core.
63(declare-function slot-unbound "eieio")
64(declare-function slot-missing "eieio")
65(declare-function child-of-class-p "eieio")
66
67
68;;;
69;; Variable declarations.
70;;
71(defvar eieio-hook nil
72 "This hook is executed, then cleared each time `defclass' is called.")
73
74(defvar eieio-error-unsupported-class-tags nil
75 "Non-nil to throw an error if an encountered tag is unsupported.
76This may prevent classes from CLOS applications from being used with EIEIO
77since EIEIO does not support all CLOS tags.")
78
79(defvar eieio-skip-typecheck nil
80 "If non-nil, skip all slot typechecking.
81Set this to t permanently if a program is functioning well to get a
82small speed increase. This variable is also used internally to handle
83default setting for optimization purposes.")
84
85(defvar eieio-optimize-primary-methods-flag t
86 "Non-nil means to optimize the method dispatch on primary methods.")
87
88(defvar eieio-initializing-object nil
89 "Set to non-nil while initializing an object.")
90
91(defconst eieio-unbound
92 (if (and (boundp 'eieio-unbound) (symbolp eieio-unbound))
93 eieio-unbound
94 (make-symbol "unbound"))
95 "Uninterned symbol representing an unbound slot in an object.")
96
97;; This is a bootstrap for eieio-default-superclass so it has a value
98;; while it is being built itself.
99(defvar eieio-default-superclass nil)
100
101;;;
102;; Class currently in scope.
103;;
104;; When invoking methods, the running method needs to know which class
105;; is currently in scope. Generally this is the class of the method
106;; being called, but 'call-next-method' needs to query this state,
107;; and change it to be then next super class up.
108;;
109;; Thus, the scoped class is a stack that needs to be managed.
110
111(defvar eieio--scoped-class-stack nil
112 "A stack of the classes currently in scope during method invocation.")
113
114(defun eieio--scoped-class ()
115 "Return the class currently in scope, or nil."
116 (car-safe eieio--scoped-class-stack))
117
118(defmacro eieio--with-scoped-class (class &rest forms)
119 "Set CLASS as the currently scoped class while executing FORMS."
120 `(unwind-protect
121 (progn
122 (push ,class eieio--scoped-class-stack)
123 ,@forms)
124 (pop eieio--scoped-class-stack)))
125(put 'eieio--with-scoped-class 'lisp-indent-function 1)
126
127;;;
128;; Field Accessors
129;;
130(defmacro eieio--define-field-accessors (prefix fields)
131 (declare (indent 1))
132 (let ((index 0)
133 (defs '()))
134 (dolist (field fields)
135 (let ((doc (if (listp field)
136 (prog1 (cadr field) (setq field (car field))))))
137 (push `(defmacro ,(intern (format "eieio--%s-%s" prefix field)) (x)
138 ,@(if doc (list (format (if (string-match "\n" doc)
139 "Return %s" "Return %s of a %s.")
140 doc prefix)))
141 (list 'aref x ,index))
142 defs)
143 (setq index (1+ index))))
144 `(eval-and-compile
145 ,@(nreverse defs)
146 (defconst ,(intern (format "eieio--%s-num-slots" prefix)) ,index))))
147
148(eieio--define-field-accessors class
149 (-unused-0 ;;FIXME: not sure, but at least there was no accessor!
150 (symbol "symbol (self-referencing)")
151 parent children
152 (symbol-obarray "obarray permitting fast access to variable position indexes")
153 ;; @todo
154 ;; the word "public" here is leftovers from the very first version.
155 ;; Get rid of it!
156 (public-a "class attribute index")
157 (public-d "class attribute defaults index")
158 (public-doc "class documentation strings for attributes")
159 (public-type "class type for a slot")
160 (public-custom "class custom type for a slot")
161 (public-custom-label "class custom group for a slot")
162 (public-custom-group "class custom group for a slot")
163 (public-printer "printer for a slot")
164 (protection "protection for a slot")
165 (initarg-tuples "initarg tuples list")
166 (class-allocation-a "class allocated attributes")
167 (class-allocation-doc "class allocated documentation")
168 (class-allocation-type "class allocated value type")
169 (class-allocation-custom "class allocated custom descriptor")
170 (class-allocation-custom-label "class allocated custom descriptor")
171 (class-allocation-custom-group "class allocated custom group")
172 (class-allocation-printer "class allocated printer for a slot")
173 (class-allocation-protection "class allocated protection list")
174 (class-allocation-values "class allocated value vector")
175 (default-object-cache "what a newly created object would look like.
176This will speed up instantiation time as only a `copy-sequence' will
177be needed, instead of looping over all the values and setting them
178from the default.")
179 (options "storage location of tagged class options.
180Stored outright without modifications or stripping.")))
181
182(eieio--define-field-accessors object
183 (-unused-0 ;;FIXME: not sure, but at least there was no accessor!
184 (class "class struct defining OBJ")
185 name))
186
187;; FIXME: The constants below should have an `eieio-' prefix added!!
188
189(defconst method-static 0 "Index into :static tag on a method.")
190(defconst method-before 1 "Index into :before tag on a method.")
191(defconst method-primary 2 "Index into :primary tag on a method.")
192(defconst method-after 3 "Index into :after tag on a method.")
193(defconst method-num-lists 4 "Number of indexes into methods vector in which groups of functions are kept.")
194(defconst method-generic-before 4 "Index into generic :before tag on a method.")
195(defconst method-generic-primary 5 "Index into generic :primary tag on a method.")
196(defconst method-generic-after 6 "Index into generic :after tag on a method.")
197(defconst method-num-slots 7 "Number of indexes into a method's vector.")
198
199(defsubst eieio-specialized-key-to-generic-key (key)
200 "Convert a specialized KEY into a generic method key."
201 (cond ((eq key method-static) 0) ;; don't convert
202 ((< key method-num-lists) (+ key 3)) ;; The conversion
203 (t key) ;; already generic.. maybe.
204 ))
205
206
207;;; Important macros used internally in eieio.
208;;
209(defmacro eieio--check-type (type obj)
210 (unless (symbolp obj)
211 (error "eieio--check-type wants OBJ to be a variable"))
212 `(if (not ,(cond
213 ((eq 'or (car-safe type))
214 `(or ,@(mapcar (lambda (type) `(,type ,obj)) (cdr type))))
215 (t `(,type ,obj))))
216 (signal 'wrong-type-argument (list ',type ,obj))))
217
218(defmacro class-v (class)
219 "Internal: Return the class vector from the CLASS symbol."
220 ;; No check: If eieio gets this far, it has probably been checked already.
221 `(get ,class 'eieio-class-definition))
222
223(defmacro class-p (class)
224 "Return t if CLASS is a valid class vector.
225CLASS is a symbol."
226 ;; this new method is faster since it doesn't waste time checking lots of
227 ;; things.
228 `(condition-case nil
229 (eq (aref (class-v ,class) 0) 'defclass)
230 (error nil)))
231
232(defun eieio-class-name (class) "Return a Lisp like symbol name for CLASS."
233 (eieio--check-type class-p class)
234 ;; I think this is supposed to return a symbol, but to me CLASS is a symbol,
235 ;; and I wanted a string. Arg!
236 (format "#<class %s>" (symbol-name class)))
237(define-obsolete-function-alias 'class-name #'eieio-class-name "24.4")
238
239(defmacro eieio-class-parents-fast (class)
240 "Return parent classes to CLASS with no check."
241 `(eieio--class-parent (class-v ,class)))
242
243(defmacro eieio-class-children-fast (class) "Return child classes to CLASS with no check."
244 `(eieio--class-children (class-v ,class)))
245
246(defmacro same-class-fast-p (obj class)
247 "Return t if OBJ is of class-type CLASS with no error checking."
248 `(eq (eieio--object-class ,obj) ,class))
249
250(defmacro class-constructor (class)
251 "Return the symbol representing the constructor of CLASS."
252 `(eieio--class-symbol (class-v ,class)))
253
254(defmacro generic-p (method)
255 "Return t if symbol METHOD is a generic function.
256Only methods have the symbol `eieio-method-obarray' as a property
257\(which contains a list of all bindings to that method type.)"
258 `(and (fboundp ,method) (get ,method 'eieio-method-obarray)))
259
260(defun generic-primary-only-p (method)
261 "Return t if symbol METHOD is a generic function with only primary methods.
262Only methods have the symbol `eieio-method-obarray' as a property (which
263contains a list of all bindings to that method type.)
264Methods with only primary implementations are executed in an optimized way."
265 (and (generic-p method)
266 (let ((M (get method 'eieio-method-tree)))
267 (and (< 0 (length (aref M method-primary)))
268 (not (aref M method-static))
269 (not (aref M method-before))
270 (not (aref M method-after))
271 (not (aref M method-generic-before))
272 (not (aref M method-generic-primary))
273 (not (aref M method-generic-after))))
274 ))
275
276(defun generic-primary-only-one-p (method)
277 "Return t if symbol METHOD is a generic function with only primary methods.
278Only methods have the symbol `eieio-method-obarray' as a property (which
279contains a list of all bindings to that method type.)
280Methods with only primary implementations are executed in an optimized way."
281 (and (generic-p method)
282 (let ((M (get method 'eieio-method-tree)))
283 (and (= 1 (length (aref M method-primary)))
284 (not (aref M method-static))
285 (not (aref M method-before))
286 (not (aref M method-after))
287 (not (aref M method-generic-before))
288 (not (aref M method-generic-primary))
289 (not (aref M method-generic-after))))
290 ))
291
292(defmacro class-option-assoc (list option)
293 "Return from LIST the found OPTION, or nil if it doesn't exist."
294 `(car-safe (cdr (memq ,option ,list))))
295
296(defmacro class-option (class option)
297 "Return the value stored for CLASS' OPTION.
298Return nil if that option doesn't exist."
299 `(class-option-assoc (eieio--class-options (class-v ,class)) ',option))
300
301(defmacro eieio-object-p (obj)
302 "Return non-nil if OBJ is an EIEIO object."
303 `(condition-case nil
304 (let ((tobj ,obj))
305 (and (eq (aref tobj 0) 'object)
306 (class-p (eieio--object-class tobj))))
307 (error nil)))
308(defalias 'object-p 'eieio-object-p)
309
310(defmacro class-abstract-p (class)
311 "Return non-nil if CLASS is abstract.
312Abstract classes cannot be instantiated."
313 `(class-option ,class :abstract))
314
315(defmacro class-method-invocation-order (class)
316 "Return the invocation order of CLASS.
317Abstract classes cannot be instantiated."
318 `(or (class-option ,class :method-invocation-order)
319 :breadth-first))
320
321
322
323;;;
324;; Class Creation
325
326(defvar eieio-defclass-autoload-map (make-vector 7 nil)
327 "Symbol map of superclasses we find in autoloads.")
328
329;; We autoload this because it's used in `make-autoload'.
330;;;###autoload
331(defun eieio-defclass-autoload (cname superclasses filename doc)
332 "Create autoload symbols for the EIEIO class CNAME.
333SUPERCLASSES are the superclasses that CNAME inherits from.
334DOC is the docstring for CNAME.
335This function creates a mock-class for CNAME and adds it into
336SUPERCLASSES as children.
337It creates an autoload function for CNAME's constructor."
338 ;; Assume we've already debugged inputs.
339
340 (let* ((oldc (when (class-p cname) (class-v cname)))
341 (newc (make-vector eieio--class-num-slots nil))
342 )
343 (if oldc
344 nil ;; Do nothing if we already have this class.
345
346 ;; Create the class in NEWC, but don't fill anything else in.
347 (aset newc 0 'defclass)
348 (setf (eieio--class-symbol newc) cname)
349
350 (let ((clear-parent nil))
351 ;; No parents?
352 (when (not superclasses)
353 (setq superclasses '(eieio-default-superclass)
354 clear-parent t)
355 )
356
357 ;; Hook our new class into the existing structures so we can
358 ;; autoload it later.
359 (dolist (SC superclasses)
360
361
362 ;; TODO - If we create an autoload that is in the map, that
363 ;; map needs to be cleared!
364
365
366 ;; Does our parent exist?
367 (if (not (class-p SC))
368
369 ;; Create a symbol for this parent, and then store this
370 ;; parent on that symbol.
371 (let ((sym (intern (symbol-name SC) eieio-defclass-autoload-map)))
372 (if (not (boundp sym))
373 (set sym (list cname))
374 (add-to-list sym cname))
375 )
376
377 ;; We have a parent, save the child in there.
378 (when (not (member cname (eieio--class-children (class-v SC))))
379 (setf (eieio--class-children (class-v SC))
380 (cons cname (eieio--class-children (class-v SC))))))
381
382 ;; save parent in child
383 (setf (eieio--class-parent newc) (cons SC (eieio--class-parent newc)))
384 )
385
386 ;; turn this into a usable self-pointing symbol
387 (set cname cname)
388
389 ;; Store the new class vector definition into the symbol. We need to
390 ;; do this first so that we can call defmethod for the accessor.
391 ;; The vector will be updated by the following while loop and will not
392 ;; need to be stored a second time.
393 (put cname 'eieio-class-definition newc)
394
395 ;; Clear the parent
396 (if clear-parent (setf (eieio--class-parent newc) nil))
397
398 ;; Create an autoload on top of our constructor function.
399 (autoload cname filename doc nil nil)
400 (autoload (intern (concat (symbol-name cname) "-p")) filename "" nil nil)
401 (autoload (intern (concat (symbol-name cname) "-child-p")) filename "" nil nil)
402 (autoload (intern (concat (symbol-name cname) "-list-p")) filename "" nil nil)
403
404 ))))
405
406(defsubst eieio-class-un-autoload (cname)
407 "If class CNAME is in an autoload state, load its file."
408 (when (eq (car-safe (symbol-function cname)) 'autoload)
409 (load-library (car (cdr (symbol-function cname))))))
410
411(defun eieio-defclass (cname superclasses slots options-and-doc)
412 ;; FIXME: Most of this should be moved to the `defclass' macro.
413 "Define CNAME as a new subclass of SUPERCLASSES.
414SLOTS are the slots residing in that class definition, and options or
415documentation OPTIONS-AND-DOC is the toplevel documentation for this class.
416See `defclass' for more information."
417 ;; Run our eieio-hook each time, and clear it when we are done.
418 ;; This way people can add hooks safely if they want to modify eieio
419 ;; or add definitions when eieio is loaded or something like that.
420 (run-hooks 'eieio-hook)
421 (setq eieio-hook nil)
422
423 (eieio--check-type listp superclasses)
424
425 (let* ((pname superclasses)
426 (newc (make-vector eieio--class-num-slots nil))
427 (oldc (when (class-p cname) (class-v cname)))
428 (groups nil) ;; list of groups id'd from slots
429 (options nil)
430 (clearparent nil))
431
432 (aset newc 0 'defclass)
433 (setf (eieio--class-symbol newc) cname)
434
435 ;; If this class already existed, and we are updating its structure,
436 ;; make sure we keep the old child list. This can cause bugs, but
437 ;; if no new slots are created, it also saves time, and prevents
438 ;; method table breakage, particularly when the users is only
439 ;; byte compiling an EIEIO file.
440 (if oldc
441 (setf (eieio--class-children newc) (eieio--class-children oldc))
442 ;; If the old class did not exist, but did exist in the autoload map, then adopt those children.
443 ;; This is like the above, but deals with autoloads nicely.
444 (let ((sym (intern-soft (symbol-name cname) eieio-defclass-autoload-map)))
445 (when sym
446 (condition-case nil
447 (setf (eieio--class-children newc) (symbol-value sym))
448 (error nil))
449 (unintern (symbol-name cname) eieio-defclass-autoload-map)
450 ))
451 )
452
453 (cond ((and (stringp (car options-and-doc))
454 (/= 1 (% (length options-and-doc) 2)))
455 (error "Too many arguments to `defclass'"))
456 ((and (symbolp (car options-and-doc))
457 (/= 0 (% (length options-and-doc) 2)))
458 (error "Too many arguments to `defclass'"))
459 )
460
461 (setq options
462 (if (stringp (car options-and-doc))
463 (cons :documentation options-and-doc)
464 options-and-doc))
465
466 (if pname
467 (progn
468 (while pname
469 (if (and (car pname) (symbolp (car pname)))
470 (if (not (class-p (car pname)))
471 ;; bad class
472 (error "Given parent class %s is not a class" (car pname))
473 ;; good parent class...
474 ;; save new child in parent
475 (when (not (member cname (eieio--class-children (class-v (car pname)))))
476 (setf (eieio--class-children (class-v (car pname)))
477 (cons cname (eieio--class-children (class-v (car pname))))))
478 ;; Get custom groups, and store them into our local copy.
479 (mapc (lambda (g) (pushnew g groups :test #'equal))
480 (class-option (car pname) :custom-groups))
481 ;; save parent in child
482 (setf (eieio--class-parent newc) (cons (car pname) (eieio--class-parent newc))))
483 (error "Invalid parent class %s" pname))
484 (setq pname (cdr pname)))
485 ;; Reverse the list of our parents so that they are prioritized in
486 ;; the same order as specified in the code.
487 (setf (eieio--class-parent newc) (nreverse (eieio--class-parent newc))) )
488 ;; If there is nothing to loop over, then inherit from the
489 ;; default superclass.
490 (unless (eq cname 'eieio-default-superclass)
491 ;; adopt the default parent here, but clear it later...
492 (setq clearparent t)
493 ;; save new child in parent
494 (if (not (member cname (eieio--class-children (class-v 'eieio-default-superclass))))
495 (setf (eieio--class-children (class-v 'eieio-default-superclass))
496 (cons cname (eieio--class-children (class-v 'eieio-default-superclass)))))
497 ;; save parent in child
498 (setf (eieio--class-parent newc) (list eieio-default-superclass))))
499
500 ;; turn this into a usable self-pointing symbol
501 (set cname cname)
502
503 ;; These two tests must be created right away so we can have self-
504 ;; referencing classes. ei, a class whose slot can contain only
505 ;; pointers to itself.
506
507 ;; Create the test function
508 (let ((csym (intern (concat (symbol-name cname) "-p"))))
509 (fset csym
510 (list 'lambda (list 'obj)
511 (format "Test OBJ to see if it an object of type %s" cname)
512 (list 'and '(eieio-object-p obj)
513 (list 'same-class-p 'obj cname)))))
514
515 ;; Make sure the method invocation order is a valid value.
516 (let ((io (class-option-assoc options :method-invocation-order)))
517 (when (and io (not (member io '(:depth-first :breadth-first :c3))))
518 (error "Method invocation order %s is not allowed" io)
519 ))
520
521 ;; Create a handy child test too
522 (let ((csym (intern (concat (symbol-name cname) "-child-p"))))
523 (fset csym
524 `(lambda (obj)
525 ,(format
526 "Test OBJ to see if it an object is a child of type %s"
527 cname)
528 (and (eieio-object-p obj)
529 (object-of-class-p obj ,cname))))
530
531 ;; Create a handy list of the class test too
532 (let ((csym (intern (concat (symbol-name cname) "-list-p"))))
533 (fset csym
534 `(lambda (obj)
535 ,(format
536 "Test OBJ to see if it a list of objects which are a child of type %s"
537 cname)
538 (when (listp obj)
539 (let ((ans t)) ;; nil is valid
540 ;; Loop over all the elements of the input list, test
541 ;; each to make sure it is a child of the desired object class.
542 (while (and obj ans)
543 (setq ans (and (eieio-object-p (car obj))
544 (object-of-class-p (car obj) ,cname)))
545 (setq obj (cdr obj)))
546 ans)))))
547
548 ;; When using typep, (typep OBJ 'myclass) returns t for objects which
549 ;; are subclasses of myclass. For our predicates, however, it is
550 ;; important for EIEIO to be backwards compatible, where
551 ;; myobject-p, and myobject-child-p are different.
552 ;; "cl" uses this technique to specify symbols with specific typep
553 ;; test, so we can let typep have the CLOS documented behavior
554 ;; while keeping our above predicate clean.
555
556 ;; It would be cleaner to use `defsetf' here, but that requires cl
557 ;; at runtime.
558 (put cname 'cl-deftype-handler
559 (list 'lambda () `(list 'satisfies (quote ,csym)))))
560
561 ;; Before adding new slots, let's add all the methods and classes
562 ;; in from the parent class.
563 (eieio-copy-parents-into-subclass newc superclasses)
564
565 ;; Store the new class vector definition into the symbol. We need to
566 ;; do this first so that we can call defmethod for the accessor.
567 ;; The vector will be updated by the following while loop and will not
568 ;; need to be stored a second time.
569 (put cname 'eieio-class-definition newc)
570
571 ;; Query each slot in the declaration list and mangle into the
572 ;; class structure I have defined.
573 (while slots
574 (let* ((slot1 (car slots))
575 (name (car slot1))
576 (slot (cdr slot1))
577 (acces (plist-get slot ':accessor))
578 (init (or (plist-get slot ':initform)
579 (if (member ':initform slot) nil
580 eieio-unbound)))
581 (initarg (plist-get slot ':initarg))
582 (docstr (plist-get slot ':documentation))
583 (prot (plist-get slot ':protection))
584 (reader (plist-get slot ':reader))
585 (writer (plist-get slot ':writer))
586 (alloc (plist-get slot ':allocation))
587 (type (plist-get slot ':type))
588 (custom (plist-get slot ':custom))
589 (label (plist-get slot ':label))
590 (customg (plist-get slot ':group))
591 (printer (plist-get slot ':printer))
592
593 (skip-nil (class-option-assoc options :allow-nil-initform))
594 )
595
596 (if eieio-error-unsupported-class-tags
597 (let ((tmp slot))
598 (while tmp
599 (if (not (member (car tmp) '(:accessor
600 :initform
601 :initarg
602 :documentation
603 :protection
604 :reader
605 :writer
606 :allocation
607 :type
608 :custom
609 :label
610 :group
611 :printer
612 :allow-nil-initform
613 :custom-groups)))
614 (signal 'invalid-slot-type (list (car tmp))))
615 (setq tmp (cdr (cdr tmp))))))
616
617 ;; Clean up the meaning of protection.
618 (cond ((or (eq prot 'public) (eq prot :public)) (setq prot nil))
619 ((or (eq prot 'protected) (eq prot :protected)) (setq prot 'protected))
620 ((or (eq prot 'private) (eq prot :private)) (setq prot 'private))
621 ((eq prot nil) nil)
622 (t (signal 'invalid-slot-type (list ':protection prot))))
623
624 ;; Make sure the :allocation parameter has a valid value.
625 (if (not (or (not alloc) (eq alloc :class) (eq alloc :instance)))
626 (signal 'invalid-slot-type (list ':allocation alloc)))
627
628 ;; The default type specifier is supposed to be t, meaning anything.
629 (if (not type) (setq type t))
630
631 ;; Label is nil, or a string
632 (if (not (or (null label) (stringp label)))
633 (signal 'invalid-slot-type (list ':label label)))
634
635 ;; Is there an initarg, but allocation of class?
636 (if (and initarg (eq alloc :class))
637 (message "Class allocated slots do not need :initarg"))
638
639 ;; intern the symbol so we can use it blankly
640 (if initarg (set initarg initarg))
641
642 ;; The customgroup should be a list of symbols
643 (cond ((null customg)
644 (setq customg '(default)))
645 ((not (listp customg))
646 (setq customg (list customg))))
647 ;; The customgroup better be a symbol, or list of symbols.
648 (mapc (lambda (cg)
649 (if (not (symbolp cg))
650 (signal 'invalid-slot-type (list ':group cg))))
651 customg)
652
653 ;; First up, add this slot into our new class.
654 (eieio-add-new-slot newc name init docstr type custom label customg printer
655 prot initarg alloc 'defaultoverride skip-nil)
656
657 ;; We need to id the group, and store them in a group list attribute.
658 (mapc (lambda (cg) (pushnew cg groups :test 'equal)) customg)
659
660 ;; Anyone can have an accessor function. This creates a function
661 ;; of the specified name, and also performs a `defsetf' if applicable
662 ;; so that users can `setf' the space returned by this function.
663 (if acces
664 (progn
665 (eieio--defmethod
666 acces (if (eq alloc :class) :static :primary) cname
667 `(lambda (this)
668 ,(format
669 "Retrieves the slot `%s' from an object of class `%s'"
670 name cname)
671 (if (slot-boundp this ',name)
672 (eieio-oref this ',name)
673 ;; Else - Some error? nil?
674 nil)))
675
676 (if (fboundp 'gv-define-setter)
677 ;; FIXME: We should move more of eieio-defclass into the
678 ;; defclass macro so we don't have to use `eval' and require
679 ;; `gv' at run-time.
680 (eval `(gv-define-setter ,acces (eieio--store eieio--object)
681 (list 'eieio-oset eieio--object '',name
682 eieio--store)))
683 ;; Provide a setf method. It would be cleaner to use
684 ;; defsetf, but that would require CL at runtime.
685 (put acces 'setf-method
686 `(lambda (widget)
687 (let* ((--widget-sym-- (make-symbol "--widget--"))
688 (--store-sym-- (make-symbol "--store--")))
689 (list
690 (list --widget-sym--)
691 (list widget)
692 (list --store-sym--)
693 (list 'eieio-oset --widget-sym-- '',name
694 --store-sym--)
695 (list 'getfoo --widget-sym--))))))))
696
697 ;; If a writer is defined, then create a generic method of that
698 ;; name whose purpose is to set the value of the slot.
699 (if writer
700 (eieio--defmethod
701 writer nil cname
702 `(lambda (this value)
703 ,(format "Set the slot `%s' of an object of class `%s'"
704 name cname)
705 (setf (slot-value this ',name) value))))
706 ;; If a reader is defined, then create a generic method
707 ;; of that name whose purpose is to access this slot value.
708 (if reader
709 (eieio--defmethod
710 reader nil cname
711 `(lambda (this)
712 ,(format "Access the slot `%s' from object of class `%s'"
713 name cname)
714 (slot-value this ',name))))
715 )
716 (setq slots (cdr slots)))
717
718 ;; Now that everything has been loaded up, all our lists are backwards!
719 ;; Fix that up now.
720 (setf (eieio--class-public-a newc) (nreverse (eieio--class-public-a newc)))
721 (setf (eieio--class-public-d newc) (nreverse (eieio--class-public-d newc)))
722 (setf (eieio--class-public-doc newc) (nreverse (eieio--class-public-doc newc)))
723 (setf (eieio--class-public-type newc)
724 (apply 'vector (nreverse (eieio--class-public-type newc))))
725 (setf (eieio--class-public-custom newc) (nreverse (eieio--class-public-custom newc)))
726 (setf (eieio--class-public-custom-label newc) (nreverse (eieio--class-public-custom-label newc)))
727 (setf (eieio--class-public-custom-group newc) (nreverse (eieio--class-public-custom-group newc)))
728 (setf (eieio--class-public-printer newc) (nreverse (eieio--class-public-printer newc)))
729 (setf (eieio--class-protection newc) (nreverse (eieio--class-protection newc)))
730 (setf (eieio--class-initarg-tuples newc) (nreverse (eieio--class-initarg-tuples newc)))
731
732 ;; The storage for class-class-allocation-type needs to be turned into
733 ;; a vector now.
734 (setf (eieio--class-class-allocation-type newc)
735 (apply 'vector (eieio--class-class-allocation-type newc)))
736
737 ;; Also, take class allocated values, and vectorize them for speed.
738 (setf (eieio--class-class-allocation-values newc)
739 (apply 'vector (eieio--class-class-allocation-values newc)))
740
741 ;; Attach slot symbols into an obarray, and store the index of
742 ;; this slot as the variable slot in this new symbol. We need to
743 ;; know about primes, because obarrays are best set in vectors of
744 ;; prime number length, and we also need to make our vector small
745 ;; to save space, and also optimal for the number of items we have.
746 (let* ((cnt 0)
747 (pubsyms (eieio--class-public-a newc))
748 (prots (eieio--class-protection newc))
749 (l (length pubsyms))
750 (vl (let ((primes '( 3 5 7 11 13 17 19 23 29 31 37 41 43 47
751 53 59 61 67 71 73 79 83 89 97 101 )))
752 (while (and primes (< (car primes) l))
753 (setq primes (cdr primes)))
754 (car primes)))
755 (oa (make-vector vl 0))
756 (newsym))
757 (while pubsyms
758 (setq newsym (intern (symbol-name (car pubsyms)) oa))
759 (set newsym cnt)
760 (setq cnt (1+ cnt))
761 (if (car prots) (put newsym 'protection (car prots)))
762 (setq pubsyms (cdr pubsyms)
763 prots (cdr prots)))
764 (setf (eieio--class-symbol-obarray newc) oa)
765 )
766
767 ;; Create the constructor function
768 (if (class-option-assoc options :abstract)
769 ;; Abstract classes cannot be instantiated. Say so.
770 (let ((abs (class-option-assoc options :abstract)))
771 (if (not (stringp abs))
772 (setq abs (format "Class %s is abstract" cname)))
773 (fset cname
774 `(lambda (&rest stuff)
775 ,(format "You cannot create a new object of type %s" cname)
776 (error ,abs))))
777
778 ;; Non-abstract classes need a constructor.
779 (fset cname
780 `(lambda (newname &rest slots)
781 ,(format "Create a new object with name NAME of class type %s" cname)
782 (apply 'constructor ,cname newname slots)))
783 )
784
785 ;; Set up a specialized doc string.
786 ;; Use stored value since it is calculated in a non-trivial way
787 (put cname 'variable-documentation
788 (class-option-assoc options :documentation))
789
790 ;; Save the file location where this class is defined.
791 (let ((fname (if load-in-progress
792 load-file-name
793 buffer-file-name)))
794 (when fname
795 (when (string-match "\\.elc\\'" fname)
796 (setq fname (substring fname 0 (1- (length fname)))))
797 (put cname 'class-location fname)))
798
799 ;; We have a list of custom groups. Store them into the options.
800 (let ((g (class-option-assoc options :custom-groups)))
801 (mapc (lambda (cg) (pushnew cg g :test 'equal)) groups)
802 (if (memq :custom-groups options)
803 (setcar (cdr (memq :custom-groups options)) g)
804 (setq options (cons :custom-groups (cons g options)))))
805
806 ;; Set up the options we have collected.
807 (setf (eieio--class-options newc) options)
808
809 ;; if this is a superclass, clear out parent (which was set to the
810 ;; default superclass eieio-default-superclass)
811 (if clearparent (setf (eieio--class-parent newc) nil))
812
813 ;; Create the cached default object.
814 (let ((cache (make-vector (+ (length (eieio--class-public-a newc)) 3)
815 nil)))
816 (aset cache 0 'object)
817 (setf (eieio--object-class cache) cname)
818 (setf (eieio--object-name cache) 'default-cache-object)
819 (let ((eieio-skip-typecheck t))
820 ;; All type-checking has been done to our satisfaction
821 ;; before this call. Don't waste our time in this call..
822 (eieio-set-defaults cache t))
823 (setf (eieio--class-default-object-cache newc) cache))
824
825 ;; Return our new class object
826 ;; newc
827 cname
828 ))
829
830(defsubst eieio-eval-default-p (val)
831 "Whether the default value VAL should be evaluated for use."
832 (and (consp val) (symbolp (car val)) (fboundp (car val))))
833
834(defun eieio-perform-slot-validation-for-default (slot spec value skipnil)
835 "For SLOT, signal if SPEC does not match VALUE.
836If SKIPNIL is non-nil, then if VALUE is nil return t instead."
837 (if (and (not (eieio-eval-default-p value))
838 (not eieio-skip-typecheck)
839 (not (and skipnil (null value)))
840 (not (eieio-perform-slot-validation spec value)))
841 (signal 'invalid-slot-type (list slot spec value))))
842
843(defun eieio-add-new-slot (newc a d doc type cust label custg print prot init alloc
844 &optional defaultoverride skipnil)
845 "Add into NEWC attribute A.
846If A already exists in NEWC, then do nothing. If it doesn't exist,
847then also add in D (default), DOC, TYPE, CUST, LABEL, CUSTG, PRINT, PROT, and INIT arg.
848Argument ALLOC specifies if the slot is allocated per instance, or per class.
849If optional DEFAULTOVERRIDE is non-nil, then if A exists in NEWC,
850we must override its value for a default.
851Optional argument SKIPNIL indicates if type checking should be skipped
852if default value is nil."
853 ;; Make sure we duplicate those items that are sequences.
854 (condition-case nil
855 (if (sequencep d) (setq d (copy-sequence d)))
856 ;; This copy can fail on a cons cell with a non-cons in the cdr. Let's skip it if it doesn't work.
857 (error nil))
858 (if (sequencep type) (setq type (copy-sequence type)))
859 (if (sequencep cust) (setq cust (copy-sequence cust)))
860 (if (sequencep custg) (setq custg (copy-sequence custg)))
861
862 ;; To prevent override information w/out specification of storage,
863 ;; we need to do this little hack.
864 (if (member a (eieio--class-class-allocation-a newc)) (setq alloc ':class))
865
866 (if (or (not alloc) (and (symbolp alloc) (eq alloc ':instance)))
867 ;; In this case, we modify the INSTANCE version of a given slot.
868
869 (progn
870
871 ;; Only add this element if it is so-far unique
872 (if (not (member a (eieio--class-public-a newc)))
873 (progn
874 (eieio-perform-slot-validation-for-default a type d skipnil)
875 (setf (eieio--class-public-a newc) (cons a (eieio--class-public-a newc)))
876 (setf (eieio--class-public-d newc) (cons d (eieio--class-public-d newc)))
877 (setf (eieio--class-public-doc newc) (cons doc (eieio--class-public-doc newc)))
878 (setf (eieio--class-public-type newc) (cons type (eieio--class-public-type newc)))
879 (setf (eieio--class-public-custom newc) (cons cust (eieio--class-public-custom newc)))
880 (setf (eieio--class-public-custom-label newc) (cons label (eieio--class-public-custom-label newc)))
881 (setf (eieio--class-public-custom-group newc) (cons custg (eieio--class-public-custom-group newc)))
882 (setf (eieio--class-public-printer newc) (cons print (eieio--class-public-printer newc)))
883 (setf (eieio--class-protection newc) (cons prot (eieio--class-protection newc)))
884 (setf (eieio--class-initarg-tuples newc) (cons (cons init a) (eieio--class-initarg-tuples newc)))
885 )
886 ;; When defaultoverride is true, we are usually adding new local
887 ;; attributes which must override the default value of any slot
888 ;; passed in by one of the parent classes.
889 (when defaultoverride
890 ;; There is a match, and we must override the old value.
891 (let* ((ca (eieio--class-public-a newc))
892 (np (member a ca))
893 (num (- (length ca) (length np)))
894 (dp (if np (nthcdr num (eieio--class-public-d newc))
895 nil))
896 (tp (if np (nth num (eieio--class-public-type newc))))
897 )
898 (if (not np)
899 (error "EIEIO internal error overriding default value for %s"
900 a)
901 ;; If type is passed in, is it the same?
902 (if (not (eq type t))
903 (if (not (equal type tp))
904 (error
905 "Child slot type `%s' does not match inherited type `%s' for `%s'"
906 type tp a)))
907 ;; If we have a repeat, only update the initarg...
908 (unless (eq d eieio-unbound)
909 (eieio-perform-slot-validation-for-default a tp d skipnil)
910 (setcar dp d))
911 ;; If we have a new initarg, check for it.
912 (when init
913 (let* ((inits (eieio--class-initarg-tuples newc))
914 (inita (rassq a inits)))
915 ;; Replace the CAR of the associate INITA.
916 ;;(message "Initarg: %S replace %s" inita init)
917 (setcar inita init)
918 ))
919
920 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is
921 ;; checked and SHOULD match the superclass
922 ;; protection. Otherwise an error is thrown. However
923 ;; I wonder if a more flexible schedule might be
924 ;; implemented.
925 ;;
926 ;; EML - We used to have (if prot... here,
927 ;; but a prot of 'nil means public.
928 ;;
929 (let ((super-prot (nth num (eieio--class-protection newc)))
930 )
931 (if (not (eq prot super-prot))
932 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'"
933 prot super-prot a)))
934 ;; End original PLN
935
936 ;; PLN Tue Jun 26 11:57:06 2007 :
937 ;; Do a non redundant combination of ancient custom
938 ;; groups and new ones.
939 (when custg
940 (let* ((groups
941 (nthcdr num (eieio--class-public-custom-group newc)))
942 (list1 (car groups))
943 (list2 (if (listp custg) custg (list custg))))
944 (if (< (length list1) (length list2))
945 (setq list1 (prog1 list2 (setq list2 list1))))
946 (dolist (elt list2)
947 (unless (memq elt list1)
948 (push elt list1)))
949 (setcar groups list1)))
950 ;; End PLN
951
952 ;; PLN Mon Jun 25 22:44:34 2007 : If a new cust is
953 ;; set, simply replaces the old one.
954 (when cust
955 ;; (message "Custom type redefined to %s" cust)
956 (setcar (nthcdr num (eieio--class-public-custom newc)) cust))
957
958 ;; If a new label is specified, it simply replaces
959 ;; the old one.
960 (when label
961 ;; (message "Custom label redefined to %s" label)
962 (setcar (nthcdr num (eieio--class-public-custom-label newc)) label))
963 ;; End PLN
964
965 ;; PLN Sat Jun 30 17:24:42 2007 : when a new
966 ;; doc is specified, simply replaces the old one.
967 (when doc
968 ;;(message "Documentation redefined to %s" doc)
969 (setcar (nthcdr num (eieio--class-public-doc newc))
970 doc))
971 ;; End PLN
972
973 ;; If a new printer is specified, it simply replaces
974 ;; the old one.
975 (when print
976 ;; (message "printer redefined to %s" print)
977 (setcar (nthcdr num (eieio--class-public-printer newc)) print))
978
979 )))
980 ))
981
982 ;; CLASS ALLOCATED SLOTS
983 (let ((value (eieio-default-eval-maybe d)))
984 (if (not (member a (eieio--class-class-allocation-a newc)))
985 (progn
986 (eieio-perform-slot-validation-for-default a type value skipnil)
987 ;; Here we have found a :class version of a slot. This
988 ;; requires a very different approach.
989 (setf (eieio--class-class-allocation-a newc) (cons a (eieio--class-class-allocation-a newc)))
990 (setf (eieio--class-class-allocation-doc newc) (cons doc (eieio--class-class-allocation-doc newc)))
991 (setf (eieio--class-class-allocation-type newc) (cons type (eieio--class-class-allocation-type newc)))
992 (setf (eieio--class-class-allocation-custom newc) (cons cust (eieio--class-class-allocation-custom newc)))
993 (setf (eieio--class-class-allocation-custom-label newc) (cons label (eieio--class-class-allocation-custom-label newc)))
994 (setf (eieio--class-class-allocation-custom-group newc) (cons custg (eieio--class-class-allocation-custom-group newc)))
995 (setf (eieio--class-class-allocation-protection newc) (cons prot (eieio--class-class-allocation-protection newc)))
996 ;; Default value is stored in the 'values section, since new objects
997 ;; can't initialize from this element.
998 (setf (eieio--class-class-allocation-values newc) (cons value (eieio--class-class-allocation-values newc))))
999 (when defaultoverride
1000 ;; There is a match, and we must override the old value.
1001 (let* ((ca (eieio--class-class-allocation-a newc))
1002 (np (member a ca))
1003 (num (- (length ca) (length np)))
1004 (dp (if np
1005 (nthcdr num
1006 (eieio--class-class-allocation-values newc))
1007 nil))
1008 (tp (if np (nth num (eieio--class-class-allocation-type newc))
1009 nil)))
1010 (if (not np)
1011 (error "EIEIO internal error overriding default value for %s"
1012 a)
1013 ;; If type is passed in, is it the same?
1014 (if (not (eq type t))
1015 (if (not (equal type tp))
1016 (error
1017 "Child slot type `%s' does not match inherited type `%s' for `%s'"
1018 type tp a)))
1019 ;; EML - Note: the only reason to override a class bound slot
1020 ;; is to change the default, so allow unbound in.
1021
1022 ;; If we have a repeat, only update the value...
1023 (eieio-perform-slot-validation-for-default a tp value skipnil)
1024 (setcar dp value))
1025
1026 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is
1027 ;; checked and SHOULD match the superclass
1028 ;; protection. Otherwise an error is thrown. However
1029 ;; I wonder if a more flexible schedule might be
1030 ;; implemented.
1031 (let ((super-prot
1032 (car (nthcdr num (eieio--class-class-allocation-protection newc)))))
1033 (if (not (eq prot super-prot))
1034 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'"
1035 prot super-prot a)))
1036 ;; Do a non redundant combination of ancient custom groups
1037 ;; and new ones.
1038 (when custg
1039 (let* ((groups
1040 (nthcdr num (eieio--class-class-allocation-custom-group newc)))
1041 (list1 (car groups))
1042 (list2 (if (listp custg) custg (list custg))))
1043 (if (< (length list1) (length list2))
1044 (setq list1 (prog1 list2 (setq list2 list1))))
1045 (dolist (elt list2)
1046 (unless (memq elt list1)
1047 (push elt list1)))
1048 (setcar groups list1)))
1049
1050 ;; PLN Sat Jun 30 17:24:42 2007 : when a new
1051 ;; doc is specified, simply replaces the old one.
1052 (when doc
1053 ;;(message "Documentation redefined to %s" doc)
1054 (setcar (nthcdr num (eieio--class-class-allocation-doc newc))
1055 doc))
1056 ;; End PLN
1057
1058 ;; If a new printer is specified, it simply replaces
1059 ;; the old one.
1060 (when print
1061 ;; (message "printer redefined to %s" print)
1062 (setcar (nthcdr num (eieio--class-class-allocation-printer newc)) print))
1063
1064 ))
1065 ))
1066 ))
1067
1068(defun eieio-copy-parents-into-subclass (newc parents)
1069 "Copy into NEWC the slots of PARENTS.
1070Follow the rules of not overwriting early parents when applying to
1071the new child class."
1072 (let ((ps (eieio--class-parent newc))
1073 (sn (class-option-assoc (eieio--class-options newc)
1074 ':allow-nil-initform)))
1075 (while ps
1076 ;; First, duplicate all the slots of the parent.
1077 (let ((pcv (class-v (car ps))))
1078 (let ((pa (eieio--class-public-a pcv))
1079 (pd (eieio--class-public-d pcv))
1080 (pdoc (eieio--class-public-doc pcv))
1081 (ptype (eieio--class-public-type pcv))
1082 (pcust (eieio--class-public-custom pcv))
1083 (plabel (eieio--class-public-custom-label pcv))
1084 (pcustg (eieio--class-public-custom-group pcv))
1085 (printer (eieio--class-public-printer pcv))
1086 (pprot (eieio--class-protection pcv))
1087 (pinit (eieio--class-initarg-tuples pcv))
1088 (i 0))
1089 (while pa
1090 (eieio-add-new-slot newc
1091 (car pa) (car pd) (car pdoc) (aref ptype i)
1092 (car pcust) (car plabel) (car pcustg)
1093 (car printer)
1094 (car pprot) (car-safe (car pinit)) nil nil sn)
1095 ;; Increment each value.
1096 (setq pa (cdr pa)
1097 pd (cdr pd)
1098 pdoc (cdr pdoc)
1099 i (1+ i)
1100 pcust (cdr pcust)
1101 plabel (cdr plabel)
1102 pcustg (cdr pcustg)
1103 printer (cdr printer)
1104 pprot (cdr pprot)
1105 pinit (cdr pinit))
1106 )) ;; while/let
1107 ;; Now duplicate all the class alloc slots.
1108 (let ((pa (eieio--class-class-allocation-a pcv))
1109 (pdoc (eieio--class-class-allocation-doc pcv))
1110 (ptype (eieio--class-class-allocation-type pcv))
1111 (pcust (eieio--class-class-allocation-custom pcv))
1112 (plabel (eieio--class-class-allocation-custom-label pcv))
1113 (pcustg (eieio--class-class-allocation-custom-group pcv))
1114 (printer (eieio--class-class-allocation-printer pcv))
1115 (pprot (eieio--class-class-allocation-protection pcv))
1116 (pval (eieio--class-class-allocation-values pcv))
1117 (i 0))
1118 (while pa
1119 (eieio-add-new-slot newc
1120 (car pa) (aref pval i) (car pdoc) (aref ptype i)
1121 (car pcust) (car plabel) (car pcustg)
1122 (car printer)
1123 (car pprot) nil ':class sn)
1124 ;; Increment each value.
1125 (setq pa (cdr pa)
1126 pdoc (cdr pdoc)
1127 pcust (cdr pcust)
1128 plabel (cdr plabel)
1129 pcustg (cdr pcustg)
1130 printer (cdr printer)
1131 pprot (cdr pprot)
1132 i (1+ i))
1133 ))) ;; while/let
1134 ;; Loop over each parent class
1135 (setq ps (cdr ps)))
1136 ))
1137
1138
1139;;; CLOS methods and generics
1140;;
1141
1142(defun eieio--defgeneric-init-form (method doc-string)
1143 "Form to use for the initial definition of a generic."
1144 (cond
1145 ((or (not (fboundp method))
1146 (eq 'autoload (car-safe (symbol-function method))))
1147 ;; Make sure the method tables are installed.
1148 (eieiomt-install method)
1149 ;; Construct the actual body of this function.
1150 (eieio-defgeneric-form method doc-string))
1151 ((generic-p method) (symbol-function method)) ;Leave it as-is.
1152 (t (error "You cannot create a generic/method over an existing symbol: %s"
1153 method))))
1154
1155(defun eieio-defgeneric-form (method doc-string)
1156 "The lambda form that would be used as the function defined on METHOD.
1157All methods should call the same EIEIO function for dispatch.
1158DOC-STRING is the documentation attached to METHOD."
1159 `(lambda (&rest local-args)
1160 ,doc-string
1161 (eieio-generic-call (quote ,method) local-args)))
1162
1163(defsubst eieio-defgeneric-reset-generic-form (method)
1164 "Setup METHOD to call the generic form."
1165 (let ((doc-string (documentation method)))
1166 (fset method (eieio-defgeneric-form method doc-string))))
1167
1168(defun eieio-defgeneric-form-primary-only (method doc-string)
1169 "The lambda form that would be used as the function defined on METHOD.
1170All methods should call the same EIEIO function for dispatch.
1171DOC-STRING is the documentation attached to METHOD."
1172 `(lambda (&rest local-args)
1173 ,doc-string
1174 (eieio-generic-call-primary-only (quote ,method) local-args)))
1175
1176(defsubst eieio-defgeneric-reset-generic-form-primary-only (method)
1177 "Setup METHOD to call the generic form."
1178 (let ((doc-string (documentation method)))
1179 (fset method (eieio-defgeneric-form-primary-only method doc-string))))
1180
1181(defun eieio-defgeneric-form-primary-only-one (method doc-string
1182 class
1183 impl
1184 )
1185 "The lambda form that would be used as the function defined on METHOD.
1186All methods should call the same EIEIO function for dispatch.
1187DOC-STRING is the documentation attached to METHOD.
1188CLASS is the class symbol needed for private method access.
1189IMPL is the symbol holding the method implementation."
1190 ;; NOTE: I tried out byte compiling this little fcn. Turns out it
1191 ;; is faster to execute this for not byte-compiled. ie, install this,
1192 ;; then measure calls going through here. I wonder why.
1193 (require 'bytecomp)
1194 (let ((byte-compile-warnings nil))
1195 (byte-compile
1196 `(lambda (&rest local-args)
1197 ,doc-string
1198 ;; This is a cool cheat. Usually we need to look up in the
1199 ;; method table to find out if there is a method or not. We can
1200 ;; instead make that determination at load time when there is
1201 ;; only one method. If the first arg is not a child of the class
1202 ;; of that one implementation, then clearly, there is no method def.
1203 (if (not (eieio-object-p (car local-args)))
1204 ;; Not an object. Just signal.
1205 (signal 'no-method-definition
1206 (list ',method local-args))
1207
1208 ;; We do have an object. Make sure it is the right type.
1209 (if ,(if (eq class eieio-default-superclass)
1210 nil ; default superclass means just an obj. Already asked.
1211 `(not (child-of-class-p (eieio--object-class (car local-args))
1212 ',class)))
1213
1214 ;; If not the right kind of object, call no applicable
1215 (apply 'no-applicable-method (car local-args)
1216 ',method local-args)
1217
1218 ;; It is ok, do the call.
1219 ;; Fill in inter-call variables then evaluate the method.
1220 (let ((eieio-generic-call-next-method-list nil)
1221 (eieio-generic-call-key method-primary)
1222 (eieio-generic-call-methodname ',method)
1223 (eieio-generic-call-arglst local-args)
1224 )
1225 (eieio--with-scoped-class ',class
1226 ,(if (< emacs-major-version 24)
1227 `(apply ,(list 'quote impl) local-args)
1228 `(apply #',impl local-args)))
1229 ;(,impl local-args)
1230 )))))))
1231
1232(defsubst eieio-defgeneric-reset-generic-form-primary-only-one (method)
1233 "Setup METHOD to call the generic form."
1234 (let* ((doc-string (documentation method))
1235 (M (get method 'eieio-method-tree))
1236 (entry (car (aref M method-primary)))
1237 )
1238 (fset method (eieio-defgeneric-form-primary-only-one
1239 method doc-string
1240 (car entry)
1241 (cdr entry)
1242 ))))
1243
1244(defun eieio-unbind-method-implementations (method)
1245 "Make the generic method METHOD have no implementations.
1246It will leave the original generic function in place,
1247but remove reference to all implementations of METHOD."
1248 (put method 'eieio-method-tree nil)
1249 (put method 'eieio-method-obarray nil))
1250
1251(defun eieio--defmethod (method kind argclass code)
1252 "Work part of the `defmethod' macro defining METHOD with ARGS."
1253 (let ((key
1254 ;; Find optional keys.
1255 (cond ((memq kind '(:BEFORE :before)) method-before)
1256 ((memq kind '(:AFTER :after)) method-after)
1257 ((memq kind '(:STATIC :static)) method-static)
1258 ((memq kind '(:PRIMARY :primary nil)) method-primary)
1259 ;; Primary key.
1260 ;; (t method-primary)
1261 (t (error "Unknown method kind %S" kind)))))
1262 ;; Make sure there is a generic (when called from defclass).
1263 (eieio--defalias
1264 method (eieio--defgeneric-init-form
1265 method (or (documentation code)
1266 (format "Generically created method `%s'." method))))
1267 ;; Create symbol for property to bind to. If the first arg is of
1268 ;; the form (varname vartype) and `vartype' is a class, then
1269 ;; that class will be the type symbol. If not, then it will fall
1270 ;; under the type `primary' which is a non-specific calling of the
1271 ;; function.
1272 (if argclass
1273 (if (not (class-p argclass))
1274 (error "Unknown class type %s in method parameters"
1275 argclass))
1276 ;; Generics are higher.
1277 (setq key (eieio-specialized-key-to-generic-key key)))
1278 ;; Put this lambda into the symbol so we can find it.
1279 (eieiomt-add method code key argclass)
1280 )
1281
1282 (when eieio-optimize-primary-methods-flag
1283 ;; Optimizing step:
1284 ;;
1285 ;; If this method, after this setup, only has primary methods, then
1286 ;; we can setup the generic that way.
1287 (if (generic-primary-only-p method)
1288 ;; If there is only one primary method, then we can go one more
1289 ;; optimization step.
1290 (if (generic-primary-only-one-p method)
1291 (eieio-defgeneric-reset-generic-form-primary-only-one method)
1292 (eieio-defgeneric-reset-generic-form-primary-only method))
1293 (eieio-defgeneric-reset-generic-form method)))
1294
1295 method)
1296
1297;;; Slot type validation
1298
1299;; This is a hideous hack for replacing `typep' from cl-macs, to avoid
1300;; requiring the CL library at run-time. It can be eliminated if/when
1301;; `typep' is merged into Emacs core.
1302(defun eieio--typep (val type)
1303 (if (symbolp type)
1304 (cond ((get type 'cl-deftype-handler)
1305 (eieio--typep val (funcall (get type 'cl-deftype-handler))))
1306 ((eq type t) t)
1307 ((eq type 'null) (null val))
1308 ((eq type 'atom) (atom val))
1309 ((eq type 'float) (and (numberp val) (not (integerp val))))
1310 ((eq type 'real) (numberp val))
1311 ((eq type 'fixnum) (integerp val))
1312 ((memq type '(character string-char)) (characterp val))
1313 (t
1314 (let* ((name (symbol-name type))
1315 (namep (intern (concat name "p"))))
1316 (if (fboundp namep)
1317 (funcall `(lambda () (,namep val)))
1318 (funcall `(lambda ()
1319 (,(intern (concat name "-p")) val)))))))
1320 (cond ((get (car type) 'cl-deftype-handler)
1321 (eieio--typep val (apply (get (car type) 'cl-deftype-handler)
1322 (cdr type))))
1323 ((memq (car type) '(integer float real number))
1324 (and (eieio--typep val (car type))
1325 (or (memq (cadr type) '(* nil))
1326 (if (consp (cadr type))
1327 (> val (car (cadr type)))
1328 (>= val (cadr type))))
1329 (or (memq (caddr type) '(* nil))
1330 (if (consp (car (cddr type)))
1331 (< val (caar (cddr type)))
1332 (<= val (car (cddr type)))))))
1333 ((memq (car type) '(and or not))
1334 (eval (cons (car type)
1335 (mapcar (lambda (x)
1336 `(eieio--typep (quote ,val) (quote ,x)))
1337 (cdr type)))))
1338 ((memq (car type) '(member member*))
1339 (memql val (cdr type)))
1340 ((eq (car type) 'satisfies)
1341 (funcall `(lambda () (,(cadr type) val))))
1342 (t (error "Bad type spec: %s" type)))))
1343
1344(defun eieio-perform-slot-validation (spec value)
1345 "Return non-nil if SPEC does not match VALUE."
1346 (or (eq spec t) ; t always passes
1347 (eq value eieio-unbound) ; unbound always passes
1348 (eieio--typep value spec)))
1349
1350(defun eieio-validate-slot-value (class slot-idx value slot)
1351 "Make sure that for CLASS referencing SLOT-IDX, VALUE is valid.
1352Checks the :type specifier.
1353SLOT is the slot that is being checked, and is only used when throwing
1354an error."
1355 (if eieio-skip-typecheck
1356 nil
1357 ;; Trim off object IDX junk added in for the object index.
1358 (setq slot-idx (- slot-idx 3))
1359 (let ((st (aref (eieio--class-public-type (class-v class)) slot-idx)))
1360 (if (not (eieio-perform-slot-validation st value))
1361 (signal 'invalid-slot-type (list class slot st value))))))
1362
1363(defun eieio-validate-class-slot-value (class slot-idx value slot)
1364 "Make sure that for CLASS referencing SLOT-IDX, VALUE is valid.
1365Checks the :type specifier.
1366SLOT is the slot that is being checked, and is only used when throwing
1367an error."
1368 (if eieio-skip-typecheck
1369 nil
1370 (let ((st (aref (eieio--class-class-allocation-type (class-v class))
1371 slot-idx)))
1372 (if (not (eieio-perform-slot-validation st value))
1373 (signal 'invalid-slot-type (list class slot st value))))))
1374
1375(defun eieio-barf-if-slot-unbound (value instance slotname fn)
1376 "Throw a signal if VALUE is a representation of an UNBOUND slot.
1377INSTANCE is the object being referenced. SLOTNAME is the offending
1378slot. If the slot is ok, return VALUE.
1379Argument FN is the function calling this verifier."
1380 (if (and (eq value eieio-unbound) (not eieio-skip-typecheck))
1381 (slot-unbound instance (eieio--object-class instance) slotname fn)
1382 value))
1383
1384
1385;;; Get/Set slots in an object.
1386;;
1387(defun eieio-oref (obj slot)
1388 "Return the value in OBJ at SLOT in the object vector."
1389 (eieio--check-type (or eieio-object-p class-p) obj)
1390 (eieio--check-type symbolp slot)
1391 (if (class-p obj) (eieio-class-un-autoload obj))
1392 (let* ((class (if (class-p obj) obj (eieio--object-class obj)))
1393 (c (eieio-slot-name-index class obj slot)))
1394 (if (not c)
1395 ;; It might be missing because it is a :class allocated slot.
1396 ;; Let's check that info out.
1397 (if (setq c (eieio-class-slot-name-index class slot))
1398 ;; Oref that slot.
1399 (aref (eieio--class-class-allocation-values (class-v class)) c)
1400 ;; The slot-missing method is a cool way of allowing an object author
1401 ;; to intercept missing slot definitions. Since it is also the LAST
1402 ;; thing called in this fn, its return value would be retrieved.
1403 (slot-missing obj slot 'oref)
1404 ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot))
1405 )
1406 (eieio--check-type eieio-object-p obj)
1407 (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref))))
1408
1409
1410(defun eieio-oref-default (obj slot)
1411 "Do the work for the macro `oref-default' with similar parameters.
1412Fills in OBJ's SLOT with its default value."
1413 (eieio--check-type (or eieio-object-p class-p) obj)
1414 (eieio--check-type symbolp slot)
1415 (let* ((cl (if (eieio-object-p obj) (eieio--object-class obj) obj))
1416 (c (eieio-slot-name-index cl obj slot)))
1417 (if (not c)
1418 ;; It might be missing because it is a :class allocated slot.
1419 ;; Let's check that info out.
1420 (if (setq c
1421 (eieio-class-slot-name-index cl slot))
1422 ;; Oref that slot.
1423 (aref (eieio--class-class-allocation-values (class-v cl))
1424 c)
1425 (slot-missing obj slot 'oref-default)
1426 ;;(signal 'invalid-slot-name (list (class-name cl) slot))
1427 )
1428 (eieio-barf-if-slot-unbound
1429 (let ((val (nth (- c 3) (eieio--class-public-d (class-v cl)))))
1430 (eieio-default-eval-maybe val))
1431 obj cl 'oref-default))))
1432
1433(defun eieio-default-eval-maybe (val)
1434 "Check VAL, and return what `oref-default' would provide."
1435 (cond
1436 ;; Is it a function call? If so, evaluate it.
1437 ((eieio-eval-default-p val)
1438 (eval val))
1439 ;;;; check for quoted things, and unquote them
1440 ;;((and (consp val) (eq (car val) 'quote))
1441 ;; (car (cdr val)))
1442 ;; return it verbatim
1443 (t val)))
1444
1445(defun eieio-oset (obj slot value)
1446 "Do the work for the macro `oset'.
1447Fills in OBJ's SLOT with VALUE."
1448 (eieio--check-type eieio-object-p obj)
1449 (eieio--check-type symbolp slot)
1450 (let ((c (eieio-slot-name-index (eieio--object-class obj) obj slot)))
1451 (if (not c)
1452 ;; It might be missing because it is a :class allocated slot.
1453 ;; Let's check that info out.
1454 (if (setq c
1455 (eieio-class-slot-name-index (eieio--object-class obj) slot))
1456 ;; Oset that slot.
1457 (progn
1458 (eieio-validate-class-slot-value (eieio--object-class obj) c value slot)
1459 (aset (eieio--class-class-allocation-values (class-v (eieio--object-class obj)))
1460 c value))
1461 ;; See oref for comment on `slot-missing'
1462 (slot-missing obj slot 'oset value)
1463 ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot))
1464 )
1465 (eieio-validate-slot-value (eieio--object-class obj) c value slot)
1466 (aset obj c value))))
1467
1468(defun eieio-oset-default (class slot value)
1469 "Do the work for the macro `oset-default'.
1470Fills in the default value in CLASS' in SLOT with VALUE."
1471 (eieio--check-type class-p class)
1472 (eieio--check-type symbolp slot)
1473 (eieio--with-scoped-class class
1474 (let* ((c (eieio-slot-name-index class nil slot)))
1475 (if (not c)
1476 ;; It might be missing because it is a :class allocated slot.
1477 ;; Let's check that info out.
1478 (if (setq c (eieio-class-slot-name-index class slot))
1479 (progn
1480 ;; Oref that slot.
1481 (eieio-validate-class-slot-value class c value slot)
1482 (aset (eieio--class-class-allocation-values (class-v class)) c
1483 value))
1484 (signal 'invalid-slot-name (list (eieio-class-name class) slot)))
1485 (eieio-validate-slot-value class c value slot)
1486 ;; Set this into the storage for defaults.
1487 (setcar (nthcdr (- c 3) (eieio--class-public-d (class-v class)))
1488 value)
1489 ;; Take the value, and put it into our cache object.
1490 (eieio-oset (eieio--class-default-object-cache (class-v class))
1491 slot value)
1492 ))))
1493
1494
1495;;; EIEIO internal search functions
1496;;
1497(defun eieio-slot-originating-class-p (start-class slot)
1498 "Return non-nil if START-CLASS is the first class to define SLOT.
1499This is for testing if the class currently in scope is the class that defines SLOT
1500so that we can protect private slots."
1501 (let ((par (eieio-class-parents-fast start-class))
1502 (ret t))
1503 (if (not par)
1504 t
1505 (while (and par ret)
1506 (if (intern-soft (symbol-name slot)
1507 (eieio--class-symbol-obarray (class-v (car par))))
1508 (setq ret nil))
1509 (setq par (cdr par)))
1510 ret)))
1511
1512(defun eieio-slot-name-index (class obj slot)
1513 "In CLASS for OBJ find the index of the named SLOT.
1514The slot is a symbol which is installed in CLASS by the `defclass'
1515call. OBJ can be nil, but if it is an object, and the slot in question
1516is protected, access will be allowed if OBJ is a child of the currently
1517scoped class.
1518If SLOT is the value created with :initarg instead,
1519reverse-lookup that name, and recurse with the associated slot value."
1520 ;; Removed checks to outside this call
1521 (let* ((fsym (intern-soft (symbol-name slot)
1522 (eieio--class-symbol-obarray (class-v class))))
1523 (fsi (if (symbolp fsym) (symbol-value fsym) nil)))
1524 (if (integerp fsi)
1525 (cond
1526 ((not (get fsym 'protection))
1527 (+ 3 fsi))
1528 ((and (eq (get fsym 'protection) 'protected)
1529 (eieio--scoped-class)
1530 (or (child-of-class-p class (eieio--scoped-class))
1531 (and (eieio-object-p obj)
1532 (child-of-class-p class (eieio--object-class obj)))))
1533 (+ 3 fsi))
1534 ((and (eq (get fsym 'protection) 'private)
1535 (or (and (eieio--scoped-class)
1536 (eieio-slot-originating-class-p (eieio--scoped-class) slot))
1537 eieio-initializing-object))
1538 (+ 3 fsi))
1539 (t nil))
1540 (let ((fn (eieio-initarg-to-attribute class slot)))
1541 (if fn (eieio-slot-name-index class obj fn) nil)))))
1542
1543(defun eieio-class-slot-name-index (class slot)
1544 "In CLASS find the index of the named SLOT.
1545The slot is a symbol which is installed in CLASS by the `defclass'
1546call. If SLOT is the value created with :initarg instead,
1547reverse-lookup that name, and recurse with the associated slot value."
1548 ;; This will happen less often, and with fewer slots. Do this the
1549 ;; storage cheap way.
1550 (let* ((a (eieio--class-class-allocation-a (class-v class)))
1551 (l1 (length a))
1552 (af (memq slot a))
1553 (l2 (length af)))
1554 ;; Slot # is length of the total list, minus the remaining list of
1555 ;; the found slot.
1556 (if af (- l1 l2))))
1557
1558;;;
1559;; Way to assign slots based on a list. Used for constructors, or
1560;; even resetting an object at run-time
1561;;
1562(defun eieio-set-defaults (obj &optional set-all)
1563 "Take object OBJ, and reset all slots to their defaults.
1564If SET-ALL is non-nil, then when a default is nil, that value is
1565reset. If SET-ALL is nil, the slots are only reset if the default is
1566not nil."
1567 (eieio--with-scoped-class (eieio--object-class obj)
1568 (let ((eieio-initializing-object t)
1569 (pub (eieio--class-public-a (class-v (eieio--object-class obj)))))
1570 (while pub
1571 (let ((df (eieio-oref-default obj (car pub))))
1572 (if (or df set-all)
1573 (eieio-oset obj (car pub) df)))
1574 (setq pub (cdr pub))))))
1575
1576(defun eieio-initarg-to-attribute (class initarg)
1577 "For CLASS, convert INITARG to the actual attribute name.
1578If there is no translation, pass it in directly (so we can cheat if
1579need be... May remove that later...)"
1580 (let ((tuple (assoc initarg (eieio--class-initarg-tuples (class-v class)))))
1581 (if tuple
1582 (cdr tuple)
1583 nil)))
1584
1585(defun eieio-attribute-to-initarg (class attribute)
1586 "In CLASS, convert the ATTRIBUTE into the corresponding init argument tag.
1587This is usually a symbol that starts with `:'."
1588 (let ((tuple (rassoc attribute (eieio--class-initarg-tuples (class-v class)))))
1589 (if tuple
1590 (car tuple)
1591 nil)))
1592
1593;;;
1594;; Method Invocation order: C3
1595(defun eieio-c3-candidate (class remaining-inputs)
1596 "Return CLASS if it can go in the result now, otherwise nil"
1597 ;; Ensure CLASS is not in any position but the first in any of the
1598 ;; element lists of REMAINING-INPUTS.
1599 (and (not (let ((found nil))
1600 (while (and remaining-inputs (not found))
1601 (setq found (member class (cdr (car remaining-inputs)))
1602 remaining-inputs (cdr remaining-inputs)))
1603 found))
1604 class))
1605
1606(defun eieio-c3-merge-lists (reversed-partial-result remaining-inputs)
1607 "Merge REVERSED-PARTIAL-RESULT REMAINING-INPUTS in a consistent order, if possible.
1608If a consistent order does not exist, signal an error."
1609 (if (let ((tail remaining-inputs)
1610 (found nil))
1611 (while (and tail (not found))
1612 (setq found (car tail) tail (cdr tail)))
1613 (not found))
1614 ;; If all remaining inputs are empty lists, we are done.
1615 (nreverse reversed-partial-result)
1616 ;; Otherwise, we try to find the next element of the result. This
1617 ;; is achieved by considering the first element of each
1618 ;; (non-empty) input list and accepting a candidate if it is
1619 ;; consistent with the rests of the input lists.
1620 (let* ((found nil)
1621 (tail remaining-inputs)
1622 (next (progn
1623 (while (and tail (not found))
1624 (setq found (and (car tail)
1625 (eieio-c3-candidate (caar tail)
1626 remaining-inputs))
1627 tail (cdr tail)))
1628 found)))
1629 (if next
1630 ;; The graph is consistent so far, add NEXT to result and
1631 ;; merge input lists, dropping NEXT from their heads where
1632 ;; applicable.
1633 (eieio-c3-merge-lists
1634 (cons next reversed-partial-result)
1635 (mapcar (lambda (l) (if (eq (first l) next) (rest l) l))
1636 remaining-inputs))
1637 ;; The graph is inconsistent, give up
1638 (signal 'inconsistent-class-hierarchy (list remaining-inputs))))))
1639
1640(defun eieio-class-precedence-c3 (class)
1641 "Return all parents of CLASS in c3 order."
1642 (let ((parents (eieio-class-parents-fast class)))
1643 (eieio-c3-merge-lists
1644 (list class)
1645 (append
1646 (or
1647 (mapcar
1648 (lambda (x)
1649 (eieio-class-precedence-c3 x))
1650 parents)
1651 '((eieio-default-superclass)))
1652 (list parents))))
1653 )
1654;;;
1655;; Method Invocation Order: Depth First
1656
1657(defun eieio-class-precedence-dfs (class)
1658 "Return all parents of CLASS in depth-first order."
1659 (let* ((parents (eieio-class-parents-fast class))
1660 (classes (copy-sequence
1661 (apply #'append
1662 (list class)
1663 (or
1664 (mapcar
1665 (lambda (parent)
1666 (cons parent
1667 (eieio-class-precedence-dfs parent)))
1668 parents)
1669 '((eieio-default-superclass))))))
1670 (tail classes))
1671 ;; Remove duplicates.
1672 (while tail
1673 (setcdr tail (delq (car tail) (cdr tail)))
1674 (setq tail (cdr tail)))
1675 classes))
1676
1677;;;
1678;; Method Invocation Order: Breadth First
1679(defun eieio-class-precedence-bfs (class)
1680 "Return all parents of CLASS in breadth-first order."
1681 (let ((result)
1682 (queue (or (eieio-class-parents-fast class)
1683 '(eieio-default-superclass))))
1684 (while queue
1685 (let ((head (pop queue)))
1686 (unless (member head result)
1687 (push head result)
1688 (unless (eq head 'eieio-default-superclass)
1689 (setq queue (append queue (or (eieio-class-parents-fast head)
1690 '(eieio-default-superclass))))))))
1691 (cons class (nreverse result)))
1692 )
1693
1694;;;
1695;; Method Invocation Order
1696
1697(defun eieio-class-precedence-list (class)
1698 "Return (transitively closed) list of parents of CLASS.
1699The order, in which the parents are returned depends on the
1700method invocation orders of the involved classes."
1701 (if (or (null class) (eq class 'eieio-default-superclass))
1702 nil
1703 (case (class-method-invocation-order class)
1704 (:depth-first
1705 (eieio-class-precedence-dfs class))
1706 (:breadth-first
1707 (eieio-class-precedence-bfs class))
1708 (:c3
1709 (eieio-class-precedence-c3 class))))
1710 )
1711(define-obsolete-function-alias
1712 'class-precedence-list 'eieio-class-precedence-list "24.4")
1713
1714
1715;;; CLOS generics internal function handling
1716;;
1717(defvar eieio-generic-call-methodname nil
1718 "When using `call-next-method', provides a context on how to do it.")
1719(defvar eieio-generic-call-arglst nil
1720 "When using `call-next-method', provides a context for parameters.")
1721(defvar eieio-generic-call-key nil
1722 "When using `call-next-method', provides a context for the current key.
1723Keys are a number representing :before, :primary, and :after methods.")
1724(defvar eieio-generic-call-next-method-list nil
1725 "When executing a PRIMARY or STATIC method, track the 'next-method'.
1726During executions, the list is first generated, then as each next method
1727is called, the next method is popped off the stack.")
1728
1729(define-obsolete-variable-alias 'eieio-pre-method-execution-hooks
1730 'eieio-pre-method-execution-functions "24.3")
1731(defvar eieio-pre-method-execution-functions nil
1732 "Abnormal hook run just before an EIEIO method is executed.
1733The hook function must accept one argument, the list of forms
1734about to be executed.")
1735
1736(defun eieio-generic-call (method args)
1737 "Call METHOD with ARGS.
1738ARGS provides the context on which implementation to use.
1739This should only be called from a generic function."
1740 ;; We must expand our arguments first as they are always
1741 ;; passed in as quoted symbols
1742 (let ((newargs nil) (mclass nil) (lambdas nil) (tlambdas nil) (keys nil)
1743 (eieio-generic-call-methodname method)
1744 (eieio-generic-call-arglst args)
1745 (firstarg nil)
1746 (primarymethodlist nil))
1747 ;; get a copy
1748 (setq newargs args
1749 firstarg (car newargs))
1750 ;; Is the class passed in autoloaded?
1751 ;; Since class names are also constructors, they can be autoloaded
1752 ;; via the autoload command. Check for this, and load them in.
1753 ;; It is ok if it doesn't turn out to be a class. Probably want that
1754 ;; function loaded anyway.
1755 (if (and (symbolp firstarg)
1756 (fboundp firstarg)
1757 (listp (symbol-function firstarg))
1758 (eq 'autoload (car (symbol-function firstarg))))
1759 (load (nth 1 (symbol-function firstarg))))
1760 ;; Determine the class to use.
1761 (cond ((eieio-object-p firstarg)
1762 (setq mclass (eieio--object-class firstarg)))
1763 ((class-p firstarg)
1764 (setq mclass firstarg))
1765 )
1766 ;; Make sure the class is a valid class
1767 ;; mclass can be nil (meaning a generic for should be used.
1768 ;; mclass cannot have a value that is not a class, however.
1769 (when (and (not (null mclass)) (not (class-p mclass)))
1770 (error "Cannot dispatch method %S on class %S"
1771 method mclass)
1772 )
1773 ;; Now create a list in reverse order of all the calls we have
1774 ;; make in order to successfully do this right. Rules:
1775 ;; 1) Only call generics if scoped-class is not defined
1776 ;; This prevents multiple calls in the case of recursion
1777 ;; 2) Only call static if this is a static method.
1778 ;; 3) Only call specifics if the definition allows for them.
1779 ;; 4) Call in order based on :before, :primary, and :after
1780 (when (eieio-object-p firstarg)
1781 ;; Non-static calls do all this stuff.
1782
1783 ;; :after methods
1784 (setq tlambdas
1785 (if mclass
1786 (eieiomt-method-list method method-after mclass)
1787 (list (eieio-generic-form method method-after nil)))
1788 ;;(or (and mclass (eieio-generic-form method method-after mclass))
1789 ;; (eieio-generic-form method method-after nil))
1790 )
1791 (setq lambdas (append tlambdas lambdas)
1792 keys (append (make-list (length tlambdas) method-after) keys))
1793
1794 ;; :primary methods
1795 (setq tlambdas
1796 (or (and mclass (eieio-generic-form method method-primary mclass))
1797 (eieio-generic-form method method-primary nil)))
1798 (when tlambdas
1799 (setq lambdas (cons tlambdas lambdas)
1800 keys (cons method-primary keys)
1801 primarymethodlist
1802 (eieiomt-method-list method method-primary mclass)))
1803
1804 ;; :before methods
1805 (setq tlambdas
1806 (if mclass
1807 (eieiomt-method-list method method-before mclass)
1808 (list (eieio-generic-form method method-before nil)))
1809 ;;(or (and mclass (eieio-generic-form method method-before mclass))
1810 ;; (eieio-generic-form method method-before nil))
1811 )
1812 (setq lambdas (append tlambdas lambdas)
1813 keys (append (make-list (length tlambdas) method-before) keys))
1814 )
1815
1816 (if mclass
1817 ;; For the case of a class,
1818 ;; if there were no methods found, then there could be :static methods.
1819 (when (not lambdas)
1820 (setq tlambdas
1821 (eieio-generic-form method method-static mclass))
1822 (setq lambdas (cons tlambdas lambdas)
1823 keys (cons method-static keys)
1824 primarymethodlist ;; Re-use even with bad name here
1825 (eieiomt-method-list method method-static mclass)))
1826 ;; For the case of no class (ie - mclass == nil) then there may
1827 ;; be a primary method.
1828 (setq tlambdas
1829 (eieio-generic-form method method-primary nil))
1830 (when tlambdas
1831 (setq lambdas (cons tlambdas lambdas)
1832 keys (cons method-primary keys)
1833 primarymethodlist
1834 (eieiomt-method-list method method-primary nil)))
1835 )
1836
1837 (run-hook-with-args 'eieio-pre-method-execution-functions
1838 primarymethodlist)
1839
1840 ;; Now loop through all occurrences forms which we must execute
1841 ;; (which are happily sorted now) and execute them all!
1842 (let ((rval nil) (lastval nil) (rvalever nil) (found nil))
1843 (while lambdas
1844 (if (car lambdas)
1845 (eieio--with-scoped-class (cdr (car lambdas))
1846 (let* ((eieio-generic-call-key (car keys))
1847 (has-return-val
1848 (or (= eieio-generic-call-key method-primary)
1849 (= eieio-generic-call-key method-static)))
1850 (eieio-generic-call-next-method-list
1851 ;; Use the cdr, as the first element is the fcn
1852 ;; we are calling right now.
1853 (when has-return-val (cdr primarymethodlist)))
1854 )
1855 (setq found t)
1856 ;;(setq rval (apply (car (car lambdas)) newargs))
1857 (setq lastval (apply (car (car lambdas)) newargs))
1858 (when has-return-val
1859 (setq rval lastval
1860 rvalever t))
1861 )))
1862 (setq lambdas (cdr lambdas)
1863 keys (cdr keys)))
1864 (if (not found)
1865 (if (eieio-object-p (car args))
1866 (setq rval (apply 'no-applicable-method (car args) method args)
1867 rvalever t)
1868 (signal
1869 'no-method-definition
1870 (list method args))))
1871 ;; Right Here... it could be that lastval is returned when
1872 ;; rvalever is nil. Is that right?
1873 rval)))
1874
1875(defun eieio-generic-call-primary-only (method args)
1876 "Call METHOD with ARGS for methods with only :PRIMARY implementations.
1877ARGS provides the context on which implementation to use.
1878This should only be called from a generic function.
1879
1880This method is like `eieio-generic-call', but only
1881implementations in the :PRIMARY slot are queried. After many
1882years of use, it appears that over 90% of methods in use
1883have :PRIMARY implementations only. We can therefore optimize
1884for this common case to improve performance."
1885 ;; We must expand our arguments first as they are always
1886 ;; passed in as quoted symbols
1887 (let ((newargs nil) (mclass nil) (lambdas nil)
1888 (eieio-generic-call-methodname method)
1889 (eieio-generic-call-arglst args)
1890 (firstarg nil)
1891 (primarymethodlist nil)
1892 )
1893 ;; get a copy
1894 (setq newargs args
1895 firstarg (car newargs))
1896
1897 ;; Determine the class to use.
1898 (cond ((eieio-object-p firstarg)
1899 (setq mclass (eieio--object-class firstarg)))
1900 ((not firstarg)
1901 (error "Method %s called on nil" method))
1902 ((not (eieio-object-p firstarg))
1903 (error "Primary-only method %s called on something not an object" method))
1904 (t
1905 (error "EIEIO Error: Improperly classified method %s as primary only"
1906 method)
1907 ))
1908 ;; Make sure the class is a valid class
1909 ;; mclass can be nil (meaning a generic for should be used.
1910 ;; mclass cannot have a value that is not a class, however.
1911 (when (null mclass)
1912 (error "Cannot dispatch method %S on class %S" method mclass)
1913 )
1914
1915 ;; :primary methods
1916 (setq lambdas (eieio-generic-form method method-primary mclass))
1917 (setq primarymethodlist ;; Re-use even with bad name here
1918 (eieiomt-method-list method method-primary mclass))
1919
1920 ;; Now loop through all occurrences forms which we must execute
1921 ;; (which are happily sorted now) and execute them all!
1922 (eieio--with-scoped-class (cdr lambdas)
1923 (let* ((rval nil) (lastval nil) (rvalever nil)
1924 (eieio-generic-call-key method-primary)
1925 ;; Use the cdr, as the first element is the fcn
1926 ;; we are calling right now.
1927 (eieio-generic-call-next-method-list (cdr primarymethodlist))
1928 )
1929
1930 (if (or (not lambdas) (not (car lambdas)))
1931
1932 ;; No methods found for this impl...
1933 (if (eieio-object-p (car args))
1934 (setq rval (apply 'no-applicable-method (car args) method args)
1935 rvalever t)
1936 (signal
1937 'no-method-definition
1938 (list method args)))
1939
1940 ;; Do the regular implementation here.
1941
1942 (run-hook-with-args 'eieio-pre-method-execution-functions
1943 lambdas)
1944
1945 (setq lastval (apply (car lambdas) newargs))
1946 (setq rval lastval
1947 rvalever t)
1948 )
1949
1950 ;; Right Here... it could be that lastval is returned when
1951 ;; rvalever is nil. Is that right?
1952 rval))))
1953
1954(defun eieiomt-method-list (method key class)
1955 "Return an alist list of methods lambdas.
1956METHOD is the method name.
1957KEY represents either :before, or :after methods.
1958CLASS is the starting class to search from in the method tree.
1959If CLASS is nil, then an empty list of methods should be returned."
1960 ;; Note: eieiomt - the MT means MethodTree. See more comments below
1961 ;; for the rest of the eieiomt methods.
1962
1963 ;; Collect lambda expressions stored for the class and its parent
1964 ;; classes.
1965 (let (lambdas)
1966 (dolist (ancestor (eieio-class-precedence-list class))
1967 ;; Lookup the form to use for the PRIMARY object for the next level
1968 (let ((tmpl (eieio-generic-form method key ancestor)))
1969 (when (and tmpl
1970 (or (not lambdas)
1971 ;; This prevents duplicates coming out of the
1972 ;; class method optimizer. Perhaps we should
1973 ;; just not optimize before/afters?
1974 (not (member tmpl lambdas))))
1975 (push tmpl lambdas))))
1976
1977 ;; Return collected lambda. For :after methods, return in current
1978 ;; order (most general class last); Otherwise, reverse order.
1979 (if (eq key method-after)
1980 lambdas
1981 (nreverse lambdas))))
1982
1983
1984;;;
1985;; eieio-method-tree : eieiomt-
1986;;
1987;; Stored as eieio-method-tree in property list of a generic method
1988;;
1989;; (eieio-method-tree . [BEFORE PRIMARY AFTER
1990;; genericBEFORE genericPRIMARY genericAFTER])
1991;; and
1992;; (eieio-method-obarray . [BEFORE PRIMARY AFTER
1993;; genericBEFORE genericPRIMARY genericAFTER])
1994;; where the association is a vector.
1995;; (aref 0 -- all static methods.
1996;; (aref 1 -- all methods classified as :before
1997;; (aref 2 -- all methods classified as :primary
1998;; (aref 3 -- all methods classified as :after
1999;; (aref 4 -- a generic classified as :before
2000;; (aref 5 -- a generic classified as :primary
2001;; (aref 6 -- a generic classified as :after
2002;;
2003(defvar eieiomt-optimizing-obarray nil
2004 "While mapping atoms, this contain the obarray being optimized.")
2005
2006(defun eieiomt-install (method-name)
2007 "Install the method tree, and obarray onto METHOD-NAME.
2008Do not do the work if they already exist."
2009 (let ((emtv (get method-name 'eieio-method-tree))
2010 (emto (get method-name 'eieio-method-obarray)))
2011 (if (or (not emtv) (not emto))
2012 (progn
2013 (setq emtv (put method-name 'eieio-method-tree
2014 (make-vector method-num-slots nil))
2015 emto (put method-name 'eieio-method-obarray
2016 (make-vector method-num-slots nil)))
2017 (aset emto 0 (make-vector 11 0))
2018 (aset emto 1 (make-vector 11 0))
2019 (aset emto 2 (make-vector 41 0))
2020 (aset emto 3 (make-vector 11 0))
2021 ))))
2022
2023(defun eieiomt-add (method-name method key class)
2024 "Add to METHOD-NAME the forms METHOD in a call position KEY for CLASS.
2025METHOD-NAME is the name created by a call to `defgeneric'.
2026METHOD are the forms for a given implementation.
2027KEY is an integer (see comment in eieio.el near this function) which
2028is associated with the :static :before :primary and :after tags.
2029It also indicates if CLASS is defined or not.
2030CLASS is the class this method is associated with."
2031 (if (or (> key method-num-slots) (< key 0))
2032 (error "eieiomt-add: method key error!"))
2033 (let ((emtv (get method-name 'eieio-method-tree))
2034 (emto (get method-name 'eieio-method-obarray)))
2035 ;; Make sure the method tables are available.
2036 (if (or (not emtv) (not emto))
2037 (error "Programmer error: eieiomt-add"))
2038 ;; only add new cells on if it doesn't already exist!
2039 (if (assq class (aref emtv key))
2040 (setcdr (assq class (aref emtv key)) method)
2041 (aset emtv key (cons (cons class method) (aref emtv key))))
2042 ;; Add function definition into newly created symbol, and store
2043 ;; said symbol in the correct obarray, otherwise use the
2044 ;; other array to keep this stuff
2045 (if (< key method-num-lists)
2046 (let ((nsym (intern (symbol-name class) (aref emto key))))
2047 (fset nsym method)))
2048 ;; Save the defmethod file location in a symbol property.
2049 (let ((fname (if load-in-progress
2050 load-file-name
2051 buffer-file-name))
2052 loc)
2053 (when fname
2054 (when (string-match "\\.elc$" fname)
2055 (setq fname (substring fname 0 (1- (length fname)))))
2056 (setq loc (get method-name 'method-locations))
2057 (pushnew (list class fname) loc :test 'equal)
2058 (put method-name 'method-locations loc)))
2059 ;; Now optimize the entire obarray
2060 (if (< key method-num-lists)
2061 (let ((eieiomt-optimizing-obarray (aref emto key)))
2062 ;; @todo - Is this overkill? Should we just clear the symbol?
2063 (mapatoms 'eieiomt-sym-optimize eieiomt-optimizing-obarray)))
2064 ))
2065
2066(defun eieiomt-next (class)
2067 "Return the next parent class for CLASS.
2068If CLASS is a superclass, return variable `eieio-default-superclass'.
2069If CLASS is variable `eieio-default-superclass' then return nil.
2070This is different from function `class-parent' as class parent returns
2071nil for superclasses. This function performs no type checking!"
2072 ;; No type-checking because all calls are made from functions which
2073 ;; are safe and do checking for us.
2074 (or (eieio-class-parents-fast class)
2075 (if (eq class 'eieio-default-superclass)
2076 nil
2077 '(eieio-default-superclass))))
2078
2079(defun eieiomt-sym-optimize (s)
2080 "Find the next class above S which has a function body for the optimizer."
2081 ;; Set the value to nil in case there is no nearest cell.
2082 (set s nil)
2083 ;; Find the nearest cell that has a function body. If we find one,
2084 ;; we replace the nil from above.
2085 (let ((external-symbol (intern-soft (symbol-name s))))
2086 (catch 'done
2087 (dolist (ancestor (rest (eieio-class-precedence-list external-symbol)))
2088 (let ((ov (intern-soft (symbol-name ancestor)
2089 eieiomt-optimizing-obarray)))
2090 (when (fboundp ov)
2091 (set s ov) ;; store ov as our next symbol
2092 (throw 'done ancestor)))))))
2093
2094(defun eieio-generic-form (method key class)
2095 "Return the lambda form belonging to METHOD using KEY based upon CLASS.
2096If CLASS is not a class then use `generic' instead. If class has
2097no form, but has a parent class, then trace to that parent class.
2098The first time a form is requested from a symbol, an optimized path
2099is memorized for faster future use."
2100 (let ((emto (aref (get method 'eieio-method-obarray)
2101 (if class key (eieio-specialized-key-to-generic-key key)))))
2102 (if (class-p class)
2103 ;; 1) find our symbol
2104 (let ((cs (intern-soft (symbol-name class) emto)))
2105 (if (not cs)
2106 ;; 2) If there isn't one, then make one.
2107 ;; This can be slow since it only occurs once
2108 (progn
2109 (setq cs (intern (symbol-name class) emto))
2110 ;; 2.1) Cache its nearest neighbor with a quick optimize
2111 ;; which should only occur once for this call ever
2112 (let ((eieiomt-optimizing-obarray emto))
2113 (eieiomt-sym-optimize cs))))
2114 ;; 3) If it's bound return this one.
2115 (if (fboundp cs)
2116 (cons cs (eieio--class-symbol (class-v class)))
2117 ;; 4) If it's not bound then this variable knows something
2118 (if (symbol-value cs)
2119 (progn
2120 ;; 4.1) This symbol holds the next class in its value
2121 (setq class (symbol-value cs)
2122 cs (intern-soft (symbol-name class) emto))
2123 ;; 4.2) The optimizer should always have chosen a
2124 ;; function-symbol
2125 ;;(if (fboundp cs)
2126 (cons cs (eieio--class-symbol (class-v (intern (symbol-name class)))))
2127 ;;(error "EIEIO optimizer: erratic data loss!"))
2128 )
2129 ;; There never will be a funcall...
2130 nil)))
2131 ;; for a generic call, what is a list, is the function body we want.
2132 (let ((emtl (aref (get method 'eieio-method-tree)
2133 (if class key (eieio-specialized-key-to-generic-key key)))))
2134 (if emtl
2135 ;; The car of EMTL is supposed to be a class, which in this
2136 ;; case is nil, so skip it.
2137 (cons (cdr (car emtl)) nil)
2138 nil)))))
2139
2140
2141;;; Here are some special types of errors
2142;;
2143(intern "no-method-definition")
2144(put 'no-method-definition 'error-conditions '(no-method-definition error))
2145(put 'no-method-definition 'error-message "No method definition")
2146
2147(intern "no-next-method")
2148(put 'no-next-method 'error-conditions '(no-next-method error))
2149(put 'no-next-method 'error-message "No next method")
2150
2151(intern "invalid-slot-name")
2152(put 'invalid-slot-name 'error-conditions '(invalid-slot-name error))
2153(put 'invalid-slot-name 'error-message "Invalid slot name")
2154
2155(intern "invalid-slot-type")
2156(put 'invalid-slot-type 'error-conditions '(invalid-slot-type error nil))
2157(put 'invalid-slot-type 'error-message "Invalid slot type")
2158
2159(intern "unbound-slot")
2160(put 'unbound-slot 'error-conditions '(unbound-slot error nil))
2161(put 'unbound-slot 'error-message "Unbound slot")
2162
2163(intern "inconsistent-class-hierarchy")
2164(put 'inconsistent-class-hierarchy 'error-conditions
2165 '(inconsistent-class-hierarchy error nil))
2166(put 'inconsistent-class-hierarchy 'error-message "Inconsistent class hierarchy")
2167
2168;;; Obsolete backward compatibility functions.
2169;; Needed to run byte-code compiled with the EIEIO of Emacs-23.
2170
2171(defun eieio-defmethod (method args)
2172 "Obsolete work part of an old version of the `defmethod' macro."
2173 (let ((key nil) (body nil) (firstarg nil) (argfix nil) (argclass nil) loopa)
2174 ;; find optional keys
2175 (setq key
2176 (cond ((memq (car args) '(:BEFORE :before))
2177 (setq args (cdr args))
2178 method-before)
2179 ((memq (car args) '(:AFTER :after))
2180 (setq args (cdr args))
2181 method-after)
2182 ((memq (car args) '(:STATIC :static))
2183 (setq args (cdr args))
2184 method-static)
2185 ((memq (car args) '(:PRIMARY :primary))
2186 (setq args (cdr args))
2187 method-primary)
2188 ;; Primary key.
2189 (t method-primary)))
2190 ;; Get body, and fix contents of args to be the arguments of the fn.
2191 (setq body (cdr args)
2192 args (car args))
2193 (setq loopa args)
2194 ;; Create a fixed version of the arguments.
2195 (while loopa
2196 (setq argfix (cons (if (listp (car loopa)) (car (car loopa)) (car loopa))
2197 argfix))
2198 (setq loopa (cdr loopa)))
2199 ;; Make sure there is a generic.
2200 (eieio-defgeneric
2201 method
2202 (if (stringp (car body))
2203 (car body) (format "Generically created method `%s'." method)))
2204 ;; create symbol for property to bind to. If the first arg is of
2205 ;; the form (varname vartype) and `vartype' is a class, then
2206 ;; that class will be the type symbol. If not, then it will fall
2207 ;; under the type `primary' which is a non-specific calling of the
2208 ;; function.
2209 (setq firstarg (car args))
2210 (if (listp firstarg)
2211 (progn
2212 (setq argclass (nth 1 firstarg))
2213 (if (not (class-p argclass))
2214 (error "Unknown class type %s in method parameters"
2215 (nth 1 firstarg))))
2216 ;; Generics are higher.
2217 (setq key (eieio-specialized-key-to-generic-key key)))
2218 ;; Put this lambda into the symbol so we can find it.
2219 (if (byte-code-function-p (car-safe body))
2220 (eieiomt-add method (car-safe body) key argclass)
2221 (eieiomt-add method (append (list 'lambda (reverse argfix)) body)
2222 key argclass))
2223 )
2224
2225 (when eieio-optimize-primary-methods-flag
2226 ;; Optimizing step:
2227 ;;
2228 ;; If this method, after this setup, only has primary methods, then
2229 ;; we can setup the generic that way.
2230 (if (generic-primary-only-p method)
2231 ;; If there is only one primary method, then we can go one more
2232 ;; optimization step.
2233 (if (generic-primary-only-one-p method)
2234 (eieio-defgeneric-reset-generic-form-primary-only-one method)
2235 (eieio-defgeneric-reset-generic-form-primary-only method))
2236 (eieio-defgeneric-reset-generic-form method)))
2237
2238 method)
2239(make-obsolete 'eieio-defmethod 'eieio--defmethod "24.1")
2240
2241(defun eieio-defgeneric (method doc-string)
2242 "Obsolete work part of an old version of the `defgeneric' macro."
2243 (if (and (fboundp method) (not (generic-p method))
2244 (or (byte-code-function-p (symbol-function method))
2245 (not (eq 'autoload (car (symbol-function method)))))
2246 )
2247 (error "You cannot create a generic/method over an existing symbol: %s"
2248 method))
2249 ;; Don't do this over and over.
2250 (unless (fboundp 'method)
2251 ;; This defun tells emacs where the first definition of this
2252 ;; method is defined.
2253 `(defun ,method nil)
2254 ;; Make sure the method tables are installed.
2255 (eieiomt-install method)
2256 ;; Apply the actual body of this function.
2257 (fset method (eieio-defgeneric-form method doc-string))
2258 ;; Return the method
2259 'method))
2260(make-obsolete 'eieio-defgeneric nil "24.1")
2261
2262(provide 'eieio-core)
2263
2264;;; eieio-core.el ends here
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 37b1ec5fa94..3cdf1f078bd 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -54,223 +54,7 @@
54 (interactive) 54 (interactive)
55 (message eieio-version)) 55 (message eieio-version))
56 56
57(eval-and-compile 57(require 'eieio-core)
58;; About the above. EIEIO must process its own code when it compiles
59;; itself, thus, by eval-and-compiling ourselves, we solve the problem.
60
61;; Compatibility
62(if (fboundp 'compiled-function-arglist)
63
64 ;; XEmacs can only access a compiled functions arglist like this:
65 (defalias 'eieio-compiled-function-arglist 'compiled-function-arglist)
66
67 ;; Emacs doesn't have this function, but since FUNC is a vector, we can just
68 ;; grab the appropriate element.
69 (defun eieio-compiled-function-arglist (func)
70 "Return the argument list for the compiled function FUNC."
71 (aref func 0))
72
73 )
74
75
76;;;
77;; Variable declarations.
78;;
79
80(defvar eieio-hook nil
81 "This hook is executed, then cleared each time `defclass' is called.")
82
83(defvar eieio-error-unsupported-class-tags nil
84 "Non-nil to throw an error if an encountered tag is unsupported.
85This may prevent classes from CLOS applications from being used with EIEIO
86since EIEIO does not support all CLOS tags.")
87
88(defvar eieio-skip-typecheck nil
89 "If non-nil, skip all slot typechecking.
90Set this to t permanently if a program is functioning well to get a
91small speed increase. This variable is also used internally to handle
92default setting for optimization purposes.")
93
94(defvar eieio-optimize-primary-methods-flag t
95 "Non-nil means to optimize the method dispatch on primary methods.")
96
97(defvar eieio-initializing-object nil
98 "Set to non-nil while initializing an object.")
99
100(defconst eieio-unbound
101 (if (and (boundp 'eieio-unbound) (symbolp eieio-unbound))
102 eieio-unbound
103 (make-symbol "unbound"))
104 "Uninterned symbol representing an unbound slot in an object.")
105
106;; This is a bootstrap for eieio-default-superclass so it has a value
107;; while it is being built itself.
108(defvar eieio-default-superclass nil))
109
110(defmacro eieio--define-field-accessors (prefix fields)
111 (declare (indent 1))
112 (let ((index 0)
113 (defs '()))
114 (dolist (field fields)
115 (let ((doc (if (listp field)
116 (prog1 (cadr field) (setq field (car field))))))
117 (push `(defmacro ,(intern (format "eieio--%s-%s" prefix field)) (x)
118 ,@(if doc (list (format (if (string-match "\n" doc)
119 "Return %s" "Return %s of a %s.")
120 doc prefix)))
121 (list 'aref x ,index))
122 defs)
123 (setq index (1+ index))))
124 `(eval-and-compile
125 ,@(nreverse defs)
126 (defconst ,(intern (format "eieio--%s-num-slots" prefix)) ,index))))
127
128(eieio--define-field-accessors class
129 (-unused-0 ;;FIXME: not sure, but at least there was no accessor!
130 (symbol "symbol (self-referencing)")
131 parent children
132 (symbol-obarray "obarray permitting fast access to variable position indexes")
133 ;; @todo
134 ;; the word "public" here is leftovers from the very first version.
135 ;; Get rid of it!
136 (public-a "class attribute index")
137 (public-d "class attribute defaults index")
138 (public-doc "class documentation strings for attributes")
139 (public-type "class type for a slot")
140 (public-custom "class custom type for a slot")
141 (public-custom-label "class custom group for a slot")
142 (public-custom-group "class custom group for a slot")
143 (public-printer "printer for a slot")
144 (protection "protection for a slot")
145 (initarg-tuples "initarg tuples list")
146 (class-allocation-a "class allocated attributes")
147 (class-allocation-doc "class allocated documentation")
148 (class-allocation-type "class allocated value type")
149 (class-allocation-custom "class allocated custom descriptor")
150 (class-allocation-custom-label "class allocated custom descriptor")
151 (class-allocation-custom-group "class allocated custom group")
152 (class-allocation-printer "class allocated printer for a slot")
153 (class-allocation-protection "class allocated protection list")
154 (class-allocation-values "class allocated value vector")
155 (default-object-cache "what a newly created object would look like.
156This will speed up instantiation time as only a `copy-sequence' will
157be needed, instead of looping over all the values and setting them
158from the default.")
159 (options "storage location of tagged class options.
160Stored outright without modifications or stripping.")))
161
162(eieio--define-field-accessors object
163 (-unused-0 ;;FIXME: not sure, but at least there was no accessor!
164 (class "class struct defining OBJ")
165 name))
166
167(eval-and-compile
168;; FIXME: The constants below should have an `eieio-' prefix added!!
169
170(defconst method-static 0 "Index into :static tag on a method.")
171(defconst method-before 1 "Index into :before tag on a method.")
172(defconst method-primary 2 "Index into :primary tag on a method.")
173(defconst method-after 3 "Index into :after tag on a method.")
174(defconst method-num-lists 4 "Number of indexes into methods vector in which groups of functions are kept.")
175(defconst method-generic-before 4 "Index into generic :before tag on a method.")
176(defconst method-generic-primary 5 "Index into generic :primary tag on a method.")
177(defconst method-generic-after 6 "Index into generic :after tag on a method.")
178(defconst method-num-slots 7 "Number of indexes into a method's vector.")
179
180(defsubst eieio-specialized-key-to-generic-key (key)
181 "Convert a specialized KEY into a generic method key."
182 (cond ((eq key method-static) 0) ;; don't convert
183 ((< key method-num-lists) (+ key 3)) ;; The conversion
184 (t key) ;; already generic.. maybe.
185 ))
186
187
188;;; Important macros used in eieio.
189;;
190(defmacro class-v (class)
191 "Internal: Return the class vector from the CLASS symbol."
192 ;; No check: If eieio gets this far, it's probably been checked already.
193 `(get ,class 'eieio-class-definition))
194
195(defmacro class-p (class)
196 "Return t if CLASS is a valid class vector.
197CLASS is a symbol."
198 ;; this new method is faster since it doesn't waste time checking lots of
199 ;; things.
200 `(condition-case nil
201 (eq (aref (class-v ,class) 0) 'defclass)
202 (error nil)))
203
204(defmacro eieio-object-p (obj)
205 "Return non-nil if OBJ is an EIEIO object."
206 `(condition-case nil
207 (let ((tobj ,obj))
208 (and (eq (aref tobj 0) 'object)
209 (class-p (eieio--object-class tobj))))
210 (error nil)))
211(defalias 'object-p 'eieio-object-p)
212
213(defmacro class-constructor (class)
214 "Return the symbol representing the constructor of CLASS."
215 `(eieio--class-symbol (class-v ,class)))
216
217(defmacro generic-p (method)
218 "Return t if symbol METHOD is a generic function.
219Only methods have the symbol `eieio-method-obarray' as a property
220\(which contains a list of all bindings to that method type.)"
221 `(and (fboundp ,method) (get ,method 'eieio-method-obarray)))
222
223(defun generic-primary-only-p (method)
224 "Return t if symbol METHOD is a generic function with only primary methods.
225Only methods have the symbol `eieio-method-obarray' as a property (which
226contains a list of all bindings to that method type.)
227Methods with only primary implementations are executed in an optimized way."
228 (and (generic-p method)
229 (let ((M (get method 'eieio-method-tree)))
230 (and (< 0 (length (aref M method-primary)))
231 (not (aref M method-static))
232 (not (aref M method-before))
233 (not (aref M method-after))
234 (not (aref M method-generic-before))
235 (not (aref M method-generic-primary))
236 (not (aref M method-generic-after))))
237 ))
238
239(defun generic-primary-only-one-p (method)
240 "Return t if symbol METHOD is a generic function with only primary methods.
241Only methods have the symbol `eieio-method-obarray' as a property (which
242contains a list of all bindings to that method type.)
243Methods with only primary implementations are executed in an optimized way."
244 (and (generic-p method)
245 (let ((M (get method 'eieio-method-tree)))
246 (and (= 1 (length (aref M method-primary)))
247 (not (aref M method-static))
248 (not (aref M method-before))
249 (not (aref M method-after))
250 (not (aref M method-generic-before))
251 (not (aref M method-generic-primary))
252 (not (aref M method-generic-after))))
253 ))
254
255(defmacro class-option-assoc (list option)
256 "Return from LIST the found OPTION, or nil if it doesn't exist."
257 `(car-safe (cdr (memq ,option ,list))))
258
259(defmacro class-option (class option)
260 "Return the value stored for CLASS' OPTION.
261Return nil if that option doesn't exist."
262 `(class-option-assoc (eieio--class-options (class-v ,class)) ',option))
263
264(defmacro class-abstract-p (class)
265 "Return non-nil if CLASS is abstract.
266Abstract classes cannot be instantiated."
267 `(class-option ,class :abstract))
268
269(defmacro class-method-invocation-order (class)
270 "Return the invocation order of CLASS.
271Abstract classes cannot be instantiated."
272 `(or (class-option ,class :method-invocation-order)
273 :breadth-first))
274 58
275 59
276;;; Defining a new class 60;;; Defining a new class
@@ -331,829 +115,8 @@ Options in CLOS not supported in EIEIO:
331 115
332Due to the way class options are set up, you can add any tags you wish, 116Due to the way class options are set up, you can add any tags you wish,
333and reference them using the function `class-option'." 117and reference them using the function `class-option'."
334 ;; We must `eval-and-compile' this so that when we byte compile 118 `(eieio-defclass ',name ',superclass ',slots ',options-and-doc))
335 ;; an eieio program, there is no need to load it ahead of time.
336 ;; It also provides lots of nice debugging errors at compile time.
337 `(eval-and-compile
338 (eieio-defclass ',name ',superclass ',slots ',options-and-doc)))
339
340(defvar eieio-defclass-autoload-map (make-vector 7 nil)
341 "Symbol map of superclasses we find in autoloads.")
342
343;; We autoload this because it's used in `make-autoload'.
344;;;###autoload
345(defun eieio-defclass-autoload (cname superclasses filename doc)
346 "Create autoload symbols for the EIEIO class CNAME.
347SUPERCLASSES are the superclasses that CNAME inherits from.
348DOC is the docstring for CNAME.
349This function creates a mock-class for CNAME and adds it into
350SUPERCLASSES as children.
351It creates an autoload function for CNAME's constructor."
352 ;; Assume we've already debugged inputs.
353
354 (let* ((oldc (when (class-p cname) (class-v cname)))
355 (newc (make-vector eieio--class-num-slots nil))
356 )
357 (if oldc
358 nil ;; Do nothing if we already have this class.
359
360 ;; Create the class in NEWC, but don't fill anything else in.
361 (aset newc 0 'defclass)
362 (setf (eieio--class-symbol newc) cname)
363
364 (let ((clear-parent nil))
365 ;; No parents?
366 (when (not superclasses)
367 (setq superclasses '(eieio-default-superclass)
368 clear-parent t)
369 )
370
371 ;; Hook our new class into the existing structures so we can
372 ;; autoload it later.
373 (dolist (SC superclasses)
374
375
376 ;; TODO - If we create an autoload that is in the map, that
377 ;; map needs to be cleared!
378
379
380 ;; Does our parent exist?
381 (if (not (class-p SC))
382
383 ;; Create a symbol for this parent, and then store this
384 ;; parent on that symbol.
385 (let ((sym (intern (symbol-name SC) eieio-defclass-autoload-map)))
386 (if (not (boundp sym))
387 (set sym (list cname))
388 (add-to-list sym cname))
389 )
390
391 ;; We have a parent, save the child in there.
392 (when (not (member cname (eieio--class-children (class-v SC))))
393 (setf (eieio--class-children (class-v SC))
394 (cons cname (eieio--class-children (class-v SC))))))
395
396 ;; save parent in child
397 (setf (eieio--class-parent newc) (cons SC (eieio--class-parent newc)))
398 )
399
400 ;; turn this into a usable self-pointing symbol
401 (set cname cname)
402
403 ;; Store the new class vector definition into the symbol. We need to
404 ;; do this first so that we can call defmethod for the accessor.
405 ;; The vector will be updated by the following while loop and will not
406 ;; need to be stored a second time.
407 (put cname 'eieio-class-definition newc)
408
409 ;; Clear the parent
410 (if clear-parent (setf (eieio--class-parent newc) nil))
411
412 ;; Create an autoload on top of our constructor function.
413 (autoload cname filename doc nil nil)
414 (autoload (intern (concat (symbol-name cname) "-p")) filename "" nil nil)
415 (autoload (intern (concat (symbol-name cname) "-child-p")) filename "" nil nil)
416 (autoload (intern (concat (symbol-name cname) "-list-p")) filename "" nil nil)
417
418 ))))
419
420(defsubst eieio-class-un-autoload (cname)
421 "If class CNAME is in an autoload state, load its file."
422 (when (eq (car-safe (symbol-function cname)) 'autoload)
423 (load-library (car (cdr (symbol-function cname))))))
424
425(defmacro eieio--check-type (type obj)
426 (unless (symbolp obj)
427 (error "eieio--check-type wants OBJ to be a variable"))
428 `(if (not ,(cond
429 ((eq 'or (car-safe type))
430 `(or ,@(mapcar (lambda (type) `(,type ,obj)) (cdr type))))
431 (t `(,type ,obj))))
432 (signal 'wrong-type-argument (list ',type ,obj))))
433
434(defun eieio-defclass (cname superclasses slots options-and-doc)
435 ;; FIXME: Most of this should be moved to the `defclass' macro.
436 "Define CNAME as a new subclass of SUPERCLASSES.
437SLOTS are the slots residing in that class definition, and options or
438documentation OPTIONS-AND-DOC is the toplevel documentation for this class.
439See `defclass' for more information."
440 ;; Run our eieio-hook each time, and clear it when we are done.
441 ;; This way people can add hooks safely if they want to modify eieio
442 ;; or add definitions when eieio is loaded or something like that.
443 (run-hooks 'eieio-hook)
444 (setq eieio-hook nil)
445
446 (eieio--check-type listp superclasses)
447
448 (let* ((pname superclasses)
449 (newc (make-vector eieio--class-num-slots nil))
450 (oldc (when (class-p cname) (class-v cname)))
451 (groups nil) ;; list of groups id'd from slots
452 (options nil)
453 (clearparent nil))
454
455 (aset newc 0 'defclass)
456 (setf (eieio--class-symbol newc) cname)
457
458 ;; If this class already existed, and we are updating its structure,
459 ;; make sure we keep the old child list. This can cause bugs, but
460 ;; if no new slots are created, it also saves time, and prevents
461 ;; method table breakage, particularly when the users is only
462 ;; byte compiling an EIEIO file.
463 (if oldc
464 (setf (eieio--class-children newc) (eieio--class-children oldc))
465 ;; If the old class did not exist, but did exist in the autoload map, then adopt those children.
466 ;; This is like the above, but deals with autoloads nicely.
467 (let ((sym (intern-soft (symbol-name cname) eieio-defclass-autoload-map)))
468 (when sym
469 (condition-case nil
470 (setf (eieio--class-children newc) (symbol-value sym))
471 (error nil))
472 (unintern (symbol-name cname) eieio-defclass-autoload-map)
473 ))
474 )
475
476 (cond ((and (stringp (car options-and-doc))
477 (/= 1 (% (length options-and-doc) 2)))
478 (error "Too many arguments to `defclass'"))
479 ((and (symbolp (car options-and-doc))
480 (/= 0 (% (length options-and-doc) 2)))
481 (error "Too many arguments to `defclass'"))
482 )
483
484 (setq options
485 (if (stringp (car options-and-doc))
486 (cons :documentation options-and-doc)
487 options-and-doc))
488
489 (if pname
490 (progn
491 (while pname
492 (if (and (car pname) (symbolp (car pname)))
493 (if (not (class-p (car pname)))
494 ;; bad class
495 (error "Given parent class %s is not a class" (car pname))
496 ;; good parent class...
497 ;; save new child in parent
498 (when (not (member cname (eieio--class-children (class-v (car pname)))))
499 (setf (eieio--class-children (class-v (car pname)))
500 (cons cname (eieio--class-children (class-v (car pname))))))
501 ;; Get custom groups, and store them into our local copy.
502 (mapc (lambda (g) (add-to-list 'groups g))
503 (class-option (car pname) :custom-groups))
504 ;; save parent in child
505 (setf (eieio--class-parent newc) (cons (car pname) (eieio--class-parent newc))))
506 (error "Invalid parent class %s" pname))
507 (setq pname (cdr pname)))
508 ;; Reverse the list of our parents so that they are prioritized in
509 ;; the same order as specified in the code.
510 (setf (eieio--class-parent newc) (nreverse (eieio--class-parent newc))) )
511 ;; If there is nothing to loop over, then inherit from the
512 ;; default superclass.
513 (unless (eq cname 'eieio-default-superclass)
514 ;; adopt the default parent here, but clear it later...
515 (setq clearparent t)
516 ;; save new child in parent
517 (if (not (member cname (eieio--class-children (class-v 'eieio-default-superclass))))
518 (setf (eieio--class-children (class-v 'eieio-default-superclass))
519 (cons cname (eieio--class-children (class-v 'eieio-default-superclass)))))
520 ;; save parent in child
521 (setf (eieio--class-parent newc) (list eieio-default-superclass))))
522
523 ;; turn this into a usable self-pointing symbol
524 (set cname cname)
525
526 ;; These two tests must be created right away so we can have self-
527 ;; referencing classes. ei, a class whose slot can contain only
528 ;; pointers to itself.
529
530 ;; Create the test function
531 (let ((csym (intern (concat (symbol-name cname) "-p"))))
532 (fset csym
533 (list 'lambda (list 'obj)
534 (format "Test OBJ to see if it an object of type %s" cname)
535 (list 'and '(eieio-object-p obj)
536 (list 'same-class-p 'obj cname)))))
537
538 ;; Make sure the method invocation order is a valid value.
539 (let ((io (class-option-assoc options :method-invocation-order)))
540 (when (and io (not (member io '(:depth-first :breadth-first :c3))))
541 (error "Method invocation order %s is not allowed" io)
542 ))
543
544 ;; Create a handy child test too
545 (let ((csym (intern (concat (symbol-name cname) "-child-p"))))
546 (fset csym
547 `(lambda (obj)
548 ,(format
549 "Test OBJ to see if it an object is a child of type %s"
550 cname)
551 (and (eieio-object-p obj)
552 (object-of-class-p obj ,cname))))
553
554 ;; Create a handy list of the class test too
555 (let ((csym (intern (concat (symbol-name cname) "-list-p"))))
556 (fset csym
557 `(lambda (obj)
558 ,(format
559 "Test OBJ to see if it a list of objects which are a child of type %s"
560 cname)
561 (when (listp obj)
562 (let ((ans t)) ;; nil is valid
563 ;; Loop over all the elements of the input list, test
564 ;; each to make sure it is a child of the desired object class.
565 (while (and obj ans)
566 (setq ans (and (eieio-object-p (car obj))
567 (object-of-class-p (car obj) ,cname)))
568 (setq obj (cdr obj)))
569 ans)))))
570
571 ;; When using typep, (typep OBJ 'myclass) returns t for objects which
572 ;; are subclasses of myclass. For our predicates, however, it is
573 ;; important for EIEIO to be backwards compatible, where
574 ;; myobject-p, and myobject-child-p are different.
575 ;; "cl" uses this technique to specify symbols with specific typep
576 ;; test, so we can let typep have the CLOS documented behavior
577 ;; while keeping our above predicate clean.
578
579 ;; It would be cleaner to use `defsetf' here, but that requires cl
580 ;; at runtime.
581 (put cname 'cl-deftype-handler
582 (list 'lambda () `(list 'satisfies (quote ,csym)))))
583
584 ;; Before adding new slots, let's add all the methods and classes
585 ;; in from the parent class.
586 (eieio-copy-parents-into-subclass newc superclasses)
587
588 ;; Store the new class vector definition into the symbol. We need to
589 ;; do this first so that we can call defmethod for the accessor.
590 ;; The vector will be updated by the following while loop and will not
591 ;; need to be stored a second time.
592 (put cname 'eieio-class-definition newc)
593
594 ;; Query each slot in the declaration list and mangle into the
595 ;; class structure I have defined.
596 (while slots
597 (let* ((slot1 (car slots))
598 (name (car slot1))
599 (slot (cdr slot1))
600 (acces (plist-get slot ':accessor))
601 (init (or (plist-get slot ':initform)
602 (if (member ':initform slot) nil
603 eieio-unbound)))
604 (initarg (plist-get slot ':initarg))
605 (docstr (plist-get slot ':documentation))
606 (prot (plist-get slot ':protection))
607 (reader (plist-get slot ':reader))
608 (writer (plist-get slot ':writer))
609 (alloc (plist-get slot ':allocation))
610 (type (plist-get slot ':type))
611 (custom (plist-get slot ':custom))
612 (label (plist-get slot ':label))
613 (customg (plist-get slot ':group))
614 (printer (plist-get slot ':printer))
615
616 (skip-nil (class-option-assoc options :allow-nil-initform))
617 )
618
619 (if eieio-error-unsupported-class-tags
620 (let ((tmp slot))
621 (while tmp
622 (if (not (member (car tmp) '(:accessor
623 :initform
624 :initarg
625 :documentation
626 :protection
627 :reader
628 :writer
629 :allocation
630 :type
631 :custom
632 :label
633 :group
634 :printer
635 :allow-nil-initform
636 :custom-groups)))
637 (signal 'invalid-slot-type (list (car tmp))))
638 (setq tmp (cdr (cdr tmp))))))
639
640 ;; Clean up the meaning of protection.
641 (cond ((or (eq prot 'public) (eq prot :public)) (setq prot nil))
642 ((or (eq prot 'protected) (eq prot :protected)) (setq prot 'protected))
643 ((or (eq prot 'private) (eq prot :private)) (setq prot 'private))
644 ((eq prot nil) nil)
645 (t (signal 'invalid-slot-type (list ':protection prot))))
646
647 ;; Make sure the :allocation parameter has a valid value.
648 (if (not (or (not alloc) (eq alloc :class) (eq alloc :instance)))
649 (signal 'invalid-slot-type (list ':allocation alloc)))
650
651 ;; The default type specifier is supposed to be t, meaning anything.
652 (if (not type) (setq type t))
653
654 ;; Label is nil, or a string
655 (if (not (or (null label) (stringp label)))
656 (signal 'invalid-slot-type (list ':label label)))
657
658 ;; Is there an initarg, but allocation of class?
659 (if (and initarg (eq alloc :class))
660 (message "Class allocated slots do not need :initarg"))
661
662 ;; intern the symbol so we can use it blankly
663 (if initarg (set initarg initarg))
664
665 ;; The customgroup should be a list of symbols
666 (cond ((null customg)
667 (setq customg '(default)))
668 ((not (listp customg))
669 (setq customg (list customg))))
670 ;; The customgroup better be a symbol, or list of symbols.
671 (mapc (lambda (cg)
672 (if (not (symbolp cg))
673 (signal 'invalid-slot-type (list ':group cg))))
674 customg)
675
676 ;; First up, add this slot into our new class.
677 (eieio-add-new-slot newc name init docstr type custom label customg printer
678 prot initarg alloc 'defaultoverride skip-nil)
679
680 ;; We need to id the group, and store them in a group list attribute.
681 (mapc (lambda (cg) (add-to-list 'groups cg)) customg)
682
683 ;; Anyone can have an accessor function. This creates a function
684 ;; of the specified name, and also performs a `defsetf' if applicable
685 ;; so that users can `setf' the space returned by this function.
686 (if acces
687 (progn
688 (eieio--defmethod
689 acces (if (eq alloc :class) :static :primary) cname
690 `(lambda (this)
691 ,(format
692 "Retrieves the slot `%s' from an object of class `%s'"
693 name cname)
694 (if (slot-boundp this ',name)
695 (eieio-oref this ',name)
696 ;; Else - Some error? nil?
697 nil)))
698
699 (if (fboundp 'gv-define-setter)
700 ;; FIXME: We should move more of eieio-defclass into the
701 ;; defclass macro so we don't have to use `eval' and require
702 ;; `gv' at run-time.
703 (eval `(gv-define-setter ,acces (eieio--store eieio--object)
704 (list 'eieio-oset eieio--object '',name
705 eieio--store)))
706 ;; Provide a setf method. It would be cleaner to use
707 ;; defsetf, but that would require CL at runtime.
708 (put acces 'setf-method
709 `(lambda (widget)
710 (let* ((--widget-sym-- (make-symbol "--widget--"))
711 (--store-sym-- (make-symbol "--store--")))
712 (list
713 (list --widget-sym--)
714 (list widget)
715 (list --store-sym--)
716 (list 'eieio-oset --widget-sym-- '',name
717 --store-sym--)
718 (list 'getfoo --widget-sym--))))))))
719
720 ;; If a writer is defined, then create a generic method of that
721 ;; name whose purpose is to set the value of the slot.
722 (if writer
723 (eieio--defmethod
724 writer nil cname
725 `(lambda (this value)
726 ,(format "Set the slot `%s' of an object of class `%s'"
727 name cname)
728 (setf (slot-value this ',name) value))))
729 ;; If a reader is defined, then create a generic method
730 ;; of that name whose purpose is to access this slot value.
731 (if reader
732 (eieio--defmethod
733 reader nil cname
734 `(lambda (this)
735 ,(format "Access the slot `%s' from object of class `%s'"
736 name cname)
737 (slot-value this ',name))))
738 )
739 (setq slots (cdr slots)))
740
741 ;; Now that everything has been loaded up, all our lists are backwards!
742 ;; Fix that up now.
743 (setf (eieio--class-public-a newc) (nreverse (eieio--class-public-a newc)))
744 (setf (eieio--class-public-d newc) (nreverse (eieio--class-public-d newc)))
745 (setf (eieio--class-public-doc newc) (nreverse (eieio--class-public-doc newc)))
746 (setf (eieio--class-public-type newc)
747 (apply 'vector (nreverse (eieio--class-public-type newc))))
748 (setf (eieio--class-public-custom newc) (nreverse (eieio--class-public-custom newc)))
749 (setf (eieio--class-public-custom-label newc) (nreverse (eieio--class-public-custom-label newc)))
750 (setf (eieio--class-public-custom-group newc) (nreverse (eieio--class-public-custom-group newc)))
751 (setf (eieio--class-public-printer newc) (nreverse (eieio--class-public-printer newc)))
752 (setf (eieio--class-protection newc) (nreverse (eieio--class-protection newc)))
753 (setf (eieio--class-initarg-tuples newc) (nreverse (eieio--class-initarg-tuples newc)))
754
755 ;; The storage for class-class-allocation-type needs to be turned into
756 ;; a vector now.
757 (setf (eieio--class-class-allocation-type newc)
758 (apply 'vector (eieio--class-class-allocation-type newc)))
759
760 ;; Also, take class allocated values, and vectorize them for speed.
761 (setf (eieio--class-class-allocation-values newc)
762 (apply 'vector (eieio--class-class-allocation-values newc)))
763
764 ;; Attach slot symbols into an obarray, and store the index of
765 ;; this slot as the variable slot in this new symbol. We need to
766 ;; know about primes, because obarrays are best set in vectors of
767 ;; prime number length, and we also need to make our vector small
768 ;; to save space, and also optimal for the number of items we have.
769 (let* ((cnt 0)
770 (pubsyms (eieio--class-public-a newc))
771 (prots (eieio--class-protection newc))
772 (l (length pubsyms))
773 (vl (let ((primes '( 3 5 7 11 13 17 19 23 29 31 37 41 43 47
774 53 59 61 67 71 73 79 83 89 97 101 )))
775 (while (and primes (< (car primes) l))
776 (setq primes (cdr primes)))
777 (car primes)))
778 (oa (make-vector vl 0))
779 (newsym))
780 (while pubsyms
781 (setq newsym (intern (symbol-name (car pubsyms)) oa))
782 (set newsym cnt)
783 (setq cnt (1+ cnt))
784 (if (car prots) (put newsym 'protection (car prots)))
785 (setq pubsyms (cdr pubsyms)
786 prots (cdr prots)))
787 (setf (eieio--class-symbol-obarray newc) oa)
788 )
789
790 ;; Create the constructor function
791 (if (class-option-assoc options :abstract)
792 ;; Abstract classes cannot be instantiated. Say so.
793 (let ((abs (class-option-assoc options :abstract)))
794 (if (not (stringp abs))
795 (setq abs (format "Class %s is abstract" cname)))
796 (fset cname
797 `(lambda (&rest stuff)
798 ,(format "You cannot create a new object of type %s" cname)
799 (error ,abs))))
800
801 ;; Non-abstract classes need a constructor.
802 (fset cname
803 `(lambda (newname &rest slots)
804 ,(format "Create a new object with name NAME of class type %s" cname)
805 (apply 'constructor ,cname newname slots)))
806 )
807
808 ;; Set up a specialized doc string.
809 ;; Use stored value since it is calculated in a non-trivial way
810 (put cname 'variable-documentation
811 (class-option-assoc options :documentation))
812
813 ;; Save the file location where this class is defined.
814 (let ((fname (if load-in-progress
815 load-file-name
816 buffer-file-name))
817 loc)
818 (when fname
819 (when (string-match "\\.elc\\'" fname)
820 (setq fname (substring fname 0 (1- (length fname)))))
821 (put cname 'class-location fname)))
822
823 ;; We have a list of custom groups. Store them into the options.
824 (let ((g (class-option-assoc options :custom-groups)))
825 (mapc (lambda (cg) (add-to-list 'g cg)) groups)
826 (if (memq :custom-groups options)
827 (setcar (cdr (memq :custom-groups options)) g)
828 (setq options (cons :custom-groups (cons g options)))))
829
830 ;; Set up the options we have collected.
831 (setf (eieio--class-options newc) options)
832
833 ;; if this is a superclass, clear out parent (which was set to the
834 ;; default superclass eieio-default-superclass)
835 (if clearparent (setf (eieio--class-parent newc) nil))
836
837 ;; Create the cached default object.
838 (let ((cache (make-vector (+ (length (eieio--class-public-a newc)) 3)
839 nil)))
840 (aset cache 0 'object)
841 (setf (eieio--object-class cache) cname)
842 (setf (eieio--object-name cache) 'default-cache-object)
843 (let ((eieio-skip-typecheck t))
844 ;; All type-checking has been done to our satisfaction
845 ;; before this call. Don't waste our time in this call..
846 (eieio-set-defaults cache t))
847 (setf (eieio--class-default-object-cache newc) cache))
848
849 ;; Return our new class object
850 ;; newc
851 cname
852 ))
853 119
854(defun eieio-perform-slot-validation-for-default (slot spec value skipnil)
855 "For SLOT, signal if SPEC does not match VALUE.
856If SKIPNIL is non-nil, then if VALUE is nil return t instead."
857 (if (and (not (eieio-eval-default-p value))
858 (not eieio-skip-typecheck)
859 (not (and skipnil (null value)))
860 (not (eieio-perform-slot-validation spec value)))
861 (signal 'invalid-slot-type (list slot spec value))))
862
863(defun eieio-add-new-slot (newc a d doc type cust label custg print prot init alloc
864 &optional defaultoverride skipnil)
865 "Add into NEWC attribute A.
866If A already exists in NEWC, then do nothing. If it doesn't exist,
867then also add in D (default), DOC, TYPE, CUST, LABEL, CUSTG, PRINT, PROT, and INIT arg.
868Argument ALLOC specifies if the slot is allocated per instance, or per class.
869If optional DEFAULTOVERRIDE is non-nil, then if A exists in NEWC,
870we must override its value for a default.
871Optional argument SKIPNIL indicates if type checking should be skipped
872if default value is nil."
873 ;; Make sure we duplicate those items that are sequences.
874 (condition-case nil
875 (if (sequencep d) (setq d (copy-sequence d)))
876 ;; This copy can fail on a cons cell with a non-cons in the cdr. Let's skip it if it doesn't work.
877 (error nil))
878 (if (sequencep type) (setq type (copy-sequence type)))
879 (if (sequencep cust) (setq cust (copy-sequence cust)))
880 (if (sequencep custg) (setq custg (copy-sequence custg)))
881
882 ;; To prevent override information w/out specification of storage,
883 ;; we need to do this little hack.
884 (if (member a (eieio--class-class-allocation-a newc)) (setq alloc ':class))
885
886 (if (or (not alloc) (and (symbolp alloc) (eq alloc ':instance)))
887 ;; In this case, we modify the INSTANCE version of a given slot.
888
889 (progn
890
891 ;; Only add this element if it is so-far unique
892 (if (not (member a (eieio--class-public-a newc)))
893 (progn
894 (eieio-perform-slot-validation-for-default a type d skipnil)
895 (setf (eieio--class-public-a newc) (cons a (eieio--class-public-a newc)))
896 (setf (eieio--class-public-d newc) (cons d (eieio--class-public-d newc)))
897 (setf (eieio--class-public-doc newc) (cons doc (eieio--class-public-doc newc)))
898 (setf (eieio--class-public-type newc) (cons type (eieio--class-public-type newc)))
899 (setf (eieio--class-public-custom newc) (cons cust (eieio--class-public-custom newc)))
900 (setf (eieio--class-public-custom-label newc) (cons label (eieio--class-public-custom-label newc)))
901 (setf (eieio--class-public-custom-group newc) (cons custg (eieio--class-public-custom-group newc)))
902 (setf (eieio--class-public-printer newc) (cons print (eieio--class-public-printer newc)))
903 (setf (eieio--class-protection newc) (cons prot (eieio--class-protection newc)))
904 (setf (eieio--class-initarg-tuples newc) (cons (cons init a) (eieio--class-initarg-tuples newc)))
905 )
906 ;; When defaultoverride is true, we are usually adding new local
907 ;; attributes which must override the default value of any slot
908 ;; passed in by one of the parent classes.
909 (when defaultoverride
910 ;; There is a match, and we must override the old value.
911 (let* ((ca (eieio--class-public-a newc))
912 (np (member a ca))
913 (num (- (length ca) (length np)))
914 (dp (if np (nthcdr num (eieio--class-public-d newc))
915 nil))
916 (tp (if np (nth num (eieio--class-public-type newc))))
917 )
918 (if (not np)
919 (error "EIEIO internal error overriding default value for %s"
920 a)
921 ;; If type is passed in, is it the same?
922 (if (not (eq type t))
923 (if (not (equal type tp))
924 (error
925 "Child slot type `%s' does not match inherited type `%s' for `%s'"
926 type tp a)))
927 ;; If we have a repeat, only update the initarg...
928 (unless (eq d eieio-unbound)
929 (eieio-perform-slot-validation-for-default a tp d skipnil)
930 (setcar dp d))
931 ;; If we have a new initarg, check for it.
932 (when init
933 (let* ((inits (eieio--class-initarg-tuples newc))
934 (inita (rassq a inits)))
935 ;; Replace the CAR of the associate INITA.
936 ;;(message "Initarg: %S replace %s" inita init)
937 (setcar inita init)
938 ))
939
940 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is
941 ;; checked and SHOULD match the superclass
942 ;; protection. Otherwise an error is thrown. However
943 ;; I wonder if a more flexible schedule might be
944 ;; implemented.
945 ;;
946 ;; EML - We used to have (if prot... here,
947 ;; but a prot of 'nil means public.
948 ;;
949 (let ((super-prot (nth num (eieio--class-protection newc)))
950 )
951 (if (not (eq prot super-prot))
952 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'"
953 prot super-prot a)))
954 ;; End original PLN
955
956 ;; PLN Tue Jun 26 11:57:06 2007 :
957 ;; Do a non redundant combination of ancient custom
958 ;; groups and new ones.
959 (when custg
960 (let* ((groups
961 (nthcdr num (eieio--class-public-custom-group newc)))
962 (list1 (car groups))
963 (list2 (if (listp custg) custg (list custg))))
964 (if (< (length list1) (length list2))
965 (setq list1 (prog1 list2 (setq list2 list1))))
966 (dolist (elt list2)
967 (unless (memq elt list1)
968 (push elt list1)))
969 (setcar groups list1)))
970 ;; End PLN
971
972 ;; PLN Mon Jun 25 22:44:34 2007 : If a new cust is
973 ;; set, simply replaces the old one.
974 (when cust
975 ;; (message "Custom type redefined to %s" cust)
976 (setcar (nthcdr num (eieio--class-public-custom newc)) cust))
977
978 ;; If a new label is specified, it simply replaces
979 ;; the old one.
980 (when label
981 ;; (message "Custom label redefined to %s" label)
982 (setcar (nthcdr num (eieio--class-public-custom-label newc)) label))
983 ;; End PLN
984
985 ;; PLN Sat Jun 30 17:24:42 2007 : when a new
986 ;; doc is specified, simply replaces the old one.
987 (when doc
988 ;;(message "Documentation redefined to %s" doc)
989 (setcar (nthcdr num (eieio--class-public-doc newc))
990 doc))
991 ;; End PLN
992
993 ;; If a new printer is specified, it simply replaces
994 ;; the old one.
995 (when print
996 ;; (message "printer redefined to %s" print)
997 (setcar (nthcdr num (eieio--class-public-printer newc)) print))
998
999 )))
1000 ))
1001
1002 ;; CLASS ALLOCATED SLOTS
1003 (let ((value (eieio-default-eval-maybe d)))
1004 (if (not (member a (eieio--class-class-allocation-a newc)))
1005 (progn
1006 (eieio-perform-slot-validation-for-default a type value skipnil)
1007 ;; Here we have found a :class version of a slot. This
1008 ;; requires a very different approach.
1009 (setf (eieio--class-class-allocation-a newc) (cons a (eieio--class-class-allocation-a newc)))
1010 (setf (eieio--class-class-allocation-doc newc) (cons doc (eieio--class-class-allocation-doc newc)))
1011 (setf (eieio--class-class-allocation-type newc) (cons type (eieio--class-class-allocation-type newc)))
1012 (setf (eieio--class-class-allocation-custom newc) (cons cust (eieio--class-class-allocation-custom newc)))
1013 (setf (eieio--class-class-allocation-custom-label newc) (cons label (eieio--class-class-allocation-custom-label newc)))
1014 (setf (eieio--class-class-allocation-custom-group newc) (cons custg (eieio--class-class-allocation-custom-group newc)))
1015 (setf (eieio--class-class-allocation-protection newc) (cons prot (eieio--class-class-allocation-protection newc)))
1016 ;; Default value is stored in the 'values section, since new objects
1017 ;; can't initialize from this element.
1018 (setf (eieio--class-class-allocation-values newc) (cons value (eieio--class-class-allocation-values newc))))
1019 (when defaultoverride
1020 ;; There is a match, and we must override the old value.
1021 (let* ((ca (eieio--class-class-allocation-a newc))
1022 (np (member a ca))
1023 (num (- (length ca) (length np)))
1024 (dp (if np
1025 (nthcdr num
1026 (eieio--class-class-allocation-values newc))
1027 nil))
1028 (tp (if np (nth num (eieio--class-class-allocation-type newc))
1029 nil)))
1030 (if (not np)
1031 (error "EIEIO internal error overriding default value for %s"
1032 a)
1033 ;; If type is passed in, is it the same?
1034 (if (not (eq type t))
1035 (if (not (equal type tp))
1036 (error
1037 "Child slot type `%s' does not match inherited type `%s' for `%s'"
1038 type tp a)))
1039 ;; EML - Note: the only reason to override a class bound slot
1040 ;; is to change the default, so allow unbound in.
1041
1042 ;; If we have a repeat, only update the value...
1043 (eieio-perform-slot-validation-for-default a tp value skipnil)
1044 (setcar dp value))
1045
1046 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is
1047 ;; checked and SHOULD match the superclass
1048 ;; protection. Otherwise an error is thrown. However
1049 ;; I wonder if a more flexible schedule might be
1050 ;; implemented.
1051 (let ((super-prot
1052 (car (nthcdr num (eieio--class-class-allocation-protection newc)))))
1053 (if (not (eq prot super-prot))
1054 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'"
1055 prot super-prot a)))
1056 ;; Do a non redundant combination of ancient custom groups
1057 ;; and new ones.
1058 (when custg
1059 (let* ((groups
1060 (nthcdr num (eieio--class-class-allocation-custom-group newc)))
1061 (list1 (car groups))
1062 (list2 (if (listp custg) custg (list custg))))
1063 (if (< (length list1) (length list2))
1064 (setq list1 (prog1 list2 (setq list2 list1))))
1065 (dolist (elt list2)
1066 (unless (memq elt list1)
1067 (push elt list1)))
1068 (setcar groups list1)))
1069
1070 ;; PLN Sat Jun 30 17:24:42 2007 : when a new
1071 ;; doc is specified, simply replaces the old one.
1072 (when doc
1073 ;;(message "Documentation redefined to %s" doc)
1074 (setcar (nthcdr num (eieio--class-class-allocation-doc newc))
1075 doc))
1076 ;; End PLN
1077
1078 ;; If a new printer is specified, it simply replaces
1079 ;; the old one.
1080 (when print
1081 ;; (message "printer redefined to %s" print)
1082 (setcar (nthcdr num (eieio--class-class-allocation-printer newc)) print))
1083
1084 ))
1085 ))
1086 ))
1087
1088(defun eieio-copy-parents-into-subclass (newc parents)
1089 "Copy into NEWC the slots of PARENTS.
1090Follow the rules of not overwriting early parents when applying to
1091the new child class."
1092 (let ((ps (eieio--class-parent newc))
1093 (sn (class-option-assoc (eieio--class-options newc)
1094 ':allow-nil-initform)))
1095 (while ps
1096 ;; First, duplicate all the slots of the parent.
1097 (let ((pcv (class-v (car ps))))
1098 (let ((pa (eieio--class-public-a pcv))
1099 (pd (eieio--class-public-d pcv))
1100 (pdoc (eieio--class-public-doc pcv))
1101 (ptype (eieio--class-public-type pcv))
1102 (pcust (eieio--class-public-custom pcv))
1103 (plabel (eieio--class-public-custom-label pcv))
1104 (pcustg (eieio--class-public-custom-group pcv))
1105 (printer (eieio--class-public-printer pcv))
1106 (pprot (eieio--class-protection pcv))
1107 (pinit (eieio--class-initarg-tuples pcv))
1108 (i 0))
1109 (while pa
1110 (eieio-add-new-slot newc
1111 (car pa) (car pd) (car pdoc) (aref ptype i)
1112 (car pcust) (car plabel) (car pcustg)
1113 (car printer)
1114 (car pprot) (car-safe (car pinit)) nil nil sn)
1115 ;; Increment each value.
1116 (setq pa (cdr pa)
1117 pd (cdr pd)
1118 pdoc (cdr pdoc)
1119 i (1+ i)
1120 pcust (cdr pcust)
1121 plabel (cdr plabel)
1122 pcustg (cdr pcustg)
1123 printer (cdr printer)
1124 pprot (cdr pprot)
1125 pinit (cdr pinit))
1126 )) ;; while/let
1127 ;; Now duplicate all the class alloc slots.
1128 (let ((pa (eieio--class-class-allocation-a pcv))
1129 (pdoc (eieio--class-class-allocation-doc pcv))
1130 (ptype (eieio--class-class-allocation-type pcv))
1131 (pcust (eieio--class-class-allocation-custom pcv))
1132 (plabel (eieio--class-class-allocation-custom-label pcv))
1133 (pcustg (eieio--class-class-allocation-custom-group pcv))
1134 (printer (eieio--class-class-allocation-printer pcv))
1135 (pprot (eieio--class-class-allocation-protection pcv))
1136 (pval (eieio--class-class-allocation-values pcv))
1137 (i 0))
1138 (while pa
1139 (eieio-add-new-slot newc
1140 (car pa) (aref pval i) (car pdoc) (aref ptype i)
1141 (car pcust) (car plabel) (car pcustg)
1142 (car printer)
1143 (car pprot) nil ':class sn)
1144 ;; Increment each value.
1145 (setq pa (cdr pa)
1146 pdoc (cdr pdoc)
1147 pcust (cdr pcust)
1148 plabel (cdr plabel)
1149 pcustg (cdr pcustg)
1150 printer (cdr printer)
1151 pprot (cdr pprot)
1152 i (1+ i))
1153 ))) ;; while/let
1154 ;; Loop over each parent class
1155 (setq ps (cdr ps)))
1156 ))
1157 120
1158;;; CLOS style implementation of object creators. 121;;; CLOS style implementation of object creators.
1159;; 122;;
@@ -1187,17 +150,6 @@ a string."
1187 150
1188;;; CLOS methods and generics 151;;; CLOS methods and generics
1189;; 152;;
1190
1191(put 'eieio--defalias 'byte-hunk-handler
1192 #'byte-compile-file-form-defalias) ;;(get 'defalias 'byte-hunk-handler)
1193(defun eieio--defalias (name body)
1194 "Like `defalias', but with less side-effects.
1195More specifically, it has no side-effects at all when the new function
1196definition is the same (`eq') as the old one."
1197 (unless (and (fboundp name)
1198 (eq (symbol-function name) body))
1199 (defalias name body)))
1200
1201(defmacro defgeneric (method args &optional doc-string) 153(defmacro defgeneric (method args &optional doc-string)
1202 "Create a generic function METHOD. 154 "Create a generic function METHOD.
1203DOC-STRING is the base documentation for this class. A generic 155DOC-STRING is the base documentation for this class. A generic
@@ -1209,115 +161,6 @@ top level documentation to a method."
1209 `(eieio--defalias ',method 161 `(eieio--defalias ',method
1210 (eieio--defgeneric-init-form ',method ,doc-string))) 162 (eieio--defgeneric-init-form ',method ,doc-string)))
1211 163
1212(defun eieio--defgeneric-init-form (method doc-string)
1213 "Form to use for the initial definition of a generic."
1214 (cond
1215 ((or (not (fboundp method))
1216 (eq 'autoload (car-safe (symbol-function method))))
1217 ;; Make sure the method tables are installed.
1218 (eieiomt-install method)
1219 ;; Construct the actual body of this function.
1220 (eieio-defgeneric-form method doc-string))
1221 ((generic-p method) (symbol-function method)) ;Leave it as-is.
1222 (t (error "You cannot create a generic/method over an existing symbol: %s"
1223 method))))
1224
1225(defun eieio-defgeneric-form (method doc-string)
1226 "The lambda form that would be used as the function defined on METHOD.
1227All methods should call the same EIEIO function for dispatch.
1228DOC-STRING is the documentation attached to METHOD."
1229 `(lambda (&rest local-args)
1230 ,doc-string
1231 (eieio-generic-call (quote ,method) local-args)))
1232
1233(defsubst eieio-defgeneric-reset-generic-form (method)
1234 "Setup METHOD to call the generic form."
1235 (let ((doc-string (documentation method)))
1236 (fset method (eieio-defgeneric-form method doc-string))))
1237
1238(defun eieio-defgeneric-form-primary-only (method doc-string)
1239 "The lambda form that would be used as the function defined on METHOD.
1240All methods should call the same EIEIO function for dispatch.
1241DOC-STRING is the documentation attached to METHOD."
1242 `(lambda (&rest local-args)
1243 ,doc-string
1244 (eieio-generic-call-primary-only (quote ,method) local-args)))
1245
1246(defsubst eieio-defgeneric-reset-generic-form-primary-only (method)
1247 "Setup METHOD to call the generic form."
1248 (let ((doc-string (documentation method)))
1249 (fset method (eieio-defgeneric-form-primary-only method doc-string))))
1250
1251(defun eieio-defgeneric-form-primary-only-one (method doc-string
1252 class
1253 impl
1254 )
1255 "The lambda form that would be used as the function defined on METHOD.
1256All methods should call the same EIEIO function for dispatch.
1257DOC-STRING is the documentation attached to METHOD.
1258CLASS is the class symbol needed for private method access.
1259IMPL is the symbol holding the method implementation."
1260 ;; NOTE: I tried out byte compiling this little fcn. Turns out it
1261 ;; is faster to execute this for not byte-compiled. ie, install this,
1262 ;; then measure calls going through here. I wonder why.
1263 (require 'bytecomp)
1264 (let ((byte-compile-warnings nil))
1265 (byte-compile
1266 `(lambda (&rest local-args)
1267 ,doc-string
1268 ;; This is a cool cheat. Usually we need to look up in the
1269 ;; method table to find out if there is a method or not. We can
1270 ;; instead make that determination at load time when there is
1271 ;; only one method. If the first arg is not a child of the class
1272 ;; of that one implementation, then clearly, there is no method def.
1273 (if (not (eieio-object-p (car local-args)))
1274 ;; Not an object. Just signal.
1275 (signal 'no-method-definition
1276 (list ',method local-args))
1277
1278 ;; We do have an object. Make sure it is the right type.
1279 (if ,(if (eq class eieio-default-superclass)
1280 nil ; default superclass means just an obj. Already asked.
1281 `(not (child-of-class-p (eieio--object-class (car local-args))
1282 ',class)))
1283
1284 ;; If not the right kind of object, call no applicable
1285 (apply 'no-applicable-method (car local-args)
1286 ',method local-args)
1287
1288 ;; It is ok, do the call.
1289 ;; Fill in inter-call variables then evaluate the method.
1290 (let ((scoped-class ',class)
1291 (eieio-generic-call-next-method-list nil)
1292 (eieio-generic-call-key method-primary)
1293 (eieio-generic-call-methodname ',method)
1294 (eieio-generic-call-arglst local-args)
1295 )
1296 ,(if (< emacs-major-version 24)
1297 `(apply ,(list 'quote impl) local-args)
1298 `(apply #',impl local-args))
1299 ;(,impl local-args)
1300 )))))))
1301
1302(defsubst eieio-defgeneric-reset-generic-form-primary-only-one (method)
1303 "Setup METHOD to call the generic form."
1304 (let* ((doc-string (documentation method))
1305 (M (get method 'eieio-method-tree))
1306 (entry (car (aref M method-primary)))
1307 )
1308 (fset method (eieio-defgeneric-form-primary-only-one
1309 method doc-string
1310 (car entry)
1311 (cdr entry)
1312 ))))
1313
1314(defun eieio-unbind-method-implementations (method)
1315 "Make the generic method METHOD have no implementations.
1316It will leave the original generic function in place,
1317but remove reference to all implementations of METHOD."
1318 (put method 'eieio-method-tree nil)
1319 (put method 'eieio-method-obarray nil))
1320
1321(defmacro defmethod (method &rest args) 164(defmacro defmethod (method &rest args)
1322 "Create a new METHOD through `defgeneric' with ARGS. 165 "Create a new METHOD through `defgeneric' with ARGS.
1323 166
@@ -1358,139 +201,6 @@ Summary:
1358 (format "Generically created method `%s'." method))) 201 (format "Generically created method `%s'." method)))
1359 (eieio--defmethod ',method ',key ',class #',code)))) 202 (eieio--defmethod ',method ',key ',class #',code))))
1360 203
1361(defun eieio--defmethod (method kind argclass code)
1362 "Work part of the `defmethod' macro defining METHOD with ARGS."
1363 (let ((key
1364 ;; Find optional keys.
1365 (cond ((memq kind '(:BEFORE :before)) method-before)
1366 ((memq kind '(:AFTER :after)) method-after)
1367 ((memq kind '(:STATIC :static)) method-static)
1368 ((memq kind '(:PRIMARY :primary nil)) method-primary)
1369 ;; Primary key.
1370 ;; (t method-primary)
1371 (t (error "Unknown method kind %S" kind)))))
1372 ;; Make sure there is a generic (when called from defclass).
1373 (eieio--defalias
1374 method (eieio--defgeneric-init-form
1375 method (or (documentation code)
1376 (format "Generically created method `%s'." method))))
1377 ;; Create symbol for property to bind to. If the first arg is of
1378 ;; the form (varname vartype) and `vartype' is a class, then
1379 ;; that class will be the type symbol. If not, then it will fall
1380 ;; under the type `primary' which is a non-specific calling of the
1381 ;; function.
1382 (if argclass
1383 (if (not (class-p argclass))
1384 (error "Unknown class type %s in method parameters"
1385 argclass))
1386 ;; Generics are higher.
1387 (setq key (eieio-specialized-key-to-generic-key key)))
1388 ;; Put this lambda into the symbol so we can find it.
1389 (eieiomt-add method code key argclass)
1390 )
1391
1392 (when eieio-optimize-primary-methods-flag
1393 ;; Optimizing step:
1394 ;;
1395 ;; If this method, after this setup, only has primary methods, then
1396 ;; we can setup the generic that way.
1397 (if (generic-primary-only-p method)
1398 ;; If there is only one primary method, then we can go one more
1399 ;; optimization step.
1400 (if (generic-primary-only-one-p method)
1401 (eieio-defgeneric-reset-generic-form-primary-only-one method)
1402 (eieio-defgeneric-reset-generic-form-primary-only method))
1403 (eieio-defgeneric-reset-generic-form method)))
1404
1405 method)
1406
1407;;; Slot type validation
1408
1409;; This is a hideous hack for replacing `typep' from cl-macs, to avoid
1410;; requiring the CL library at run-time. It can be eliminated if/when
1411;; `typep' is merged into Emacs core.
1412(defun eieio--typep (val type)
1413 (if (symbolp type)
1414 (cond ((get type 'cl-deftype-handler)
1415 (eieio--typep val (funcall (get type 'cl-deftype-handler))))
1416 ((eq type t) t)
1417 ((eq type 'null) (null val))
1418 ((eq type 'atom) (atom val))
1419 ((eq type 'float) (and (numberp val) (not (integerp val))))
1420 ((eq type 'real) (numberp val))
1421 ((eq type 'fixnum) (integerp val))
1422 ((memq type '(character string-char)) (characterp val))
1423 (t
1424 (let* ((name (symbol-name type))
1425 (namep (intern (concat name "p"))))
1426 (if (fboundp namep)
1427 (funcall `(lambda () (,namep val)))
1428 (funcall `(lambda ()
1429 (,(intern (concat name "-p")) val)))))))
1430 (cond ((get (car type) 'cl-deftype-handler)
1431 (eieio--typep val (apply (get (car type) 'cl-deftype-handler)
1432 (cdr type))))
1433 ((memq (car type) '(integer float real number))
1434 (and (eieio--typep val (car type))
1435 (or (memq (cadr type) '(* nil))
1436 (if (consp (cadr type))
1437 (> val (car (cadr type)))
1438 (>= val (cadr type))))
1439 (or (memq (caddr type) '(* nil))
1440 (if (consp (car (cddr type)))
1441 (< val (caar (cddr type)))
1442 (<= val (car (cddr type)))))))
1443 ((memq (car type) '(and or not))
1444 (eval (cons (car type)
1445 (mapcar (lambda (x)
1446 `(eieio--typep (quote ,val) (quote ,x)))
1447 (cdr type)))))
1448 ((memq (car type) '(member member*))
1449 (memql val (cdr type)))
1450 ((eq (car type) 'satisfies)
1451 (funcall `(lambda () (,(cadr type) val))))
1452 (t (error "Bad type spec: %s" type)))))
1453
1454(defun eieio-perform-slot-validation (spec value)
1455 "Return non-nil if SPEC does not match VALUE."
1456 (or (eq spec t) ; t always passes
1457 (eq value eieio-unbound) ; unbound always passes
1458 (eieio--typep value spec)))
1459
1460(defun eieio-validate-slot-value (class slot-idx value slot)
1461 "Make sure that for CLASS referencing SLOT-IDX, VALUE is valid.
1462Checks the :type specifier.
1463SLOT is the slot that is being checked, and is only used when throwing
1464an error."
1465 (if eieio-skip-typecheck
1466 nil
1467 ;; Trim off object IDX junk added in for the object index.
1468 (setq slot-idx (- slot-idx 3))
1469 (let ((st (aref (eieio--class-public-type (class-v class)) slot-idx)))
1470 (if (not (eieio-perform-slot-validation st value))
1471 (signal 'invalid-slot-type (list class slot st value))))))
1472
1473(defun eieio-validate-class-slot-value (class slot-idx value slot)
1474 "Make sure that for CLASS referencing SLOT-IDX, VALUE is valid.
1475Checks the :type specifier.
1476SLOT is the slot that is being checked, and is only used when throwing
1477an error."
1478 (if eieio-skip-typecheck
1479 nil
1480 (let ((st (aref (eieio--class-class-allocation-type (class-v class))
1481 slot-idx)))
1482 (if (not (eieio-perform-slot-validation st value))
1483 (signal 'invalid-slot-type (list class slot st value))))))
1484
1485(defun eieio-barf-if-slot-unbound (value instance slotname fn)
1486 "Throw a signal if VALUE is a representation of an UNBOUND slot.
1487INSTANCE is the object being referenced. SLOTNAME is the offending
1488slot. If the slot is ok, return VALUE.
1489Argument FN is the function calling this verifier."
1490 (if (and (eq value eieio-unbound) (not eieio-skip-typecheck))
1491 (slot-unbound instance (eieio-object-class instance) slotname fn)
1492 value))
1493
1494;;; Get/Set slots in an object. 204;;; Get/Set slots in an object.
1495;; 205;;
1496(defmacro oref (obj slot) 206(defmacro oref (obj slot)
@@ -1499,28 +209,6 @@ Slot is the name of the slot when created by `defclass' or the label
1499created by the :initarg tag." 209created by the :initarg tag."
1500 `(eieio-oref ,obj (quote ,slot))) 210 `(eieio-oref ,obj (quote ,slot)))
1501 211
1502(defun eieio-oref (obj slot)
1503 "Return the value in OBJ at SLOT in the object vector."
1504 (eieio--check-type (or eieio-object-p class-p) obj)
1505 (eieio--check-type symbolp slot)
1506 (if (class-p obj) (eieio-class-un-autoload obj))
1507 (let* ((class (if (class-p obj) obj (eieio--object-class obj)))
1508 (c (eieio-slot-name-index class obj slot)))
1509 (if (not c)
1510 ;; It might be missing because it is a :class allocated slot.
1511 ;; Let's check that info out.
1512 (if (setq c (eieio-class-slot-name-index class slot))
1513 ;; Oref that slot.
1514 (aref (eieio--class-class-allocation-values (class-v class)) c)
1515 ;; The slot-missing method is a cool way of allowing an object author
1516 ;; to intercept missing slot definitions. Since it is also the LAST
1517 ;; thing called in this fn, its return value would be retrieved.
1518 (slot-missing obj slot 'oref)
1519 ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot))
1520 )
1521 (eieio--check-type eieio-object-p obj)
1522 (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref))))
1523
1524(defalias 'slot-value 'eieio-oref) 212(defalias 'slot-value 'eieio-oref)
1525(defalias 'set-slot-value 'eieio-oset) 213(defalias 'set-slot-value 'eieio-oset)
1526 214
@@ -1531,45 +219,6 @@ tag. SLOT can be the slot name, or the tag specified by the :initarg
1531tag in the `defclass' call." 219tag in the `defclass' call."
1532 `(eieio-oref-default ,obj (quote ,slot))) 220 `(eieio-oref-default ,obj (quote ,slot)))
1533 221
1534(defun eieio-oref-default (obj slot)
1535 "Do the work for the macro `oref-default' with similar parameters.
1536Fills in OBJ's SLOT with its default value."
1537 (eieio--check-type (or eieio-object-p class-p) obj)
1538 (eieio--check-type symbolp slot)
1539 (let* ((cl (if (eieio-object-p obj) (eieio--object-class obj) obj))
1540 (c (eieio-slot-name-index cl obj slot)))
1541 (if (not c)
1542 ;; It might be missing because it is a :class allocated slot.
1543 ;; Let's check that info out.
1544 (if (setq c
1545 (eieio-class-slot-name-index cl slot))
1546 ;; Oref that slot.
1547 (aref (eieio--class-class-allocation-values (class-v cl))
1548 c)
1549 (slot-missing obj slot 'oref-default)
1550 ;;(signal 'invalid-slot-name (list (class-name cl) slot))
1551 )
1552 (eieio-barf-if-slot-unbound
1553 (let ((val (nth (- c 3) (eieio--class-public-d (class-v cl)))))
1554 (eieio-default-eval-maybe val))
1555 obj cl 'oref-default))))
1556
1557(defsubst eieio-eval-default-p (val)
1558 "Whether the default value VAL should be evaluated for use."
1559 (and (consp val) (symbolp (car val)) (fboundp (car val))))
1560
1561(defun eieio-default-eval-maybe (val)
1562 "Check VAL, and return what `oref-default' would provide."
1563 (cond
1564 ;; Is it a function call? If so, evaluate it.
1565 ((eieio-eval-default-p val)
1566 (eval val))
1567 ;;;; check for quoted things, and unquote them
1568 ;;((and (consp val) (eq (car val) 'quote))
1569 ;; (car (cdr val)))
1570 ;; return it verbatim
1571 (t val)))
1572
1573;;; Handy CLOS macros 222;;; Handy CLOS macros
1574;; 223;;
1575(defmacro with-slots (spec-list object &rest body) 224(defmacro with-slots (spec-list object &rest body)
@@ -1607,13 +256,6 @@ variable name of the same name as the slot."
1607(define-obsolete-function-alias 256(define-obsolete-function-alias
1608 'object-class-fast #'eieio--object-class "24.4") 257 'object-class-fast #'eieio--object-class "24.4")
1609 258
1610(defun eieio-class-name (class) "Return a Lisp like symbol name for CLASS."
1611 (eieio--check-type class-p class)
1612 ;; I think this is supposed to return a symbol, but to me CLASS is a symbol,
1613 ;; and I wanted a string. Arg!
1614 (format "#<class %s>" (symbol-name class)))
1615(define-obsolete-function-alias 'class-name #'eieio-class-name "24.4")
1616
1617(defun eieio-object-name (obj &optional extra) 259(defun eieio-object-name (obj &optional extra)
1618 "Return a Lisp like symbol string for object OBJ. 260 "Return a Lisp like symbol string for object OBJ.
1619If EXTRA, include that in the string returned to represent the symbol." 261If EXTRA, include that in the string returned to represent the symbol."
@@ -1650,10 +292,6 @@ If EXTRA, include that in the string returned to represent the symbol."
1650(define-obsolete-function-alias 292(define-obsolete-function-alias
1651 'object-class-name 'eieio-object-class-name "24.4") 293 'object-class-name 'eieio-object-class-name "24.4")
1652 294
1653(defmacro eieio-class-parents-fast (class)
1654 "Return parent classes to CLASS with no check."
1655 `(eieio--class-parent (class-v ,class)))
1656
1657(defun eieio-class-parents (class) 295(defun eieio-class-parents (class)
1658 "Return parent classes to CLASS. (overload of variable). 296 "Return parent classes to CLASS. (overload of variable).
1659 297
@@ -1662,130 +300,14 @@ The CLOS function `class-direct-superclasses' is aliased to this function."
1662 (eieio-class-parents-fast class)) 300 (eieio-class-parents-fast class))
1663(define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4") 301(define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4")
1664 302
1665(defmacro eieio-class-children-fast (class) "Return child classes to CLASS with no check."
1666 `(eieio--class-children (class-v ,class)))
1667
1668(defun eieio-class-children (class) 303(defun eieio-class-children (class)
1669 "Return child classes to CLASS. 304 "Return child classes to CLASS.
1670
1671The CLOS function `class-direct-subclasses' is aliased to this function." 305The CLOS function `class-direct-subclasses' is aliased to this function."
1672 (eieio--check-type class-p class) 306 (eieio--check-type class-p class)
1673 (eieio-class-children-fast class)) 307 (eieio-class-children-fast class))
1674(define-obsolete-function-alias 308(define-obsolete-function-alias
1675 'class-children #'eieio-class-children "24.4") 309 'class-children #'eieio-class-children "24.4")
1676 310
1677(defun eieio-c3-candidate (class remaining-inputs)
1678 "Return CLASS if it can go in the result now, otherwise nil"
1679 ;; Ensure CLASS is not in any position but the first in any of the
1680 ;; element lists of REMAINING-INPUTS.
1681 (and (not (let ((found nil))
1682 (while (and remaining-inputs (not found))
1683 (setq found (member class (cdr (car remaining-inputs)))
1684 remaining-inputs (cdr remaining-inputs)))
1685 found))
1686 class))
1687
1688(defun eieio-c3-merge-lists (reversed-partial-result remaining-inputs)
1689 "Merge REVERSED-PARTIAL-RESULT REMAINING-INPUTS in a consistent order, if possible.
1690If a consistent order does not exist, signal an error."
1691 (if (let ((tail remaining-inputs)
1692 (found nil))
1693 (while (and tail (not found))
1694 (setq found (car tail) tail (cdr tail)))
1695 (not found))
1696 ;; If all remaining inputs are empty lists, we are done.
1697 (nreverse reversed-partial-result)
1698 ;; Otherwise, we try to find the next element of the result. This
1699 ;; is achieved by considering the first element of each
1700 ;; (non-empty) input list and accepting a candidate if it is
1701 ;; consistent with the rests of the input lists.
1702 (let* ((found nil)
1703 (tail remaining-inputs)
1704 (next (progn
1705 (while (and tail (not found))
1706 (setq found (and (car tail)
1707 (eieio-c3-candidate (caar tail)
1708 remaining-inputs))
1709 tail (cdr tail)))
1710 found)))
1711 (if next
1712 ;; The graph is consistent so far, add NEXT to result and
1713 ;; merge input lists, dropping NEXT from their heads where
1714 ;; applicable.
1715 (eieio-c3-merge-lists
1716 (cons next reversed-partial-result)
1717 (mapcar (lambda (l) (if (eq (first l) next) (rest l) l))
1718 remaining-inputs))
1719 ;; The graph is inconsistent, give up
1720 (signal 'inconsistent-class-hierarchy (list remaining-inputs))))))
1721
1722(defun eieio-class-precedence-dfs (class)
1723 "Return all parents of CLASS in depth-first order."
1724 (let* ((parents (eieio-class-parents-fast class))
1725 (classes (copy-sequence
1726 (apply #'append
1727 (list class)
1728 (or
1729 (mapcar
1730 (lambda (parent)
1731 (cons parent
1732 (eieio-class-precedence-dfs parent)))
1733 parents)
1734 '((eieio-default-superclass))))))
1735 (tail classes))
1736 ;; Remove duplicates.
1737 (while tail
1738 (setcdr tail (delq (car tail) (cdr tail)))
1739 (setq tail (cdr tail)))
1740 classes))
1741
1742(defun eieio-class-precedence-bfs (class)
1743 "Return all parents of CLASS in breadth-first order."
1744 (let ((result)
1745 (queue (or (eieio-class-parents-fast class)
1746 '(eieio-default-superclass))))
1747 (while queue
1748 (let ((head (pop queue)))
1749 (unless (member head result)
1750 (push head result)
1751 (unless (eq head 'eieio-default-superclass)
1752 (setq queue (append queue (or (eieio-class-parents-fast head)
1753 '(eieio-default-superclass))))))))
1754 (cons class (nreverse result)))
1755 )
1756
1757(defun eieio-class-precedence-c3 (class)
1758 "Return all parents of CLASS in c3 order."
1759 (let ((parents (eieio-class-parents-fast class)))
1760 (eieio-c3-merge-lists
1761 (list class)
1762 (append
1763 (or
1764 (mapcar
1765 (lambda (x)
1766 (eieio-class-precedence-c3 x))
1767 parents)
1768 '((eieio-default-superclass)))
1769 (list parents))))
1770 )
1771
1772(defun eieio-class-precedence-list (class)
1773 "Return (transitively closed) list of parents of CLASS.
1774The order, in which the parents are returned depends on the
1775method invocation orders of the involved classes."
1776 (if (or (null class) (eq class 'eieio-default-superclass))
1777 nil
1778 (case (class-method-invocation-order class)
1779 (:depth-first
1780 (eieio-class-precedence-dfs class))
1781 (:breadth-first
1782 (eieio-class-precedence-bfs class))
1783 (:c3
1784 (eieio-class-precedence-c3 class))))
1785 )
1786(define-obsolete-function-alias
1787 'class-precedence-list 'eieio-class-precedence-list "24.4")
1788
1789;; Official CLOS functions. 311;; Official CLOS functions.
1790(define-obsolete-function-alias 312(define-obsolete-function-alias
1791 'class-direct-superclasses #'eieio-class-parents "24.4") 313 'class-direct-superclasses #'eieio-class-parents "24.4")
@@ -1797,10 +319,6 @@ method invocation orders of the involved classes."
1797 `(car (eieio-class-parents ,class))) 319 `(car (eieio-class-parents ,class)))
1798(define-obsolete-function-alias 'class-parent #'eieio-class-parent "24.4") 320(define-obsolete-function-alias 'class-parent #'eieio-class-parent "24.4")
1799 321
1800(defmacro same-class-fast-p (obj class)
1801 "Return t if OBJ is of class-type CLASS with no error checking."
1802 `(eq (eieio--object-class ,obj) ,class))
1803
1804(defun same-class-p (obj class) "Return t if OBJ is of class-type CLASS." 322(defun same-class-p (obj class) "Return t if OBJ is of class-type CLASS."
1805 (eieio--check-type class-p class) 323 (eieio--check-type class-p class)
1806 (eieio--check-type eieio-object-p obj) 324 (eieio--check-type eieio-object-p obj)
@@ -1848,29 +366,6 @@ SLOT is the slot name as specified in `defclass' or the tag created
1848with in the :initarg slot. VALUE can be any Lisp object." 366with in the :initarg slot. VALUE can be any Lisp object."
1849 `(eieio-oset ,obj (quote ,slot) ,value)) 367 `(eieio-oset ,obj (quote ,slot) ,value))
1850 368
1851(defun eieio-oset (obj slot value)
1852 "Do the work for the macro `oset'.
1853Fills in OBJ's SLOT with VALUE."
1854 (eieio--check-type eieio-object-p obj)
1855 (eieio--check-type symbolp slot)
1856 (let ((c (eieio-slot-name-index (eieio--object-class obj) obj slot)))
1857 (if (not c)
1858 ;; It might be missing because it is a :class allocated slot.
1859 ;; Let's check that info out.
1860 (if (setq c
1861 (eieio-class-slot-name-index (eieio--object-class obj) slot))
1862 ;; Oset that slot.
1863 (progn
1864 (eieio-validate-class-slot-value (eieio--object-class obj) c value slot)
1865 (aset (eieio--class-class-allocation-values (class-v (eieio--object-class obj)))
1866 c value))
1867 ;; See oref for comment on `slot-missing'
1868 (slot-missing obj slot 'oset value)
1869 ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot))
1870 )
1871 (eieio-validate-slot-value (eieio--object-class obj) c value slot)
1872 (aset obj c value))))
1873
1874(defmacro oset-default (class slot value) 369(defmacro oset-default (class slot value)
1875 "Set the default slot in CLASS for SLOT to VALUE. 370 "Set the default slot in CLASS for SLOT to VALUE.
1876The default value is usually set with the :initform tag during class 371The default value is usually set with the :initform tag during class
@@ -1878,32 +373,6 @@ creation. This allows users to change the default behavior of classes
1878after they are created." 373after they are created."
1879 `(eieio-oset-default ,class (quote ,slot) ,value)) 374 `(eieio-oset-default ,class (quote ,slot) ,value))
1880 375
1881(defun eieio-oset-default (class slot value)
1882 "Do the work for the macro `oset-default'.
1883Fills in the default value in CLASS' in SLOT with VALUE."
1884 (eieio--check-type class-p class)
1885 (eieio--check-type symbolp slot)
1886 (let* ((scoped-class class)
1887 (c (eieio-slot-name-index class nil slot)))
1888 (if (not c)
1889 ;; It might be missing because it is a :class allocated slot.
1890 ;; Let's check that info out.
1891 (if (setq c (eieio-class-slot-name-index class slot))
1892 (progn
1893 ;; Oref that slot.
1894 (eieio-validate-class-slot-value class c value slot)
1895 (aset (eieio--class-class-allocation-values (class-v class)) c
1896 value))
1897 (signal 'invalid-slot-name (list (eieio-class-name class) slot)))
1898 (eieio-validate-slot-value class c value slot)
1899 ;; Set this into the storage for defaults.
1900 (setcar (nthcdr (- c 3) (eieio--class-public-d (class-v class)))
1901 value)
1902 ;; Take the value, and put it into our cache object.
1903 (eieio-oset (eieio--class-default-object-cache (class-v class))
1904 slot value)
1905 )))
1906
1907;;; CLOS queries into classes and slots 376;;; CLOS queries into classes and slots
1908;; 377;;
1909(defun slot-boundp (object slot) 378(defun slot-boundp (object slot)
@@ -2019,337 +488,9 @@ If SLOT is unbound, do nothing."
2019 (if (not (slot-boundp object slot)) 488 (if (not (slot-boundp object slot))
2020 nil 489 nil
2021 (eieio-oset object slot (delete item (eieio-oref object slot))))) 490 (eieio-oset object slot (delete item (eieio-oref object slot)))))
2022
2023;;; EIEIO internal search functions
2024;;
2025(defun eieio-slot-originating-class-p (start-class slot)
2026 "Return non-nil if START-CLASS is the first class to define SLOT.
2027This is for testing if `scoped-class' is the class that defines SLOT
2028so that we can protect private slots."
2029 (let ((par (eieio-class-parents start-class))
2030 (ret t))
2031 (if (not par)
2032 t
2033 (while (and par ret)
2034 (if (intern-soft (symbol-name slot)
2035 (eieio--class-symbol-obarray (class-v (car par))))
2036 (setq ret nil))
2037 (setq par (cdr par)))
2038 ret)))
2039
2040(defun eieio-slot-name-index (class obj slot)
2041 "In CLASS for OBJ find the index of the named SLOT.
2042The slot is a symbol which is installed in CLASS by the `defclass'
2043call. OBJ can be nil, but if it is an object, and the slot in question
2044is protected, access will be allowed if OBJ is a child of the currently
2045`scoped-class'.
2046If SLOT is the value created with :initarg instead,
2047reverse-lookup that name, and recurse with the associated slot value."
2048 ;; Removed checks to outside this call
2049 (let* ((fsym (intern-soft (symbol-name slot)
2050 (eieio--class-symbol-obarray (class-v class))))
2051 (fsi (if (symbolp fsym) (symbol-value fsym) nil)))
2052 (if (integerp fsi)
2053 (cond
2054 ((not (get fsym 'protection))
2055 (+ 3 fsi))
2056 ((and (eq (get fsym 'protection) 'protected)
2057 (bound-and-true-p scoped-class)
2058 (or (child-of-class-p class scoped-class)
2059 (and (eieio-object-p obj)
2060 (child-of-class-p class (eieio-object-class obj)))))
2061 (+ 3 fsi))
2062 ((and (eq (get fsym 'protection) 'private)
2063 (or (and (bound-and-true-p scoped-class)
2064 (eieio-slot-originating-class-p scoped-class slot))
2065 eieio-initializing-object))
2066 (+ 3 fsi))
2067 (t nil))
2068 (let ((fn (eieio-initarg-to-attribute class slot)))
2069 (if fn (eieio-slot-name-index class obj fn) nil)))))
2070
2071(defun eieio-class-slot-name-index (class slot)
2072 "In CLASS find the index of the named SLOT.
2073The slot is a symbol which is installed in CLASS by the `defclass'
2074call. If SLOT is the value created with :initarg instead,
2075reverse-lookup that name, and recurse with the associated slot value."
2076 ;; This will happen less often, and with fewer slots. Do this the
2077 ;; storage cheap way.
2078 (let* ((a (eieio--class-class-allocation-a (class-v class)))
2079 (l1 (length a))
2080 (af (memq slot a))
2081 (l2 (length af)))
2082 ;; Slot # is length of the total list, minus the remaining list of
2083 ;; the found slot.
2084 (if af (- l1 l2))))
2085
2086;;; CLOS generics internal function handling
2087;;
2088(defvar eieio-generic-call-methodname nil
2089 "When using `call-next-method', provides a context on how to do it.")
2090(defvar eieio-generic-call-arglst nil
2091 "When using `call-next-method', provides a context for parameters.")
2092(defvar eieio-generic-call-key nil
2093 "When using `call-next-method', provides a context for the current key.
2094Keys are a number representing :before, :primary, and :after methods.")
2095(defvar eieio-generic-call-next-method-list nil
2096 "When executing a PRIMARY or STATIC method, track the 'next-method'.
2097During executions, the list is first generated, then as each next method
2098is called, the next method is popped off the stack.")
2099
2100(define-obsolete-variable-alias 'eieio-pre-method-execution-hooks
2101 'eieio-pre-method-execution-functions "24.3")
2102(defvar eieio-pre-method-execution-functions nil
2103 "Abnormal hook run just before an EIEIO method is executed.
2104The hook function must accept one argument, the list of forms
2105about to be executed.")
2106
2107(defun eieio-generic-call (method args)
2108 "Call METHOD with ARGS.
2109ARGS provides the context on which implementation to use.
2110This should only be called from a generic function."
2111 ;; We must expand our arguments first as they are always
2112 ;; passed in as quoted symbols
2113 (let ((newargs nil) (mclass nil) (lambdas nil) (tlambdas nil) (keys nil)
2114 (eieio-generic-call-methodname method)
2115 (eieio-generic-call-arglst args)
2116 (firstarg nil)
2117 (primarymethodlist nil))
2118 ;; get a copy
2119 (setq newargs args
2120 firstarg (car newargs))
2121 ;; Is the class passed in autoloaded?
2122 ;; Since class names are also constructors, they can be autoloaded
2123 ;; via the autoload command. Check for this, and load them in.
2124 ;; It's ok if it doesn't turn out to be a class. Probably want that
2125 ;; function loaded anyway.
2126 (if (and (symbolp firstarg)
2127 (fboundp firstarg)
2128 (listp (symbol-function firstarg))
2129 (eq 'autoload (car (symbol-function firstarg))))
2130 (load (nth 1 (symbol-function firstarg))))
2131 ;; Determine the class to use.
2132 (cond ((eieio-object-p firstarg)
2133 (setq mclass (eieio--object-class firstarg)))
2134 ((class-p firstarg)
2135 (setq mclass firstarg))
2136 )
2137 ;; Make sure the class is a valid class
2138 ;; mclass can be nil (meaning a generic for should be used.
2139 ;; mclass cannot have a value that is not a class, however.
2140 (when (and (not (null mclass)) (not (class-p mclass)))
2141 (error "Cannot dispatch method %S on class %S"
2142 method mclass)
2143 )
2144 ;; Now create a list in reverse order of all the calls we have
2145 ;; make in order to successfully do this right. Rules:
2146 ;; 1) Only call generics if scoped-class is not defined
2147 ;; This prevents multiple calls in the case of recursion
2148 ;; 2) Only call static if this is a static method.
2149 ;; 3) Only call specifics if the definition allows for them.
2150 ;; 4) Call in order based on :before, :primary, and :after
2151 (when (eieio-object-p firstarg)
2152 ;; Non-static calls do all this stuff.
2153
2154 ;; :after methods
2155 (setq tlambdas
2156 (if mclass
2157 (eieiomt-method-list method method-after mclass)
2158 (list (eieio-generic-form method method-after nil)))
2159 ;;(or (and mclass (eieio-generic-form method method-after mclass))
2160 ;; (eieio-generic-form method method-after nil))
2161 )
2162 (setq lambdas (append tlambdas lambdas)
2163 keys (append (make-list (length tlambdas) method-after) keys))
2164
2165 ;; :primary methods
2166 (setq tlambdas
2167 (or (and mclass (eieio-generic-form method method-primary mclass))
2168 (eieio-generic-form method method-primary nil)))
2169 (when tlambdas
2170 (setq lambdas (cons tlambdas lambdas)
2171 keys (cons method-primary keys)
2172 primarymethodlist
2173 (eieiomt-method-list method method-primary mclass)))
2174
2175 ;; :before methods
2176 (setq tlambdas
2177 (if mclass
2178 (eieiomt-method-list method method-before mclass)
2179 (list (eieio-generic-form method method-before nil)))
2180 ;;(or (and mclass (eieio-generic-form method method-before mclass))
2181 ;; (eieio-generic-form method method-before nil))
2182 )
2183 (setq lambdas (append tlambdas lambdas)
2184 keys (append (make-list (length tlambdas) method-before) keys))
2185 )
2186
2187 (if mclass
2188 ;; For the case of a class,
2189 ;; if there were no methods found, then there could be :static methods.
2190 (when (not lambdas)
2191 (setq tlambdas
2192 (eieio-generic-form method method-static mclass))
2193 (setq lambdas (cons tlambdas lambdas)
2194 keys (cons method-static keys)
2195 primarymethodlist ;; Re-use even with bad name here
2196 (eieiomt-method-list method method-static mclass)))
2197 ;; For the case of no class (ie - mclass == nil) then there may
2198 ;; be a primary method.
2199 (setq tlambdas
2200 (eieio-generic-form method method-primary nil))
2201 (when tlambdas
2202 (setq lambdas (cons tlambdas lambdas)
2203 keys (cons method-primary keys)
2204 primarymethodlist
2205 (eieiomt-method-list method method-primary nil)))
2206 )
2207
2208 (run-hook-with-args 'eieio-pre-method-execution-functions
2209 primarymethodlist)
2210
2211 ;; Now loop through all occurrences forms which we must execute
2212 ;; (which are happily sorted now) and execute them all!
2213 (let ((rval nil) (lastval nil) (rvalever nil) (found nil))
2214 (while lambdas
2215 (if (car lambdas)
2216 (let* ((scoped-class (cdr (car lambdas)))
2217 (eieio-generic-call-key (car keys))
2218 (has-return-val
2219 (or (= eieio-generic-call-key method-primary)
2220 (= eieio-generic-call-key method-static)))
2221 (eieio-generic-call-next-method-list
2222 ;; Use the cdr, as the first element is the fcn
2223 ;; we are calling right now.
2224 (when has-return-val (cdr primarymethodlist)))
2225 )
2226 (setq found t)
2227 ;;(setq rval (apply (car (car lambdas)) newargs))
2228 (setq lastval (apply (car (car lambdas)) newargs))
2229 (when has-return-val
2230 (setq rval lastval
2231 rvalever t))
2232 ))
2233 (setq lambdas (cdr lambdas)
2234 keys (cdr keys)))
2235 (if (not found)
2236 (if (eieio-object-p (car args))
2237 (setq rval (apply 'no-applicable-method (car args) method args)
2238 rvalever t)
2239 (signal
2240 'no-method-definition
2241 (list method args))))
2242 ;; Right Here... it could be that lastval is returned when
2243 ;; rvalever is nil. Is that right?
2244 rval)))
2245
2246(defun eieio-generic-call-primary-only (method args)
2247 "Call METHOD with ARGS for methods with only :PRIMARY implementations.
2248ARGS provides the context on which implementation to use.
2249This should only be called from a generic function.
2250
2251This method is like `eieio-generic-call', but only
2252implementations in the :PRIMARY slot are queried. After many
2253years of use, it appears that over 90% of methods in use
2254have :PRIMARY implementations only. We can therefore optimize
2255for this common case to improve performance."
2256 ;; We must expand our arguments first as they are always
2257 ;; passed in as quoted symbols
2258 (let ((newargs nil) (mclass nil) (lambdas nil)
2259 (eieio-generic-call-methodname method)
2260 (eieio-generic-call-arglst args)
2261 (firstarg nil)
2262 (primarymethodlist nil)
2263 )
2264 ;; get a copy
2265 (setq newargs args
2266 firstarg (car newargs))
2267
2268 ;; Determine the class to use.
2269 (cond ((eieio-object-p firstarg)
2270 (setq mclass (eieio--object-class firstarg)))
2271 ((not firstarg)
2272 (error "Method %s called on nil" method))
2273 ((not (eieio-object-p firstarg))
2274 (error "Primary-only method %s called on something not an object" method))
2275 (t
2276 (error "EIEIO Error: Improperly classified method %s as primary only"
2277 method)
2278 ))
2279 ;; Make sure the class is a valid class
2280 ;; mclass can be nil (meaning a generic for should be used.
2281 ;; mclass cannot have a value that is not a class, however.
2282 (when (null mclass)
2283 (error "Cannot dispatch method %S on class %S" method mclass)
2284 )
2285
2286 ;; :primary methods
2287 (setq lambdas (eieio-generic-form method method-primary mclass))
2288 (setq primarymethodlist ;; Re-use even with bad name here
2289 (eieiomt-method-list method method-primary mclass))
2290
2291 ;; Now loop through all occurrences forms which we must execute
2292 ;; (which are happily sorted now) and execute them all!
2293 (let* ((rval nil) (lastval nil) (rvalever nil)
2294 (scoped-class (cdr lambdas))
2295 (eieio-generic-call-key method-primary)
2296 ;; Use the cdr, as the first element is the fcn
2297 ;; we are calling right now.
2298 (eieio-generic-call-next-method-list (cdr primarymethodlist))
2299 )
2300
2301 (if (or (not lambdas) (not (car lambdas)))
2302
2303 ;; No methods found for this impl...
2304 (if (eieio-object-p (car args))
2305 (setq rval (apply 'no-applicable-method (car args) method args)
2306 rvalever t)
2307 (signal
2308 'no-method-definition
2309 (list method args)))
2310
2311 ;; Do the regular implementation here.
2312
2313 (run-hook-with-args 'eieio-pre-method-execution-functions
2314 lambdas)
2315
2316 (setq lastval (apply (car lambdas) newargs))
2317 (setq rval lastval
2318 rvalever t)
2319 )
2320 491
2321 ;; Right Here... it could be that lastval is returned when 492;;;
2322 ;; rvalever is nil. Is that right? 493;; Method Calling Functions
2323 rval)))
2324
2325(defun eieiomt-method-list (method key class)
2326 "Return an alist list of methods lambdas.
2327METHOD is the method name.
2328KEY represents either :before, or :after methods.
2329CLASS is the starting class to search from in the method tree.
2330If CLASS is nil, then an empty list of methods should be returned."
2331 ;; Note: eieiomt - the MT means MethodTree. See more comments below
2332 ;; for the rest of the eieiomt methods.
2333
2334 ;; Collect lambda expressions stored for the class and its parent
2335 ;; classes.
2336 (let (lambdas)
2337 (dolist (ancestor (eieio-class-precedence-list class))
2338 ;; Lookup the form to use for the PRIMARY object for the next level
2339 (let ((tmpl (eieio-generic-form method key ancestor)))
2340 (when (and tmpl
2341 (or (not lambdas)
2342 ;; This prevents duplicates coming out of the
2343 ;; class method optimizer. Perhaps we should
2344 ;; just not optimize before/afters?
2345 (not (member tmpl lambdas))))
2346 (push tmpl lambdas))))
2347
2348 ;; Return collected lambda. For :after methods, return in current
2349 ;; order (most general class last); Otherwise, reverse order.
2350 (if (eq key method-after)
2351 lambdas
2352 (nreverse lambdas))))
2353 494
2354(defun next-method-p () 495(defun next-method-p ()
2355 "Return non-nil if there is a next method. 496 "Return non-nil if there is a next method.
@@ -2367,7 +508,7 @@ If REPLACEMENT-ARGS is non-nil, then use them instead of
2367arguments passed in at the top level. 508arguments passed in at the top level.
2368 509
2369Use `next-method-p' to find out if there is a next method to call." 510Use `next-method-p' to find out if there is a next method to call."
2370 (if (not (bound-and-true-p scoped-class)) 511 (if (not (eieio--scoped-class))
2371 (error "`call-next-method' not called within a class specific method")) 512 (error "`call-next-method' not called within a class specific method"))
2372 (if (and (/= eieio-generic-call-key method-primary) 513 (if (and (/= eieio-generic-call-key method-primary)
2373 (/= eieio-generic-call-key method-static)) 514 (/= eieio-generic-call-key method-static))
@@ -2381,231 +522,10 @@ Use `next-method-p' to find out if there is a next method to call."
2381 (let* ((eieio-generic-call-next-method-list 522 (let* ((eieio-generic-call-next-method-list
2382 (cdr eieio-generic-call-next-method-list)) 523 (cdr eieio-generic-call-next-method-list))
2383 (eieio-generic-call-arglst newargs) 524 (eieio-generic-call-arglst newargs)
2384 (scoped-class (cdr next))
2385 (fcn (car next)) 525 (fcn (car next))
2386 ) 526 )
2387 (apply fcn newargs) 527 (eieio--with-scoped-class (cdr next)
2388 )))) 528 (apply fcn newargs)) ))))
2389
2390;;;
2391;; eieio-method-tree : eieiomt-
2392;;
2393;; Stored as eieio-method-tree in property list of a generic method
2394;;
2395;; (eieio-method-tree . [BEFORE PRIMARY AFTER
2396;; genericBEFORE genericPRIMARY genericAFTER])
2397;; and
2398;; (eieio-method-obarray . [BEFORE PRIMARY AFTER
2399;; genericBEFORE genericPRIMARY genericAFTER])
2400;; where the association is a vector.
2401;; (aref 0 -- all static methods.
2402;; (aref 1 -- all methods classified as :before
2403;; (aref 2 -- all methods classified as :primary
2404;; (aref 3 -- all methods classified as :after
2405;; (aref 4 -- a generic classified as :before
2406;; (aref 5 -- a generic classified as :primary
2407;; (aref 6 -- a generic classified as :after
2408;;
2409(defvar eieiomt-optimizing-obarray nil
2410 "While mapping atoms, this contain the obarray being optimized.")
2411
2412(defun eieiomt-install (method-name)
2413 "Install the method tree, and obarray onto METHOD-NAME.
2414Do not do the work if they already exist."
2415 (let ((emtv (get method-name 'eieio-method-tree))
2416 (emto (get method-name 'eieio-method-obarray)))
2417 (if (or (not emtv) (not emto))
2418 (progn
2419 (setq emtv (put method-name 'eieio-method-tree
2420 (make-vector method-num-slots nil))
2421 emto (put method-name 'eieio-method-obarray
2422 (make-vector method-num-slots nil)))
2423 (aset emto 0 (make-vector 11 0))
2424 (aset emto 1 (make-vector 11 0))
2425 (aset emto 2 (make-vector 41 0))
2426 (aset emto 3 (make-vector 11 0))
2427 ))))
2428
2429(defun eieiomt-add (method-name method key class)
2430 "Add to METHOD-NAME the forms METHOD in a call position KEY for CLASS.
2431METHOD-NAME is the name created by a call to `defgeneric'.
2432METHOD are the forms for a given implementation.
2433KEY is an integer (see comment in eieio.el near this function) which
2434is associated with the :static :before :primary and :after tags.
2435It also indicates if CLASS is defined or not.
2436CLASS is the class this method is associated with."
2437 (if (or (> key method-num-slots) (< key 0))
2438 (error "eieiomt-add: method key error!"))
2439 (let ((emtv (get method-name 'eieio-method-tree))
2440 (emto (get method-name 'eieio-method-obarray)))
2441 ;; Make sure the method tables are available.
2442 (if (or (not emtv) (not emto))
2443 (error "Programmer error: eieiomt-add"))
2444 ;; only add new cells on if it doesn't already exist!
2445 (if (assq class (aref emtv key))
2446 (setcdr (assq class (aref emtv key)) method)
2447 (aset emtv key (cons (cons class method) (aref emtv key))))
2448 ;; Add function definition into newly created symbol, and store
2449 ;; said symbol in the correct obarray, otherwise use the
2450 ;; other array to keep this stuff
2451 (if (< key method-num-lists)
2452 (let ((nsym (intern (symbol-name class) (aref emto key))))
2453 (fset nsym method)))
2454 ;; Save the defmethod file location in a symbol property.
2455 (let ((fname (if load-in-progress
2456 load-file-name
2457 buffer-file-name))
2458 loc)
2459 (when fname
2460 (when (string-match "\\.elc$" fname)
2461 (setq fname (substring fname 0 (1- (length fname)))))
2462 (setq loc (get method-name 'method-locations))
2463 (add-to-list 'loc
2464 (list class fname))
2465 (put method-name 'method-locations loc)))
2466 ;; Now optimize the entire obarray
2467 (if (< key method-num-lists)
2468 (let ((eieiomt-optimizing-obarray (aref emto key)))
2469 ;; @todo - Is this overkill? Should we just clear the symbol?
2470 (mapatoms 'eieiomt-sym-optimize eieiomt-optimizing-obarray)))
2471 ))
2472
2473(defun eieiomt-next (class)
2474 "Return the next parent class for CLASS.
2475If CLASS is a superclass, return variable `eieio-default-superclass'.
2476If CLASS is variable `eieio-default-superclass' then return nil.
2477This is different from function `class-parent' as class parent returns
2478nil for superclasses. This function performs no type checking!"
2479 ;; No type-checking because all calls are made from functions which
2480 ;; are safe and do checking for us.
2481 (or (eieio-class-parents-fast class)
2482 (if (eq class 'eieio-default-superclass)
2483 nil
2484 '(eieio-default-superclass))))
2485
2486(defun eieiomt-sym-optimize (s)
2487 "Find the next class above S which has a function body for the optimizer."
2488 ;; Set the value to nil in case there is no nearest cell.
2489 (set s nil)
2490 ;; Find the nearest cell that has a function body. If we find one,
2491 ;; we replace the nil from above.
2492 (let ((external-symbol (intern-soft (symbol-name s))))
2493 (catch 'done
2494 (dolist (ancestor (rest (eieio-class-precedence-list external-symbol)))
2495 (let ((ov (intern-soft (symbol-name ancestor)
2496 eieiomt-optimizing-obarray)))
2497 (when (fboundp ov)
2498 (set s ov) ;; store ov as our next symbol
2499 (throw 'done ancestor)))))))
2500
2501(defun eieio-generic-form (method key class)
2502 "Return the lambda form belonging to METHOD using KEY based upon CLASS.
2503If CLASS is not a class then use `generic' instead. If class has
2504no form, but has a parent class, then trace to that parent class.
2505The first time a form is requested from a symbol, an optimized path
2506is memorized for faster future use."
2507 (let ((emto (aref (get method 'eieio-method-obarray)
2508 (if class key (eieio-specialized-key-to-generic-key key)))))
2509 (if (class-p class)
2510 ;; 1) find our symbol
2511 (let ((cs (intern-soft (symbol-name class) emto)))
2512 (if (not cs)
2513 ;; 2) If there isn't one, then make one.
2514 ;; This can be slow since it only occurs once
2515 (progn
2516 (setq cs (intern (symbol-name class) emto))
2517 ;; 2.1) Cache its nearest neighbor with a quick optimize
2518 ;; which should only occur once for this call ever
2519 (let ((eieiomt-optimizing-obarray emto))
2520 (eieiomt-sym-optimize cs))))
2521 ;; 3) If it's bound return this one.
2522 (if (fboundp cs)
2523 (cons cs (eieio--class-symbol (class-v class)))
2524 ;; 4) If it's not bound then this variable knows something
2525 (if (symbol-value cs)
2526 (progn
2527 ;; 4.1) This symbol holds the next class in its value
2528 (setq class (symbol-value cs)
2529 cs (intern-soft (symbol-name class) emto))
2530 ;; 4.2) The optimizer should always have chosen a
2531 ;; function-symbol
2532 ;;(if (fboundp cs)
2533 (cons cs (eieio--class-symbol (class-v (intern (symbol-name class)))))
2534 ;;(error "EIEIO optimizer: erratic data loss!"))
2535 )
2536 ;; There never will be a funcall...
2537 nil)))
2538 ;; for a generic call, what is a list, is the function body we want.
2539 (let ((emtl (aref (get method 'eieio-method-tree)
2540 (if class key (eieio-specialized-key-to-generic-key key)))))
2541 (if emtl
2542 ;; The car of EMTL is supposed to be a class, which in this
2543 ;; case is nil, so skip it.
2544 (cons (cdr (car emtl)) nil)
2545 nil)))))
2546
2547;;;
2548;; Way to assign slots based on a list. Used for constructors, or
2549;; even resetting an object at run-time
2550;;
2551(defun eieio-set-defaults (obj &optional set-all)
2552 "Take object OBJ, and reset all slots to their defaults.
2553If SET-ALL is non-nil, then when a default is nil, that value is
2554reset. If SET-ALL is nil, the slots are only reset if the default is
2555not nil."
2556 (let ((scoped-class (eieio--object-class obj))
2557 (eieio-initializing-object t)
2558 (pub (eieio--class-public-a (class-v (eieio--object-class obj)))))
2559 (while pub
2560 (let ((df (eieio-oref-default obj (car pub))))
2561 (if (or df set-all)
2562 (eieio-oset obj (car pub) df)))
2563 (setq pub (cdr pub)))))
2564
2565(defun eieio-initarg-to-attribute (class initarg)
2566 "For CLASS, convert INITARG to the actual attribute name.
2567If there is no translation, pass it in directly (so we can cheat if
2568need be... May remove that later...)"
2569 (let ((tuple (assoc initarg (eieio--class-initarg-tuples (class-v class)))))
2570 (if tuple
2571 (cdr tuple)
2572 nil)))
2573
2574(defun eieio-attribute-to-initarg (class attribute)
2575 "In CLASS, convert the ATTRIBUTE into the corresponding init argument tag.
2576This is usually a symbol that starts with `:'."
2577 (let ((tuple (rassoc attribute (eieio--class-initarg-tuples (class-v class)))))
2578 (if tuple
2579 (car tuple)
2580 nil)))
2581
2582
2583;;; Here are some special types of errors
2584;;
2585(intern "no-method-definition")
2586(put 'no-method-definition 'error-conditions '(no-method-definition error))
2587(put 'no-method-definition 'error-message "No method definition")
2588
2589(intern "no-next-method")
2590(put 'no-next-method 'error-conditions '(no-next-method error))
2591(put 'no-next-method 'error-message "No next method")
2592
2593(intern "invalid-slot-name")
2594(put 'invalid-slot-name 'error-conditions '(invalid-slot-name error))
2595(put 'invalid-slot-name 'error-message "Invalid slot name")
2596
2597(intern "invalid-slot-type")
2598(put 'invalid-slot-type 'error-conditions '(invalid-slot-type error nil))
2599(put 'invalid-slot-type 'error-message "Invalid slot type")
2600
2601(intern "unbound-slot")
2602(put 'unbound-slot 'error-conditions '(unbound-slot error nil))
2603(put 'unbound-slot 'error-message "Unbound slot")
2604
2605(intern "inconsistent-class-hierarchy")
2606(put 'inconsistent-class-hierarchy 'error-conditions
2607 '(inconsistent-class-hierarchy error nil))
2608(put 'inconsistent-class-hierarchy 'error-message "Inconsistent class hierarchy")
2609 529
2610;;; Here are some CLOS items that need the CL package 530;;; Here are some CLOS items that need the CL package
2611;; 531;;
@@ -2678,7 +598,7 @@ Called from the constructor routine.")
2678(defmethod shared-initialize ((obj eieio-default-superclass) slots) 598(defmethod shared-initialize ((obj eieio-default-superclass) slots)
2679 "Set slots of OBJ with SLOTS which is a list of name/value pairs. 599 "Set slots of OBJ with SLOTS which is a list of name/value pairs.
2680Called from the constructor routine." 600Called from the constructor routine."
2681 (let ((scoped-class (eieio--object-class obj))) 601 (eieio--with-scoped-class (eieio--object-class obj)
2682 (while slots 602 (while slots
2683 (let ((rn (eieio-initarg-to-attribute (eieio--object-class obj) 603 (let ((rn (eieio-initarg-to-attribute (eieio--object-class obj)
2684 (car slots)))) 604 (car slots))))
@@ -2700,27 +620,27 @@ call `shared-initialize' yourself, or you can call `call-next-method'
2700to have this constructor called automatically. If these steps are 620to have this constructor called automatically. If these steps are
2701not taken, then new objects of your class will not have their values 621not taken, then new objects of your class will not have their values
2702dynamically set from SLOTS." 622dynamically set from SLOTS."
2703 ;; First, see if any of our defaults are `lambda', and 623 ;; First, see if any of our defaults are `lambda', and
2704 ;; re-evaluate them and apply the value to our slots. 624 ;; re-evaluate them and apply the value to our slots.
2705 (let* ((scoped-class (class-v (eieio--object-class this))) 625 (let* ((this-class (class-v (eieio--object-class this)))
2706 (slot (eieio--class-public-a scoped-class)) 626 (slot (eieio--class-public-a this-class))
2707 (defaults (eieio--class-public-d scoped-class))) 627 (defaults (eieio--class-public-d this-class)))
2708 (while slot 628 (while slot
2709 ;; For each slot, see if we need to evaluate it. 629 ;; For each slot, see if we need to evaluate it.
2710 ;; 630 ;;
2711 ;; Paul Landes said in an email: 631 ;; Paul Landes said in an email:
2712 ;; > CL evaluates it if it can, and otherwise, leaves it as 632 ;; > CL evaluates it if it can, and otherwise, leaves it as
2713 ;; > the quoted thing as you already have. This is by the 633 ;; > the quoted thing as you already have. This is by the
2714 ;; > Sonya E. Keene book and other things I've look at on the 634 ;; > Sonya E. Keene book and other things I've look at on the
2715 ;; > web. 635 ;; > web.
2716 (let ((dflt (eieio-default-eval-maybe (car defaults)))) 636 (let ((dflt (eieio-default-eval-maybe (car defaults))))
2717 (when (not (eq dflt (car defaults))) 637 (when (not (eq dflt (car defaults)))
2718 (eieio-oset this (car slot) dflt) )) 638 (eieio-oset this (car slot) dflt) ))
2719 ;; Next. 639 ;; Next.
2720 (setq slot (cdr slot) 640 (setq slot (cdr slot)
2721 defaults (cdr defaults)))) 641 defaults (cdr defaults))))
2722 ;; Shared initialize will parse our slots for us. 642 ;; Shared initialize will parse our slots for us.
2723 (shared-initialize this slots)) 643 (shared-initialize this slots))
2724 644
2725(defgeneric slot-missing (object slot-name operation &optional new-value) 645(defgeneric slot-missing (object slot-name operation &optional new-value)
2726 "Method invoked when an attempt to access a slot in OBJECT fails.") 646 "Method invoked when an attempt to access a slot in OBJECT fails.")
@@ -2940,102 +860,6 @@ This may create or delete slots, but does not affect the return value
2940of `eq'." 860of `eq'."
2941 (error "EIEIO: `change-class' is unimplemented")) 861 (error "EIEIO: `change-class' is unimplemented"))
2942 862
2943)
2944
2945;;; Obsolete backward compatibility functions.
2946;; Needed to run byte-code compiled with the EIEIO of Emacs-23.
2947
2948(defun eieio-defmethod (method args)
2949 "Obsolete work part of an old version of the `defmethod' macro."
2950 (let ((key nil) (body nil) (firstarg nil) (argfix nil) (argclass nil) loopa)
2951 ;; find optional keys
2952 (setq key
2953 (cond ((memq (car args) '(:BEFORE :before))
2954 (setq args (cdr args))
2955 method-before)
2956 ((memq (car args) '(:AFTER :after))
2957 (setq args (cdr args))
2958 method-after)
2959 ((memq (car args) '(:STATIC :static))
2960 (setq args (cdr args))
2961 method-static)
2962 ((memq (car args) '(:PRIMARY :primary))
2963 (setq args (cdr args))
2964 method-primary)
2965 ;; Primary key.
2966 (t method-primary)))
2967 ;; Get body, and fix contents of args to be the arguments of the fn.
2968 (setq body (cdr args)
2969 args (car args))
2970 (setq loopa args)
2971 ;; Create a fixed version of the arguments.
2972 (while loopa
2973 (setq argfix (cons (if (listp (car loopa)) (car (car loopa)) (car loopa))
2974 argfix))
2975 (setq loopa (cdr loopa)))
2976 ;; Make sure there is a generic.
2977 (eieio-defgeneric
2978 method
2979 (if (stringp (car body))
2980 (car body) (format "Generically created method `%s'." method)))
2981 ;; create symbol for property to bind to. If the first arg is of
2982 ;; the form (varname vartype) and `vartype' is a class, then
2983 ;; that class will be the type symbol. If not, then it will fall
2984 ;; under the type `primary' which is a non-specific calling of the
2985 ;; function.
2986 (setq firstarg (car args))
2987 (if (listp firstarg)
2988 (progn
2989 (setq argclass (nth 1 firstarg))
2990 (if (not (class-p argclass))
2991 (error "Unknown class type %s in method parameters"
2992 (nth 1 firstarg))))
2993 ;; Generics are higher.
2994 (setq key (eieio-specialized-key-to-generic-key key)))
2995 ;; Put this lambda into the symbol so we can find it.
2996 (if (byte-code-function-p (car-safe body))
2997 (eieiomt-add method (car-safe body) key argclass)
2998 (eieiomt-add method (append (list 'lambda (reverse argfix)) body)
2999 key argclass))
3000 )
3001
3002 (when eieio-optimize-primary-methods-flag
3003 ;; Optimizing step:
3004 ;;
3005 ;; If this method, after this setup, only has primary methods, then
3006 ;; we can setup the generic that way.
3007 (if (generic-primary-only-p method)
3008 ;; If there is only one primary method, then we can go one more
3009 ;; optimization step.
3010 (if (generic-primary-only-one-p method)
3011 (eieio-defgeneric-reset-generic-form-primary-only-one method)
3012 (eieio-defgeneric-reset-generic-form-primary-only method))
3013 (eieio-defgeneric-reset-generic-form method)))
3014
3015 method)
3016(make-obsolete 'eieio-defmethod 'eieio--defmethod "24.1")
3017
3018(defun eieio-defgeneric (method doc-string)
3019 "Obsolete work part of an old version of the `defgeneric' macro."
3020 (if (and (fboundp method) (not (generic-p method))
3021 (or (byte-code-function-p (symbol-function method))
3022 (not (eq 'autoload (car (symbol-function method)))))
3023 )
3024 (error "You cannot create a generic/method over an existing symbol: %s"
3025 method))
3026 ;; Don't do this over and over.
3027 (unless (fboundp 'method)
3028 ;; This defun tells emacs where the first definition of this
3029 ;; method is defined.
3030 `(defun ,method nil)
3031 ;; Make sure the method tables are installed.
3032 (eieiomt-install method)
3033 ;; Apply the actual body of this function.
3034 (fset method (eieio-defgeneric-form method doc-string))
3035 ;; Return the method
3036 'method))
3037(make-obsolete 'eieio-defgeneric nil "24.1")
3038
3039;;; Interfacing with edebug 863;;; Interfacing with edebug
3040;; 864;;
3041(defun eieio-edebug-prin1-to-string (object &optional noescape) 865(defun eieio-edebug-prin1-to-string (object &optional noescape)