diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/css-abbrev.el | 10 | ||||
-rw-r--r-- | src/html-abbrev.el | 59 | ||||
-rw-r--r-- | src/init.el | 9 | ||||
-rw-r--r-- | src/mode-def.el | 40 |
4 files changed, 64 insertions, 54 deletions
diff --git a/src/css-abbrev.el b/src/css-abbrev.el index 7e2fe9f..edc09ca 100644 --- a/src/css-abbrev.el +++ b/src/css-abbrev.el @@ -46,9 +46,9 @@ (let ((rgb-mode (string= (elt it 2) "rgb"))) (if rgb-mode (format "rgb(%d,%d,%d)" - (string-to-int (substring color 0 2) 16) - (string-to-int (substring color 2 4) 16) - (string-to-int (substring color 4 6) 16)) + (string-to-number (substring color 0 2) 16) + (string-to-number (substring color 2 4) 16) + (string-to-number (substring color 4 6) 16)) (concat "#" (let ((filter (cond ((string= emmet-css-color-case "auto") #'identity) @@ -160,7 +160,7 @@ "\\):.*$")) (defun emmet-css-instantiate-lambda (str) - (flet ((insert-space-between-name-and-body + (cl-flet ((insert-space-between-name-and-body (str) (if (string-match "^\\([a-z-]+:\\)\\(.+\\)$" str) (emmet-join-string @@ -176,7 +176,7 @@ (mapcar (lambda (ref) (match-string ref str)) '(0 1 2)) (setf rt `((or - (nth ,(let ((cur-idx (if idx (1- (string-to-int idx)) i))) + (nth ,(let ((cur-idx (if idx (1- (string-to-number idx)) i))) (setf idx-max (max cur-idx idx-max))) ,args-sym) ,(or def "")) diff --git a/src/html-abbrev.el b/src/html-abbrev.el index 0c5411c..0c3519b 100644 --- a/src/html-abbrev.el +++ b/src/html-abbrev.el @@ -76,7 +76,7 @@ `((n ,(length doller) t 1) . ,input))))) (defun emmet-split-numbering-expressions (input) - (labels + (cl-labels ((iter (input) (emmet-aif (emmet-regex "\\([^$]*\\)\\(\\$.*\\)" input '(1 2)) (let ((prefix (car it)) @@ -94,7 +94,7 @@ `(numberings ,@res))))) (defun emmet-instantiate-numbering-expression (i lim exp) - (labels ((instantiate + (cl-labels ((instantiate (i lim exps) (apply #'concat (mapcar @@ -308,31 +308,34 @@ (defun emmet-parent-child (input) "Parse an tag>e expression, where `n' is an tag and `e' is any expression." - (defun listing (parents child input) - (let ((len (length parents))) - `((list ,(map 'list - (lambda (parent i) - `(parent-child ,parent - ,(emmet-instantiate-numbering-expression i len child))) - parents - (loop for i to (- len 1) collect i))) . ,input))) - (emmet-run emmet-multiplier - (let* ((items (cadr expr)) - (rest (emmet-child-sans expr input))) - (if (not (eq (car rest) 'error)) - (let ((child (car rest)) - (input (cdr rest))) - - (emmet-aif (emmet-regex "^" input '(0 1)) - (let ((input (elt it 1))) - (emmet-run emmet-subexpr - `((sibling ,(car (listing items child "")) ,expr) . ,input) - (listing items child input))) - (listing items child input))) - '(error "expected child"))) - (emmet-run emmet-tag - (emmet-child expr input) - '(error "expected parent")))) + (cl-labels + ((listing (parents child input) + (let ((len (length parents))) + `((list ,(map 'list + (lambda (parent i) + `(parent-child ,parent + ,(emmet-instantiate-numbering-expression i len child))) + parents + (loop for i to (- len 1) collect i))) . ,input)))) + (emmet-run + emmet-multiplier + (let* ((items (cadr expr)) + (rest (emmet-child-sans expr input))) + (if (not (eq (car rest) 'error)) + (let ((child (car rest)) + (input (cdr rest))) + + (emmet-aif (emmet-regex "^" input '(0 1)) + (let ((input (elt it 1))) + (emmet-run + emmet-subexpr + `((sibling ,(car (listing items child "")) ,expr) . ,input) + (listing items child input))) + (listing items child input))) + '(error "expected child"))) + (emmet-run emmet-tag + (emmet-child expr input) + '(error "expected parent"))))) (defun emmet-child-sans (parent input) (emmet-parse ">" 1 ">" @@ -504,7 +507,7 @@ '(1 2)) (list src))) (split-string src "\n")))) - (labels + (cl-labels ((iter (l m a b) (if l diff --git a/src/init.el b/src/init.el index c6095f1..ca412eb 100644 --- a/src/init.el +++ b/src/init.el @@ -4,7 +4,14 @@ (defconst emmet-mode:version "1.0.10") -(require 'cl) +(with-no-warnings + (require 'cl)) + +;; for portability with < 24.3 EMACS +(unless (fboundp 'cl-labels) (fset 'cl-labels 'labels)) +(unless (fboundp 'cl-flet) (fset 'cl-flet 'flet)) +;; < 22.1 +(unless (fboundp 'string-to-number) (fset 'string-to-number 'string-to-int)) (defmacro emmet-defparameter (symbol &optional initvalue docstring) `(progn diff --git a/src/mode-def.el b/src/mode-def.el index ffb090a..d04f805 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -76,17 +76,6 @@ e. g. without semicolons") (emmet-css-transform input) (emmet-html-transform input))) -(defun emmet-reposition-cursor (expr) - (let ((output-markup (buffer-substring-no-properties (second expr) (point)))) - (when emmet-move-cursor-after-expanding - (let ((p (point)) - (new-pos (if (emmet-html-text-p output-markup) - (emmet-html-next-insert-point output-markup) - (emmet-css-next-insert-point output-markup)))) - (goto-char - (+ (- p (length output-markup)) - new-pos)))))) - (defun emmet-detect-style-tag-and-attr () (let* ((style-attr-end "[^=][\"']") (style-attr-begin "style=[\"']") @@ -106,6 +95,11 @@ e. g. without semicolons") (or (not end-back) (> begin-back end-back)) (or (not begin-front) (< end-front begin-front))))) +(defcustom emmet-preview-default t + "If non-nil then preview is the default action. +This determines how `emmet-expand-line' works by default." + :type 'boolean + :group 'emmet) ;;;###autoload (defun emmet-expand-line (arg) @@ -200,9 +194,10 @@ See also `emmet-expand-line'." (delete-region (second expr) (third expr)) (insert filled) (indent-region (second expr) (point)) - (yas/expand-snippet - (buffer-substring (second expr) (point)) - (second expr) (point)))))) + (if (fboundp 'yas/expand-snippet) + (yas/expand-snippet + (buffer-substring (second expr) (point)) + (second expr) (point))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Real-time preview @@ -278,12 +273,6 @@ See also `emmet-expand-line'." (delete-overlay emmet-flash-ovl)) (setq emmet-flash-ovl nil))) -(defcustom emmet-preview-default t - "If non-nil then preview is the default action. -This determines how `emmet-expand-line' works by default." - :type 'boolean - :group 'emmet) - (defcustom emmet-insert-flash-time 0.5 "Time to flash insertion. Set this to a negative number if you do not want flashing the @@ -303,6 +292,17 @@ cursor position will be moved to after the first quote." :type 'boolean :group 'emmet) +(defun emmet-reposition-cursor (expr) + (let ((output-markup (buffer-substring-no-properties (second expr) (point)))) + (when emmet-move-cursor-after-expanding + (let ((p (point)) + (new-pos (if (emmet-html-text-p output-markup) + (emmet-html-next-insert-point output-markup) + (emmet-css-next-insert-point output-markup)))) + (goto-char + (+ (- p (length output-markup)) + new-pos)))))) + (defun emmet-insert-and-flash (markup) (emmet-remove-flash-ovl (current-buffer)) (let ((here (point))) |