Function: srecode-create-dictionary

srecode-create-dictionary is a byte-compiled function defined in dictionary.el.gz.

Signature

(srecode-create-dictionary &optional BUFFER-OR-PARENT)

Documentation

Create a dictionary for BUFFER-OR-PARENT.

If BUFFER-OR-PARENT is not specified, assume a buffer, and use the current buffer. If BUFFER-OR-PARENT is another dictionary, then remember the parent within the new dictionary, and assume that BUFFER is the same as belongs to the parent dictionary. The dictionary is initialized with variables setup for that buffer's table. If BUFFER-OR-PARENT is t, then this dictionary should not be associated with a buffer or parent.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/srecode/dictionary.el.gz
;;; DICTIONARY METHODS
;;

(defun srecode-create-dictionary (&optional buffer-or-parent)
  "Create a dictionary for BUFFER-OR-PARENT.
If BUFFER-OR-PARENT is not specified, assume a buffer, and
use the current buffer.
If BUFFER-OR-PARENT is another dictionary, then remember the
parent within the new dictionary, and assume that BUFFER
is the same as belongs to the parent dictionary.
The dictionary is initialized with variables setup for that
buffer's table.
If BUFFER-OR-PARENT is t, then this dictionary should not be
associated with a buffer or parent."
  (save-excursion
    ;; Handle the parent
    (let ((parent nil)
	  (buffer nil)
	  (origin nil)
	  (initfrombuff nil))
      (cond
       ;; Parent is a buffer
       ((bufferp buffer-or-parent)
	(set-buffer buffer-or-parent)
	(setq buffer buffer-or-parent
	      origin (buffer-name buffer-or-parent)
	      initfrombuff t))

       ;; Parent is another dictionary
       ((cl-typep buffer-or-parent 'srecode-dictionary)
	(setq parent buffer-or-parent
	      buffer (oref buffer-or-parent buffer)
	      origin (concat (eieio-object-name buffer-or-parent) " in "
			     (if buffer (buffer-name buffer)
			       "no buffer")))
	(when buffer
	  (set-buffer buffer)))

       ;; No parent
       ((eq buffer-or-parent t)
	(setq buffer nil
	      origin "Unspecified Origin"))

       ;; Default to unspecified parent
       (t
	(setq buffer (current-buffer)
	      origin (concat "Unspecified.  Assume "
			     (buffer-name buffer))
	      initfrombuff t)))

      ;; Create the new dictionary object.
      (let ((dict (make-instance
                   'srecode-dictionary
		   :buffer   buffer
		   :parent   parent
		   :namehash (make-hash-table :test 'equal
					      :size 20)
		   :origin   origin)))
	;; Only set up the default variables if we are being built
	;; directly for a particular buffer.
	(when initfrombuff
	  ;; Variables from the table we are inserting from.
	  ;; @todo - get a better tree of tables.
	  (let ((mt (srecode-get-mode-table major-mode))
		(def (srecode-get-mode-table 'default)))
	    ;; Each table has multiple template tables.
	    ;; Do DEF first so that MT can override any values.
	    (srecode-dictionary-add-template-table dict def)
	    (srecode-dictionary-add-template-table dict mt)
	    ))
	dict))))