-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrename-sgml-tag.el
61 lines (55 loc) · 2.01 KB
/
rename-sgml-tag.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;; rename-sgml-tag.el --- Rename tag (including closing tag)
;;
;; Copyright (C) 2011 Magnar Sveen
;;
;; Author: Magnar Sveen <[email protected]>
;; Keywords: html tags editing
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; Rename the current tag (closest from point nesting-wise).
;;
;; (require 'rename-sgml-tag)
;; (define-key sgml-mode-map (kbd "C-c C-r") 'rename-sgml-tag)
;;
;; This extension is dependent on the mark-multiple library.
;; https://github.com/magnars/mark-multiple.el
;;; Code:
(require 'mark-multiple)
(defun rst--inside-tag-p ()
(save-excursion
(not (null (sgml-get-context)))))
;;;###autoload
(defun rename-sgml-tag ()
(interactive)
(if (not (rst--inside-tag-p))
(error "Place point inside tag to rename."))
(let ((context (car (last (sgml-get-context)))))
(if (looking-at "</")
(setq context (car (last (sgml-get-context)))))
(goto-char (aref context 2))
(let* ((tag-name (aref context 4))
(num-chars (length tag-name))
(master-start (1+ (point)))
(mirror-end (save-excursion
(sgml-skip-tag-forward 1)
(1- (point)))))
(forward-char 1)
(set-mark (+ (point) num-chars))
(mm/create-master master-start (+ master-start num-chars))
(mm/add-mirror (- mirror-end num-chars) mirror-end))))
(provide 'rename-sgml-tag)
;;; rename-sgml-tag.el ends here