Bug fix for get-current-element-name
I wrote EmacsLisp function whose name is get-current-element-name in What kind of elements is Emacs cursor in? - Shammerism, but I found a bug. This bug finishes with error and not modifies a buffer content, so this bug affect isn't big.
The bug happened when cursor is within some elements, between < and >, or contents are not finished with closing elements. Latter case is likely an HTML bug. Here is a fixed version.
(defun get-current-element-name () (save-excursion (save-restriction (let* ((element-start (search-forward "</" nil t)) (element-end (search-forward ">" nil t))) (when (and element-start element-end) (buffer-substring element-start (- element-end 1)))))))
(let ((element (get-current-element-name))) (when element (let ((end (progn (search-forward (concat "</" element ">") nil t) (match-beginning 0))) (start (progn (re-search-backward (concat "<" element ".*>") nil t) (match-end 0))) (text-flag t)) (...))))