* 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:
capitaomorte
2009-11-02 18:08:20 +00:00
parent d6bf2427ea
commit 3d4d06df1d
7 changed files with 115 additions and 77 deletions

View File

@@ -0,0 +1 @@
text-mode

View 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+>")))

View File

@@ -1,48 +1,9 @@
# -*- mode: snippet -*-
# 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)
# expand-env: ((yas/wrap-around-region t))
# binding: "^<"
## condition: "text.html,"
# --
(let* ((tag yas/selected-text)
(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: &lt;word&gt;&lt;/word&gt;
# It will recognize HTML 4.0 tags that need no close tag.
#
# With no current word, it will insert: &lt;p&gt;&lt;/p&gt; 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 &lt; tag.length &amp;&amp; !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 "&lt;#{tag}#{xhtml}&gt;"
when single then "&lt;#{tag} $1#{xhtml}&gt;"
when '' then "&lt;${1:#{ENV['TM_DEFAULT_TAG'] || 'p'}}&gt;$2&lt;/${1/\\s.*//}&gt;"
else "&lt;#{tag}&gt;$1&lt;/#{tag.strip[/^\S+/]}&gt;"
end
print suffix
(yas/html-insert-tag-pair-snippet)

View File

@@ -1,8 +1,8 @@
# -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet
# name: Special: Return Inside Empty Open/Close Tags
## binding: "
"
# binding: "C-M"
# condition: (yas/html-between-tag-pair-p)
# --
$0

View File

@@ -1,7 +1,7 @@
# -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet
# contributor: joaotavora, adapted from TextMate HTML bundle
# name: Wrap Selection in Open/Close Tag
## binding: "^W"
## condition: "text.html,"
# binding: "C-S-w"
# condition: mark-active
# --
<${1:p}>`yas/selected-text`</${1/\s.*//}>
<${1:p}>`yas/selected-text`</${1:$(yas/html-first-word yas/text)}>

View File

@@ -1,6 +1,7 @@
# -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet
# name: Wrap in <?= … ?>
# expand-env: ((yas/wrap-around-region t))
## condition: "text.html string"
# --
<?= `yas/selected-text` ?>
<?= $0 ?>