Skip to main content
added 1353 characters in body
Source Link
chen bin
  • 5k
  • 21
  • 36
(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)
 
(defun html-jumpget-forwardtag (&optional)
 num (let ((b (line-beginning-position))
  "Jump forward from    (e (line-end-position))
        (looping t)
        (html-tag-char open(string-to-char tag""<"))
        (char (following-char))
        (interactivep "P"(point))
        (found_tag -1)) 

    (save-excursion
      ;; search backward
      (unless num(= char html-tag-char)
        (while (and looping (<= b (point)) (not (= char 60)))
          (setq numchar 1(following-char))
  ;; web       (setq p (point))
          (if (= p (point-modemin))
              ;; need get out of loop anyway
              (setq looping nil)
            (backward-char))))

      ;; search forward
      (if (not (= char html-sexptag-char))
 is assigned to forward      (save-sexpexcursion
            (while (and (>= e (point)) (not (= char 60)))
              (setq char (following-functionchar))
  ;; it's buggy in web        (setq p (point))
              (forward-modechar))))

 v11, here    ;; is theend workaroundtag?
      (letwhen (and (backup= char html-forwardtag-sexpchar) (< p e))
        (goto-functionchar p)
        (forward-sexpchar)
        (if (= (following-functionchar) 47)
            (sgml-progn
              ;; </
              (skip-tagchars-forward num"^>")
              (forward-char)
              (setq p (point))
              (setq found_tag 1))
          (progn
            ;; < , looks fine
            (backward-char)
            (setq found_tag 0)))))
    found_tag))

(defun html-jump-backward(&optional num)
  "Jump forward from html closeopen tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (if (= (html-get-tag) 0)
        (sgml-skip-tag-forward num)
      (sgml-skip-tag-backward num))))

ItUsage: M-x html-jump, it works in any html related major mode (php-mode, xml-mode, web-mode, nxml-mode ....)

(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)
 
(defun html-jump-forward(&optional num)
  "Jump forward from html open tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-forward num)))

(defun html-jump-backward(&optional num)
  "Jump forward from html close tag"
  (interactive "P")
  (unless num (setq num 1))
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-backward num)))

It works in any html related major mode (php-mode, xml-mode, web-mode, nxml-mode ....)

(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)
(defun html-get-tag ()
  (let ((b (line-beginning-position))
        (e (line-end-position))
        (looping t)
        (html-tag-char (string-to-char "<"))
        (char (following-char))
        (p (point))
        (found_tag -1)) 

    (save-excursion
      ;; search backward
      (unless (= char html-tag-char)
        (while (and looping (<= b (point)) (not (= char 60)))
          (setq char (following-char))
          (setq p (point))
          (if (= p (point-min))
              ;; need get out of loop anyway
              (setq looping nil)
            (backward-char))))

      ;; search forward
      (if (not (= char html-tag-char))
          (save-excursion
            (while (and (>= e (point)) (not (= char 60)))
              (setq char (following-char))
              (setq p (point))
              (forward-char))))

      ;; is end tag?
      (when (and (= char html-tag-char) (< p e))
        (goto-char p)
        (forward-char)
        (if (= (following-char) 47)
            (progn
              ;; </
              (skip-chars-forward "^>")
              (forward-char)
              (setq p (point))
              (setq found_tag 1))
          (progn
            ;; < , looks fine
            (backward-char)
            (setq found_tag 0)))))
    found_tag))

(defun html-jump(&optional num)
  "Jump forward from html open tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (if (= (html-get-tag) 0)
        (sgml-skip-tag-forward num)
      (sgml-skip-tag-backward num))))

Usage: M-x html-jump, it works in any html related major mode (php-mode, xml-mode, web-mode, nxml-mode ....)

added 90 characters in body
Source Link
chen bin
  • 5k
  • 21
  • 36

If you use evil-mode, you can install https://github.com/redguardtoo/evil-matchit and press %

If you prefer original Emacs,

(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)

(defun html-jump-forward(&optional num)
  "Jump forward from html open tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-forward num)))

(defun html-jump-backward(&optional num)
  "Jump forward from html close tag"
  (interactive "P")
  (unless num (setq num 1))
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-backward num)))

It works in any html related major mode (php-mode, xml-mode, web-mode, nxml-mode ....)

If you use evil-mode, you can install https://github.com/redguardtoo/evil-matchit and press %

If you prefer original Emacs,

(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)

(defun html-jump-forward(&optional num)
  "Jump forward from html open tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-forward num)))

(defun html-jump-backward(&optional num)
  "Jump forward from html close tag"
  (interactive "P")
  (unless num (setq num 1))
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-backward num)))

If you use evil-mode, you can install https://github.com/redguardtoo/evil-matchit and press %

If you prefer original Emacs,

(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)

(defun html-jump-forward(&optional num)
  "Jump forward from html open tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-forward num)))

(defun html-jump-backward(&optional num)
  "Jump forward from html close tag"
  (interactive "P")
  (unless num (setq num 1))
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-backward num)))

It works in any html related major mode (php-mode, xml-mode, web-mode, nxml-mode ....)

Source Link
chen bin
  • 5k
  • 21
  • 36

If you use evil-mode, you can install https://github.com/redguardtoo/evil-matchit and press %

If you prefer original Emacs,

(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)

(defun html-jump-forward(&optional num)
  "Jump forward from html open tag"
  (interactive "P")
  (unless num (setq num 1))
  ;; web-mode-forward-sexp is assigned to forward-sexp-function
  ;; it's buggy in web-mode v11, here is the workaround
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-forward num)))

(defun html-jump-backward(&optional num)
  "Jump forward from html close tag"
  (interactive "P")
  (unless num (setq num 1))
  (let ((backup-forward-sexp-function forward-sexp-function))
    (sgml-skip-tag-backward num)))