[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 1ead480ca1: Allow completing tags, parameters and values in html-
From: |
Lars Ingebrigtsen |
Subject: |
master 1ead480ca1: Allow completing tags, parameters and values in html-mode |
Date: |
Wed, 15 Jun 2022 12:31:16 -0400 (EDT) |
branch: master
commit 1ead480ca1f49b6759bb30353ee78656490149ae
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow completing tags, parameters and values in html-mode
* lisp/textmodes/sgml-mode.el (html-mode--complete-at-point):
Allow completing tags, parameters and values (bug#29057).
---
lisp/textmodes/sgml-mode.el | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index b49541f47d..ff881377a7 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -2409,6 +2409,7 @@ To work around that, do:
(lambda () (char-before (match-end 0))))
(setq-local add-log-current-defun-function #'html-current-defun-name)
(setq-local sentence-end-base "[.?!][]\"'”)}]*\\(<[^>]*>\\)*")
+ (add-hook 'completion-at-point-functions 'html-mode--complete-at-point nil t)
(when (fboundp 'libxml-parse-html-region)
(defvar css-class-list-function)
@@ -2434,6 +2435,36 @@ To work around that, do:
;; (setq imenu-sort-function nil) ; sorting the menu defeats the purpose
)
+(defun html-mode--complete-at-point ()
+ ;; Complete a tag like <colg etc.
+ (or
+ (when-let ((tag (save-excursion
+ (and (looking-back "<\\([^ \t\n]*\\)"
+ (line-beginning-position))
+ (match-string 1)))))
+ (list (match-beginning 1) (point)
+ (mapcar #'car html-tag-alist)))
+ ;; Complete params like <colgroup ali etc.
+ (when-let ((tag (save-excursion (sgml-beginning-of-tag)))
+ (params (seq-filter #'consp (cdr (assoc tag html-tag-alist))))
+ (param (save-excursion
+ (and (looking-back "[ \t\n]\\([^= \t\n]*\\)"
+ (line-beginning-position))
+ (match-string 1)))))
+ (list (match-beginning 1) (point)
+ (mapcar #'car params)))
+ ;; Complete param values like <colgroup align=mi etc.
+ (when-let ((tag (save-excursion (sgml-beginning-of-tag)))
+ (params (seq-filter #'consp (cdr (assoc tag html-tag-alist))))
+ (param (save-excursion
+ (and (looking-back
+ "[ \t\n]\\([^= \t\n]+\\)=\\([^= \t\n]*\\)"
+ (line-beginning-position))
+ (match-string 1))))
+ (values (cdr (assoc param params))))
+ (list (match-beginning 2) (point)
+ (mapcar #'car values)))))
+
(defun html-mode--html-yank-handler (_type html)
(save-restriction
(insert html)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 1ead480ca1: Allow completing tags, parameters and values in html-mode,
Lars Ingebrigtsen <=