* Fixed more bugs, probably more hiding in 3300+ lines

This commit is contained in:
capitaomorte 2009-08-13 01:46:52 +00:00
parent 8420238a19
commit ceabe9376e

View File

@ -549,28 +549,28 @@ Here's an example:
["System X-widget" (setq yas/prompt-functions ["System X-widget" (setq yas/prompt-functions
(cons 'yas/x-prompt (cons 'yas/x-prompt
(remove 'yas/x-prompt (remove 'yas/x-prompt
(yas/prompt-functions)))) yas/prompt-functions)))
:help "Use your windowing system's (gtk, mac, windows, etc...) default menu" :help "Use your windowing system's (gtk, mac, windows, etc...) default menu"
:active t :style radio :selected (eq (car yas/prompt-functions) :active t :style radio :selected (eq (car yas/prompt-functions)
'yas/x-prompt)] 'yas/x-prompt)]
["Dropdown-list" (setq yas/prompt-functions ["Dropdown-list" (setq yas/prompt-functions
(cons 'yas/dropdown-prompt (cons 'yas/dropdown-prompt
(remove 'yas/dropdown-prompt (remove 'yas/dropdown-prompt
(yas/prompt-functions)))) yas/prompt-functions)))
:help "Use a special dropdown list" :help "Use a special dropdown list"
:active t :style radio :selected (eq (car yas/prompt-functions) :active t :style radio :selected (eq (car yas/prompt-functions)
'yas/dropdown-prompt)] 'yas/dropdown-prompt)]
["Ido" (setq yas/prompt-functions ["Ido" (setq yas/prompt-functions
(cons 'yas/ido-prompt (cons 'yas/ido-prompt
(remove 'yas/ido-prompt (remove 'yas/ido-prompt
(yas/prompt-functions)))) yas/prompt-functions)))
:help "Use an ido-style minibuffer prompt" :help "Use an ido-style minibuffer prompt"
:active t :style radio :selected (eq (car yas/prompt-functions) :active t :style radio :selected (eq (car yas/prompt-functions)
'yas/ido-prompt)] 'yas/ido-prompt)]
["Completing read" (setq yas/prompt-functions ["Completing read" (setq yas/prompt-functions
(cons 'yas/completing-prompt (cons 'yas/completing-prompt
(remove 'yas/completing-prompt-prompt (remove 'yas/completing-prompt-prompt
(yas/prompt-functions)))) yas/prompt-functions)))
:help "Use a normal minibuffer prompt" :help "Use a normal minibuffer prompt"
:active t :style radio :selected (eq (car yas/prompt-functions) :active t :style radio :selected (eq (car yas/prompt-functions)
'yas/completing-prompt-prompt)] 'yas/completing-prompt-prompt)]
@ -1176,34 +1176,35 @@ TEMPLATES is a list of `yas/template'."
;; ;;
(defun yas/load-directory-1 (directory &optional parents no-hierarchy-parents making-groups-sym) (defun yas/load-directory-1 (directory &optional parents no-hierarchy-parents making-groups-sym)
"Recursively load snippet templates from DIRECTORY." "Recursively load snippet templates from DIRECTORY."
;; TODO: Rewrite this horrible, horrible monster I created
(let* ((major-mode-and-parents (unless making-groups-sym (unless (file-exists-p (concat directory "/" ".yas-skip"))
(yas/compute-major-mode-and-parents (concat directory "/dummy") (let* ((major-mode-and-parents (unless making-groups-sym
nil (yas/compute-major-mode-and-parents (concat directory "/dummy")
no-hierarchy-parents))) nil
(mode-sym (and major-mode-and-parents no-hierarchy-parents)))
(car major-mode-and-parents))) (mode-sym (and major-mode-and-parents
(parents (if making-groups-sym (car major-mode-and-parents)))
parents (parents (if making-groups-sym
(rest major-mode-and-parents))) parents
(snippet-defs nil) (rest major-mode-and-parents)))
(make-groups-p (or making-groups-sym (snippet-defs nil)
(file-exists-p (concat directory "/" ".yas-make-groups"))))) (make-groups-p (or making-groups-sym
(with-temp-buffer (file-exists-p (concat directory "/" ".yas-make-groups")))))
(dolist (file (yas/subdirs directory 'no-subdirs-just-files)) (with-temp-buffer
(when (file-readable-p file) (dolist (file (yas/subdirs directory 'no-subdirs-just-files))
(insert-file-contents file nil nil nil t) (when (file-readable-p file)
(push (yas/parse-template file) (insert-file-contents file nil nil nil t)
snippet-defs)))) (push (yas/parse-template file)
(yas/define-snippets (or mode-sym snippet-defs))))
making-groups-sym) (yas/define-snippets (or mode-sym
snippet-defs making-groups-sym)
parents) snippet-defs
(dolist (subdir (yas/subdirs directory)) parents)
(if make-groups-p (dolist (subdir (yas/subdirs directory))
(yas/load-directory-1 subdir parents 't (or mode-sym (if make-groups-p
making-groups-sym)) (yas/load-directory-1 subdir parents 't (or mode-sym
(yas/load-directory-1 subdir (list mode-sym)))))) making-groups-sym))
(yas/load-directory-1 subdir (list mode-sym)))))))
(defun yas/load-directory (directory) (defun yas/load-directory (directory)
"Load snippet definition from a directory hierarchy. "Load snippet definition from a directory hierarchy.
@ -1493,14 +1494,14 @@ its parent modes."
;; a key and a name for the snippet, because that is what ;; a key and a name for the snippet, because that is what
;; indexes the snippet tables ;; indexes the snippet tables
;; ;;
(setq template (yas/make-template (second snippet)
(or name key)
condition
(sixth snippet)
(seventh snippet)
keybinding))
(when (and key (when (and key
name) name)
(setq template (yas/make-template (second snippet)
(or name key)
condition
(sixth snippet)
(seventh snippet)
keybinding))
(yas/snippet-table-store snippet-table (yas/snippet-table-store snippet-table
name name
key key
@ -1544,9 +1545,9 @@ its parent modes."
(define-key group-keymap (vector (gensym)) (define-key group-keymap (vector (gensym))
`(menu-item ,(yas/template-name template) `(menu-item ,(yas/template-name template)
,(yas/make-menu-binding template) ,(yas/make-menu-binding template)
:help name :help ,name
:keys (when (and key name) :keys ,(when (and key name)
,(concat key yas/trigger-symbol)))))))))) (concat key yas/trigger-symbol))))))))))
(defun yas/show-menu-p (mode) (defun yas/show-menu-p (mode)
(message "what") (message "what")
@ -3290,11 +3291,12 @@ When multiple expressions are found, only the last one counts."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; `locate-dominating-file' is added for compatibility in emacs < 23 ;;; `locate-dominating-file' is added for compatibility in emacs < 23
(unless (eq emacs-major-version 23) (eval-when-compile
(unless (or (eq emacs-major-version 23)
(defvar locate-dominating-stop-dir-regexp (fboundp 'locate-dominating-file))
"\\`\\(?:[\\/][\\/][^\\/]+[\\/]\\|/\\(?:net\\|afs\\|\\.\\.\\.\\)/\\)\\'" (defvar locate-dominating-stop-dir-regexp
"Regexp of directory names which stop the search in `locate-dominating-file'. "\\`\\(?:[\\/][\\/][^\\/]+[\\/]\\|/\\(?:net\\|afs\\|\\.\\.\\.\\)/\\)\\'"
"Regexp of directory names which stop the search in `locate-dominating-file'.
Any directory whose name matches this regexp will be treated like Any directory whose name matches this regexp will be treated like
a kind of root directory by `locate-dominating-file' which will stop its search a kind of root directory by `locate-dominating-file' which will stop its search
when it bumps into it. when it bumps into it.
@ -3302,74 +3304,44 @@ The default regexp prevents fruitless and time-consuming attempts to find
special files in directories in which filenames are interpreted as hostnames, special files in directories in which filenames are interpreted as hostnames,
or mount points potentially requiring authentication as a different user.") or mount points potentially requiring authentication as a different user.")
;; (defun locate-dominating-files (file regexp) (defun locate-dominating-file (file name)
;; "Look up the directory hierarchy from FILE for a file matching REGEXP. "Look up the directory hierarchy from FILE for a file named NAME.
;; Stop at the first parent where a matching file is found and return the list
;; of files that that match in this directory."
;; (catch 'found
;; ;; `user' is not initialized yet because `file' may not exist, so we may
;; ;; have to walk up part of the hierarchy before we find the "initial UID".
;; (let ((user nil)
;; ;; Abbreviate, so as to stop when we cross ~/.
;; (dir (abbreviate-file-name (file-name-as-directory file)))
;; files)
;; (while (and dir
;; ;; As a heuristic, we stop looking up the hierarchy of
;; ;; directories as soon as we find a directory belonging to
;; ;; another user. This should save us from looking in
;; ;; things like /net and /afs. This assumes that all the
;; ;; files inside a project belong to the same user.
;; (let ((prev-user user))
;; (setq user (nth 2 (file-attributes dir)))
;; (or (null prev-user) (equal user prev-user))))
;; (if (setq files (condition-case nil
;; (directory-files dir 'full regexp 'nosort)
;; (error nil)))
;; (throw 'found files)
;; (if (equal dir
;; (setq dir (file-name-directory
;; (directory-file-name dir))))
;; (setq dir nil))))
;; nil)))
(defun locate-dominating-file (file name)
"Look up the directory hierarchy from FILE for a file named NAME.
Stop at the first parent directory containing a file NAME, Stop at the first parent directory containing a file NAME,
and return the directory. Return nil if not found." and return the directory. Return nil if not found."
;; We used to use the above locate-dominating-files code, but the ;; We used to use the above locate-dominating-files code, but the
;; directory-files call is very costly, so we're much better off doing ;; directory-files call is very costly, so we're much better off doing
;; multiple calls using the code in here. ;; multiple calls using the code in here.
;; ;;
;; Represent /home/luser/foo as ~/foo so that we don't try to look for ;; Represent /home/luser/foo as ~/foo so that we don't try to look for
;; `name' in /home or in /. ;; `name' in /home or in /.
(setq file (abbreviate-file-name file)) (setq file (abbreviate-file-name file))
(let ((root nil) (let ((root nil)
(prev-file file) (prev-file file)
;; `user' is not initialized outside the loop because ;; `user' is not initialized outside the loop because
;; `file' may not exist, so we may have to walk up part of the ;; `file' may not exist, so we may have to walk up part of the
;; hierarchy before we find the "initial UID". ;; hierarchy before we find the "initial UID".
(user nil) (user nil)
try) try)
(while (not (or root (while (not (or root
(null file) (null file)
;; FIXME: Disabled this heuristic because it is sometimes ;; FIXME: Disabled this heuristic because it is sometimes
;; inappropriate. ;; inappropriate.
;; As a heuristic, we stop looking up the hierarchy of ;; As a heuristic, we stop looking up the hierarchy of
;; directories as soon as we find a directory belonging ;; directories as soon as we find a directory belonging
;; to another user. This should save us from looking in ;; to another user. This should save us from looking in
;; things like /net and /afs. This assumes that all the ;; things like /net and /afs. This assumes that all the
;; files inside a project belong to the same user. ;; files inside a project belong to the same user.
;; (let ((prev-user user)) ;; (let ((prev-user user))
;; (setq user (nth 2 (file-attributes file))) ;; (setq user (nth 2 (file-attributes file)))
;; (and prev-user (not (equal user prev-user)))) ;; (and prev-user (not (equal user prev-user))))
(string-match locate-dominating-stop-dir-regexp file))) (string-match locate-dominating-stop-dir-regexp file)))
(setq try (file-exists-p (expand-file-name name file))) (setq try (file-exists-p (expand-file-name name file)))
(cond (try (setq root file)) (cond (try (setq root file))
((equal file (setq prev-file file ((equal file (setq prev-file file
file (file-name-directory file (file-name-directory
(directory-file-name file)))) (directory-file-name file))))
(setq file nil)))) (setq file nil))))
root))) root))))
(provide 'yasnippet) (provide 'yasnippet)