;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User customizable variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defvar yas/key-syntax "w"
- "Syntax of a key. This is used to determine the current key being
-expanded.")
+(defvar yas/key-syntaxes (list "w" "w_" "w_." "^ ")
+ "A list of syntax of a key. This list is tried in the order
+to try to find a key. For example, if the list is '(\"w\" \"w_\").
+And in emacs-lisp-mode, where \"-\" has the syntax of \"_\":
+
+foo-bar
+
+will first try \"bar\", if not found, then \"foo-bar\" is tried.")
(defvar yas/indent-line t
"Each (except the 1st) line of the snippet template is indented to
(yas/snippet-groups snippet)
:test
'(lambda (field group)
- (= (yas/field-number field)
- (yas/group-number group))))))
+ (and (not (null (yas/field-number field)))
+ (= (yas/field-number field)
+ (yas/group-number group)))))))
(if group
(yas/group-add-field group field)
(push (yas/make-group field snippet)
"Get the key under current position. A key is used to find
the template of a snippet in the current snippet-table."
(let ((start (point))
- (end (point)))
- (save-excursion
- (skip-syntax-backward yas/key-syntax)
- (setq start (point))
- (list (buffer-substring-no-properties start end)
- start
- end))))
+ (end (point))
+ (syntaxes yas/key-syntaxes)
+ syntax done)
+ (while (and (not done) syntaxes)
+ (setq syntax (car syntaxes))
+ (setq syntaxes (cdr syntaxes))
+ (save-excursion
+ (skip-syntax-backward syntax)
+ (when (gethash (buffer-substring-no-properties (point) end)
+ (yas/current-snippet-table))
+ (setq done t)
+ (setq start (point)))))
+ (list (buffer-substring-no-properties start end)
+ start
+ end)))
(defun yas/synchronize-fields (field-group)
"Update all fields' text according to the primary field."
(defun yas/fake-keymap-for-popup (templates)
"Create a fake keymap for popup menu usage."
(cons 'keymap
- (cons "Select a template:"
- (mapcar (lambda (pair)
- (let* ((template (cdr pair))
- (name (yas/template-name template))
- (content (yas/template-content template)))
- (list content 'menu-item name t)))
- templates))))
+ (mapcar (lambda (pair)
+ (let* ((template (cdr pair))
+ (name (yas/template-name template))
+ (content (yas/template-content template)))
+ (list content 'menu-item name t)))
+ templates)))
+
+(defun yas/point-to-coord (&optional point)
+ "Get the xoffset/yoffset information of POINT.
+If POINT is not given, default is to current point."
+ (let* ((pn (posn-at-point (or point (point))))
+ (x-y (posn-x-y pn))
+ (x (car x-y))
+ (y (cdr x-y))
+ (coord (list (list (+ x 10) (+ y 20)) (selected-window))))
+ coord))
(defun yas/popup-for-template (templates)
"Show a popup menu listing templates to let the user select one."
(if window-system
- (car (x-popup-menu t (yas/fake-keymap-for-popup templates)))
+ (car (x-popup-menu (yas/point-to-coord) (yas/fake-keymap-for-popup templates)))
;; no window system, simply select the first one
(cdar templates)))