mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
* Working on the html-bundle. Major work done, details missing...
* Fixed an aesthetic describe-key bug. * A serious "kill-line from snippet field" bug lurks somewhere
This commit is contained in:
parent
d6bf2427ea
commit
3d4d06df1d
1
extras/imported/html-mode/.yas-parents
Normal file
1
extras/imported/html-mode/.yas-parents
Normal file
@ -0,0 +1 @@
|
|||||||
|
text-mode
|
71
extras/imported/html-mode/.yas-setup.el
Normal file
71
extras/imported/html-mode/.yas-setup.el
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
(defvar yas/html-default-tag "p")
|
||||||
|
|
||||||
|
(defvar yas/html-xhtml-attr "")
|
||||||
|
|
||||||
|
(defvar yas/html-just-like-tm nil
|
||||||
|
"Html-mode snippets behave as close to TextMate as possible.")
|
||||||
|
|
||||||
|
|
||||||
|
(defun yas/html-remove-preceding-word ()
|
||||||
|
(interactive)
|
||||||
|
(let (word-begin
|
||||||
|
word-end
|
||||||
|
(orig-point (point))
|
||||||
|
retval)
|
||||||
|
(save-excursion
|
||||||
|
(forward-word -1)
|
||||||
|
(setq word-begin (point))
|
||||||
|
(forward-word 1)
|
||||||
|
(setq word-end (point)))
|
||||||
|
(when (and (> word-end word-begin)
|
||||||
|
(>= word-end (point)))
|
||||||
|
(setq retval
|
||||||
|
(cons
|
||||||
|
(buffer-substring-no-properties word-begin orig-point)
|
||||||
|
(buffer-substring-no-properties word-end orig-point)))
|
||||||
|
(delete-region word-begin word-end)
|
||||||
|
retval)))
|
||||||
|
|
||||||
|
|
||||||
|
(defun yas/html-first-word (string)
|
||||||
|
(replace-regexp-in-string "\\\W.*" "" string))
|
||||||
|
|
||||||
|
(defun yas/html-insert-tag-pair-snippet ()
|
||||||
|
(let* ((tag-and-suffix (or (and yas/selected-text
|
||||||
|
(cons yas/selected-text nil))
|
||||||
|
(yas/html-remove-preceding-word)))
|
||||||
|
(tag (car tag-and-suffix))
|
||||||
|
(suffix (or (cdr tag-and-suffix) ""))
|
||||||
|
(single-no-arg "\\(br\\|hr\\)")
|
||||||
|
(single "\\(img\\|meta\\|link\\|input\\|base\\|area\\|col\\|frame\\|param\\)"))
|
||||||
|
(cond ((null tag)
|
||||||
|
(yas/expand-snippet (format "<${1:%s}>%s</${1:$(yas/html-first-word yas/text)}>%s"
|
||||||
|
(or yas/html-default-tag
|
||||||
|
"p")
|
||||||
|
(if yas/html-just-like-tm "$2" "$0")
|
||||||
|
suffix)))
|
||||||
|
((string-match single-no-arg tag)
|
||||||
|
(insert (format "<%s%s/>%s" tag yas/html-xhtml-attr suffix)))
|
||||||
|
((string-match single tag)
|
||||||
|
(yas/expand-snippet (format "<%s $1%s/>%s" tag yas/html-xhtml-attr suffix)))
|
||||||
|
(t
|
||||||
|
(yas/expand-snippet (format "<%s>%s</%s>%s"
|
||||||
|
tag
|
||||||
|
(if yas/html-just-like-tm "$1" "$0")
|
||||||
|
(replace-regexp-in-string "\\\W.*" "" tag)
|
||||||
|
suffix))))))
|
||||||
|
|
||||||
|
(defun yas/html-wrap-each-line-in-openclose-tag ()
|
||||||
|
(let* ((mirror "${1:$(yas/html-first-word yas/text)}")
|
||||||
|
(template (concat (format "<${1:%s}>" (or yas/html-default-tag "p"))
|
||||||
|
yas/selected-text
|
||||||
|
"</" mirror ">")))
|
||||||
|
(setq template (replace-regexp-in-string "\n" (concat "</" mirror ">\n<" mirror ">") template))
|
||||||
|
(yas/expand-snippet template)))
|
||||||
|
|
||||||
|
(defun yas/html-between-tag-pair-p ()
|
||||||
|
(save-excursion
|
||||||
|
(backward-word)
|
||||||
|
(looking-at "\\\w+></\\\w+>")))
|
||||||
|
|
||||||
|
|
@ -1,48 +1,9 @@
|
|||||||
# -*- mode: snippet -*-
|
# -*- mode: snippet -*-
|
||||||
# type: command
|
# type: command
|
||||||
# contributor: joaotavora, adapted from TextMate HTML bundle, work in progress
|
# contributor: joaotavora, adapted from TextMate HTML bundle
|
||||||
# name: Insert Open/Close Tag (With Current Word)
|
# name: Insert Open/Close Tag (With Current Word)
|
||||||
|
# expand-env: ((yas/wrap-around-region t))
|
||||||
# binding: "^<"
|
# binding: "^<"
|
||||||
## condition: "text.html,"
|
## condition: "text.html,"
|
||||||
# --
|
# --
|
||||||
(let* ((tag yas/selected-text)
|
(yas/html-insert-tag-pair-snippet)
|
||||||
(single-no-arg "\\(br\\|hr\\)")
|
|
||||||
(single "\\(img\\|meta\\|link\\|input\\|base\\|area\\|col\\|frame\\|param\\)"))
|
|
||||||
(cond ((string-match single-no-arg yas/selected-text))))
|
|
||||||
# This script will expand the current word into: <word></word>
|
|
||||||
# It will recognize HTML 4.0 tags that need no close tag.
|
|
||||||
#
|
|
||||||
# With no current word, it will insert: <p></p> and allows you
|
|
||||||
# to overwrite the tag name and add potential arguments.
|
|
||||||
#
|
|
||||||
# The result is inserted as a snippet, so it's
|
|
||||||
# possible to tab through the place holders.
|
|
||||||
|
|
||||||
# single tags
|
|
||||||
single_no_arg = /^(?:br|hr)$/i
|
|
||||||
single = /^(?:img|meta|link|input|base|area|col|frame|param)$/i
|
|
||||||
|
|
||||||
# we are not in HTML mode, so let's scrap the above hardcoded tag lists
|
|
||||||
unless ENV.has_key? 'TM_HTML_EMPTY_TAGS' then
|
|
||||||
single_no_arg = /(?=not)possible/
|
|
||||||
single = /(?=not)possible/
|
|
||||||
end
|
|
||||||
|
|
||||||
# handle the case where caret is in the middle of a word, assume only the left part is the tag
|
|
||||||
index = ENV['TM_LINE_INDEX'].to_i - ENV['TM_INPUT_START_LINE_INDEX'].to_i
|
|
||||||
tag, suffix = STDIN.read, ''
|
|
||||||
if index < tag.length && !ENV['TM_SELECTED_TEXT']
|
|
||||||
tag, suffix = tag[0...index], tag[index..-1]
|
|
||||||
end
|
|
||||||
|
|
||||||
xhtml = ENV['TM_XHTML'].to_s
|
|
||||||
|
|
||||||
print case tag
|
|
||||||
when single_no_arg then "<#{tag}#{xhtml}>"
|
|
||||||
when single then "<#{tag} $1#{xhtml}>"
|
|
||||||
when '' then "<${1:#{ENV['TM_DEFAULT_TAG'] || 'p'}}>$2</${1/\\s.*//}>"
|
|
||||||
else "<#{tag}>$1</#{tag.strip[/^\S+/]}>"
|
|
||||||
end
|
|
||||||
|
|
||||||
print suffix
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# -*- mode: snippet -*-
|
# -*- mode: snippet -*-
|
||||||
# contributor: Translated from TextMate Snippet
|
# contributor: Translated from TextMate Snippet
|
||||||
# name: Special: Return Inside Empty Open/Close Tags
|
# name: Special: Return Inside Empty Open/Close Tags
|
||||||
## binding: "
"
|
# binding: "C-M"
|
||||||
## condition: "meta.scope.between-tag-pair"
|
# condition: (yas/html-between-tag-pair-p)
|
||||||
# --
|
# --
|
||||||
|
|
||||||
$0
|
$0
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# -*- mode: snippet -*-
|
# -*- mode: snippet -*-
|
||||||
# contributor: Translated from TextMate Snippet
|
# contributor: joaotavora, adapted from TextMate HTML bundle
|
||||||
# name: Wrap Selection in Open/Close Tag
|
# name: Wrap Selection in Open/Close Tag
|
||||||
## binding: "^W"
|
# binding: "C-S-w"
|
||||||
## condition: "text.html,"
|
# condition: mark-active
|
||||||
# --
|
# --
|
||||||
<${1:p}>`yas/selected-text`</${1/\s.*//}>
|
<${1:p}>`yas/selected-text`</${1:$(yas/html-first-word yas/text)}>
|
@ -1,6 +1,7 @@
|
|||||||
# -*- mode: snippet -*-
|
# -*- mode: snippet -*-
|
||||||
# contributor: Translated from TextMate Snippet
|
# contributor: Translated from TextMate Snippet
|
||||||
# name: Wrap in <?= … ?>
|
# name: Wrap in <?= … ?>
|
||||||
|
# expand-env: ((yas/wrap-around-region t))
|
||||||
## condition: "text.html string"
|
## condition: "text.html string"
|
||||||
# --
|
# --
|
||||||
<?= `yas/selected-text` ?>
|
<?= $0 ?>
|
52
yasnippet.el
52
yasnippet.el
@ -3294,7 +3294,8 @@ SNIPPET-MARKERS."
|
|||||||
(forward-line 1)))
|
(forward-line 1)))
|
||||||
(not (eobp))
|
(not (eobp))
|
||||||
(<= (point) end))
|
(<= (point) end))
|
||||||
(yas/indent-according-to-mode snippet-markers))))
|
(yas/indent-according-to-mode snippet-markers))
|
||||||
|
(yas/indent-according-to-mode snippet-markers)))
|
||||||
(t
|
(t
|
||||||
nil)))))
|
nil)))))
|
||||||
|
|
||||||
@ -3584,44 +3585,47 @@ When multiple expressions are found, only the last one counts."
|
|||||||
(put 'yas/expand 'function-documentation '(yas/expand-from-trigger-key-doc))
|
(put 'yas/expand 'function-documentation '(yas/expand-from-trigger-key-doc))
|
||||||
(defun yas/expand-from-trigger-key-doc ()
|
(defun yas/expand-from-trigger-key-doc ()
|
||||||
"A doc synthethizer for `yas/expand-from-trigger-key-doc'."
|
"A doc synthethizer for `yas/expand-from-trigger-key-doc'."
|
||||||
(let ((which-means (cond ((eq yas/fallback-behavior 'call-other-command)
|
(let ((fallback-description (cond ((eq yas/fallback-behavior 'call-other-command)
|
||||||
(concat ", which means that if no snippets are eligible then this\nfalls back to "
|
|
||||||
(let* ((yas/minor-mode nil)
|
(let* ((yas/minor-mode nil)
|
||||||
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
|
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
|
||||||
(or (and fallback
|
(or (and fallback
|
||||||
(format "the command `%s'." (pp-to-string fallback)))
|
(format " call command `%s'." (pp-to-string fallback)))
|
||||||
"nothing, in this case."))))
|
" do nothing.")))
|
||||||
((eq yas/fallback-behavior 'return-nil)
|
((eq yas/fallback-behavior 'return-nil)
|
||||||
", which means nothing is done if no snippets are eligible.")
|
", do nothing.")
|
||||||
(t
|
(t
|
||||||
", which means I hope you know what you're doing :-)"))))
|
", defer to `yas/fallback-behaviour' :-)"))))
|
||||||
(concat "Expand a snippet before point.
|
(concat "Expand a snippet before point. If no snippet
|
||||||
|
expansion is possible,"
|
||||||
If no snippet expansion is possible, fall back to the behaviour
|
fallback-description
|
||||||
defined in `yas/fallback-behavior' which in this case would be:\n\n"
|
"\n\nOptional argument FIELD is for non-interactive use and is an
|
||||||
(pp-to-string yas/fallback-behavior)
|
|
||||||
"\n\n"
|
|
||||||
which-means
|
|
||||||
"\n\nOptional argument FIELD is for non-interactive use and is an
|
|
||||||
object satisfying `yas/field-p' to restrict the expansion to.")))
|
object satisfying `yas/field-p' to restrict the expansion to.")))
|
||||||
|
|
||||||
(put 'yas/expand-from-keymap 'function-documentation '(yas/expand-from-keymap-doc))
|
(put 'yas/expand-from-keymap 'function-documentation '(yas/expand-from-keymap-doc))
|
||||||
(defun yas/expand-from-keymap-doc ()
|
(defun yas/expand-from-keymap-doc ()
|
||||||
"A doc synthethizer for `yas/expand-from-keymap-doc'."
|
"A doc synthethizer for `yas/expand-from-keymap-doc'."
|
||||||
(concat "Expand some snippets from keymaps.\n\n"
|
(concat "Expand some snippets from keymaps.\n\nMay fall back to original binding."
|
||||||
(when (eq this-command 'describe-key)
|
(when (eq this-command 'describe-key)
|
||||||
(let* ((vec (this-single-command-keys))
|
(let* ((vec (this-single-command-keys))
|
||||||
(templates (mapcan #'(lambda (table)
|
(templates (mapcan #'(lambda (table)
|
||||||
(yas/fetch table vec))
|
(yas/fetch table vec))
|
||||||
(yas/get-snippet-tables))))
|
(yas/get-snippet-tables)))
|
||||||
(concat "In this particular case my guess it is would expand the snippets:\n\n"
|
(yas/snippet-keymaps nil)
|
||||||
(mapconcat #'car templates "\n"))))
|
(fallback (key-binding vec)))
|
||||||
"\n\nIf no snippet expansion is possible then this falls back to \n"
|
(concat "In this particular case\nmy guess is it would "
|
||||||
(let* ((yas/minor-mode nil)
|
(when templates
|
||||||
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
|
(concat "expand the snippets:\n"
|
||||||
|
(yas/template-pretty-list templates)
|
||||||
|
"\n\nIf no expansion possible, "))
|
||||||
(or (and fallback
|
(or (and fallback
|
||||||
(format "the command `%s'." (pp-to-string fallback)))
|
(format "call command `%s'." (pp-to-string fallback)))
|
||||||
"nothing, in this case."))))
|
"do nothing."))))))
|
||||||
|
|
||||||
|
(defun yas/template-pretty-list (templates)
|
||||||
|
(let ((acc))
|
||||||
|
(dolist (plate templates)
|
||||||
|
(setq acc (concat acc "\n*) " (car plate))))
|
||||||
|
acc))
|
||||||
|
|
||||||
|
|
||||||
;;; Debug functions. Use (or change) at will whenever needed.
|
;;; Debug functions. Use (or change) at will whenever needed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user