emacs - Open selection in different major mode. -
is possible select parts of text , open in different buffer different mode?
fore example, if work in ess mode (syntax highlighting r),
astring <- '<form> <input type="checkbox" id="foo", value="bar"> </form>'
if text within single quotes selected, edit in new buffer html mode (similar org-src-lang-modes
in orgmode).
here 1 method of handling issue using narrow-to-region
-- example contemplates point (cursor) somewhere between single quotes when typing m-x narrow-to-single-quotes
. simple two-line function can used exit -- (widen) (ess-mode)
; or, can fancy recursive-edit
. of course, not same opening text in new buffer. similar functionality can used copy region new buffer, assuming original poster may want incorporate edited text primary buffer.
(defun narrow-to-single-quotes () "when cursor (aka point) between single quotes, function narrow region whatever between single quotes, , change major mode `html-mode`. exit, type `m-x widen` , `m-x [whatever-previous-major-mode-was-used]`." (interactive) (let* ( (init-pos (point)) beg end) (re-search-backward "'" nil t) (forward-char 1) (setq beg (point)) (re-search-forward "'" nil t) (backward-char 1) (setq end (point)) (narrow-to-region beg end) (html-mode) (goto-char init-pos)))
Comments
Post a Comment