mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
* another little fix and more cleanup
This commit is contained in:
parent
2c4dc70ab7
commit
35fa76296e
66
yasnippet.el
66
yasnippet.el
@ -135,9 +135,10 @@
|
|||||||
(require 'assoc)
|
(require 'assoc)
|
||||||
(require 'easymenu)
|
(require 'easymenu)
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; User customizable variables
|
;; User customizable variables
|
||||||
;;
|
|
||||||
|
|
||||||
(defgroup yasnippet nil
|
(defgroup yasnippet nil
|
||||||
"Yet Another Snippet extension"
|
"Yet Another Snippet extension"
|
||||||
@ -335,10 +336,9 @@ This cafn only work when snippets are loaded from files."
|
|||||||
"The face used for debugging some overlays normally hidden"
|
"The face used for debugging some overlays normally hidden"
|
||||||
:group 'yasnippet)
|
:group 'yasnippet)
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; User semi-customizable variables
|
;; User can also customize these
|
||||||
;;
|
|
||||||
|
|
||||||
(defvar yas/keymap (make-sparse-keymap)
|
(defvar yas/keymap (make-sparse-keymap)
|
||||||
"The keymap active while a snippet expansion is in progress.")
|
"The keymap active while a snippet expansion is in progress.")
|
||||||
|
|
||||||
@ -432,9 +432,10 @@ Here's an example:
|
|||||||
t))))")
|
t))))")
|
||||||
(make-variable-buffer-local 'yas/buffer-local-condition)
|
(make-variable-buffer-local 'yas/buffer-local-condition)
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Internal variables
|
;; Internal variables
|
||||||
;;
|
|
||||||
(defvar yas/version "0.6.1b")
|
(defvar yas/version "0.6.1b")
|
||||||
|
|
||||||
(defvar yas/snippet-tables (make-hash-table)
|
(defvar yas/snippet-tables (make-hash-table)
|
||||||
@ -482,10 +483,11 @@ Here's an example:
|
|||||||
(incf yas/snippet-id-seed)
|
(incf yas/snippet-id-seed)
|
||||||
id))
|
id))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Minor mode stuff
|
;; Minor mode stuff
|
||||||
;;
|
|
||||||
;; TODO: XXX: This is somehow needed in Carbon Emacs for MacOSX
|
;; XXX: `last-buffer-undo-list' is somehow needed in Carbon Emacs for MacOSX
|
||||||
(defvar last-buffer-undo-list nil)
|
(defvar last-buffer-undo-list nil)
|
||||||
|
|
||||||
(defvar yas/minor-mode-map (make-sparse-keymap)
|
(defvar yas/minor-mode-map (make-sparse-keymap)
|
||||||
@ -718,7 +720,6 @@ Key bindings:
|
|||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Internal structs for template management
|
;; Internal structs for template management
|
||||||
;;
|
|
||||||
|
|
||||||
(defstruct (yas/template (:constructor yas/make-template
|
(defstruct (yas/template (:constructor yas/make-template
|
||||||
(content name condition expand-env file keybinding)))
|
(content name condition expand-env file keybinding)))
|
||||||
@ -737,8 +738,8 @@ Key bindings:
|
|||||||
(parents nil))
|
(parents nil))
|
||||||
|
|
||||||
|
|
||||||
;;;; Filtering/condition login
|
;; Filtering/condition logic
|
||||||
;;;;
|
|
||||||
(defun yas/eval-condition (condition)
|
(defun yas/eval-condition (condition)
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(save-excursion
|
(save-excursion
|
||||||
@ -762,10 +763,26 @@ This function implements the rules described in
|
|||||||
(let ((requirement (yas/require-template-specific-condition-p)))
|
(let ((requirement (yas/require-template-specific-condition-p)))
|
||||||
(if (eq requirement 'always)
|
(if (eq requirement 'always)
|
||||||
templates
|
templates
|
||||||
(remove-if-not #'(lambda (pair)
|
p (remove-if-not #'(lambda (pair)
|
||||||
(yas/template-can-expand-p (yas/template-condition (cdr pair)) requirement))
|
(yas/template-can-expand-p (yas/template-condition (cdr pair)) requirement))
|
||||||
templates))))
|
templates))))
|
||||||
|
|
||||||
|
(defun yas/require-template-specific-condition-p ()
|
||||||
|
"Decides if this buffer requests/requires snippet-specific
|
||||||
|
conditions to filter out potential expansions."
|
||||||
|
(if (eq 'always yas/buffer-local-condition)
|
||||||
|
'always
|
||||||
|
(let ((local-condition (or (and (consp yas/buffer-local-condition)
|
||||||
|
(yas/eval-condition yas/buffer-local-condition))
|
||||||
|
yas/buffer-local-condition)))
|
||||||
|
(when local-condition
|
||||||
|
(if (eq local-condition t)
|
||||||
|
t
|
||||||
|
(and (consp local-condition)
|
||||||
|
(eq 'require-snippet-condition (car local-condition))
|
||||||
|
(symbolp (cdr local-condition))
|
||||||
|
(cdr local-condition)))))))
|
||||||
|
|
||||||
(defun yas/template-can-expand-p (condition &optional requirement)
|
(defun yas/template-can-expand-p (condition &optional requirement)
|
||||||
"Evaluates CONDITION and REQUIREMENT and returns a boolean"
|
"Evaluates CONDITION and REQUIREMENT and returns a boolean"
|
||||||
(let* ((requirement (or requirement
|
(let* ((requirement (or requirement
|
||||||
@ -864,9 +881,9 @@ the template of a snippet in the current snippet-table."
|
|||||||
template)
|
template)
|
||||||
(yas/snippet-table-hash table)))
|
(yas/snippet-table-hash table)))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Internal functions
|
;; Internal functions
|
||||||
;;
|
|
||||||
|
|
||||||
(defun yas/real-mode? (mode)
|
(defun yas/real-mode? (mode)
|
||||||
"Try to find out if MODE is a real mode. The MODE bound to
|
"Try to find out if MODE is a real mode. The MODE bound to
|
||||||
@ -1641,21 +1658,6 @@ will only be expanded when the condition evaluated to non-nil."
|
|||||||
(undo 1)
|
(undo 1)
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(defun yas/require-template-specific-condition-p ()
|
|
||||||
"Decides if this buffer requests/requires snippet-specific
|
|
||||||
conditions to filter out potential expansions."
|
|
||||||
(if (eq 'always yas/buffer-local-condition)
|
|
||||||
'always
|
|
||||||
(let ((local-condition (yas/eval-condition
|
|
||||||
yas/buffer-local-condition)))
|
|
||||||
(when local-condition
|
|
||||||
(if (eq local-condition t)
|
|
||||||
t
|
|
||||||
(and (consp local-condition)
|
|
||||||
(eq 'require-snippet-condition (car local-condition))
|
|
||||||
(symbolp (cdr local-condition))
|
|
||||||
(cdr local-condition)))))))
|
|
||||||
|
|
||||||
(defun yas/expand ()
|
(defun yas/expand ()
|
||||||
"Expand a snippet before point.
|
"Expand a snippet before point.
|
||||||
|
|
||||||
@ -1702,6 +1704,10 @@ defined in `yas/fallback-behavior'"
|
|||||||
;; also return nil if all the other fallbacks have failed
|
;; also return nil if all the other fallbacks have failed
|
||||||
nil)))))
|
nil)))))
|
||||||
|
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;; Snippet development
|
||||||
|
|
||||||
(defun yas/all-templates (tables)
|
(defun yas/all-templates (tables)
|
||||||
"Return all snippet tables applicable for the current buffer.
|
"Return all snippet tables applicable for the current buffer.
|
||||||
|
|
||||||
@ -1946,9 +1952,9 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(t
|
(t
|
||||||
(message "[yas] Cannot test snippet for unknown major mode")))))
|
(message "[yas] Cannot test snippet for unknown major mode")))))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; User convenience functions, for using in snippet definitions
|
;;; User convenience functions, for using in snippet definitions
|
||||||
;;;
|
|
||||||
|
|
||||||
(defvar yas/modified-p nil
|
(defvar yas/modified-p nil
|
||||||
"Non-nil if field has been modified by user or transformation.")
|
"Non-nil if field has been modified by user or transformation.")
|
||||||
@ -2005,6 +2011,10 @@ Otherwise throw exception."
|
|||||||
(when field
|
(when field
|
||||||
(yas/field-text-for-display field))))
|
(yas/field-text-for-display field))))
|
||||||
|
|
||||||
|
(defun yas/inside-string ()
|
||||||
|
(equal 'font-lock-string-face (get-char-property (1- (point)) 'face)))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; Snippet expansion and field management
|
;;; Snippet expansion and field management
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user