branch: elpa/subed commit beda7dc5e75333832e44b778335876a7e5d6d195 Author: Marcin Borkowski <mb...@mbork.pl> Commit: Marcin Borkowski <mb...@mbork.pl>
Add functions to insert HTML-like tags --- subed/subed-common.el | 37 +++++++++++++++++++++++++++++++++++++ subed/subed-config.el | 5 +++++ subed/subed.el | 2 ++ 3 files changed, 44 insertions(+) diff --git a/subed/subed-common.el b/subed/subed-common.el index 0c80cf5..bc74217 100644 --- a/subed/subed-common.el +++ b/subed/subed-common.el @@ -1028,6 +1028,43 @@ Return nil if function `buffer-file-name' returns nil." (when (file-exists-p file-stem-video) (throw 'found-videofile file-stem-video)))))))) +;;; Inserting HTML-like tags + +(defvar subed--html-tag-history nil + "History of HTML-like tags in subtitles.") +(defvar subed--html-attr-history nil + "History of HTML-like attributes in subtitles.") + +(defun subed-insert-html-tag (begin end tag &optional attributes) + "Insert a pair of HTML-like tags around the region. +If region is not active, insert a pair of tags and put the point +between them. If called with a prefix argument, also ask for +attribute(s)." + (interactive (let* ((region-p (use-region-p)) + (begin (if region-p (region-beginning) (point))) + (end (if region-p (region-end) (point))) + (tag (read-string "Tag: " nil 'subed--html-tag-history)) + (attributes (when current-prefix-arg + (read-string "Attribute(s): " nil 'subed--html-attr-history)))) + (list begin end tag attributes))) + (save-excursion + (push (point) buffer-undo-list) + (goto-char end) + (insert "</" tag ">") + (goto-char begin) + (insert-before-markers "<" tag) + (when attributes (insert-before-markers " " attributes)) + (insert-before-markers ">"))) + +(defun subed-insert-default-html-tag (begin end) + "Insert a pair of default tags at point or around the region. +See `subed-insert-html-tag' and `subed-default-html-tag'." + (interactive (let* ((region-p (use-region-p)) + (begin (if region-p (region-beginning) (point))) + (end (if region-p (region-end) (point)))) + (list begin end))) + (subed-insert-html-tag begin end subed-default-html-tag)) + ;;; Characters per second computation (defun subed-show-cps-p () diff --git a/subed/subed-config.el b/subed/subed-config.el index f2f62d8..3416ee6 100644 --- a/subed/subed-config.el +++ b/subed/subed-config.el @@ -199,6 +199,11 @@ remembers whether it was originally enabled by the user.") :type 'file :group 'subed) +(defcustom subed-default-html-tag "i" + "Default HTML-like tag." + :type 'string + :group 'subed) + (defcustom subed-mpv-arguments '("--osd-level=2" "--osd-fractions") "Additional arguments for \"mpv\". The options --input-ipc-server=SRTEDIT-MPV-SOCKET and --idle are diff --git a/subed/subed.el b/subed/subed.el index f95d5e0..f68b54b 100644 --- a/subed/subed.el +++ b/subed/subed.el @@ -71,6 +71,8 @@ (define-key subed-mode-map (kbd "C-c ]") #'subed-copy-player-pos-to-stop-time) (define-key subed-mode-map (kbd "C-c .") #'subed-toggle-sync-point-to-player) (define-key subed-mode-map (kbd "C-c ,") #'subed-toggle-sync-player-to-point) + (define-key subed-mode-map (kbd "C-c C-t") #'subed-insert-html-tag) + (define-key subed-mode-map (kbd "C-c C-e") #'subed-insert-default-html-tag) subed-mode-map)) ;;;###autoload