From 7fe33b6ba0823d4794417ef205ee1f011c09db0b Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 20 May 2022 01:17:02 +0200 Subject: [PATCH] Add new command 'enriched-toggle-markup' * lisp/textmodes/enriched.el (enriched-toggle-markup): New command (bug#33855). --- etc/NEWS | 8 ++++++++ lisp/textmodes/enriched.el | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index c3bc1f0f58b..6185c6ff6ab 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -816,6 +816,13 @@ so automatically. * Changes in Specialized Modes and Packages in Emacs 29.1 +** Enriched Mode + +--- +*** New command 'enriched-toggle-markup'. +This allows you to see the markup in 'enriched-mode' buffers (e.g., +the HELLO file). + ** Shell Script Mode --- @@ -2190,6 +2197,7 @@ platforms. This command lets you examine all data in the current selection and the clipboard, and insert it into the buffer. ++++ ** New user option 'yank-transform-functions'. This function allows the user to alter the string to be inserted. diff --git a/lisp/textmodes/enriched.el b/lisp/textmodes/enriched.el index 50ff668a9ff..935be06812f 100644 --- a/lisp/textmodes/enriched.el +++ b/lisp/textmodes/enriched.el @@ -539,6 +539,30 @@ the range of text to assign text property SYMBOL with value VALUE." (list start end 'display prop) (list start end 'display (list 'disable-eval prop))))) +(defvar enriched--markup-shown) +(defun enriched-toggle-markup () + "Toggle whether to see markup in the current buffer." + (interactive) + (save-excursion + (save-restriction + (widen) + (with-silent-modifications + (if (bound-and-true-p enriched--markup-shown) + (progn + (setq-local enriched--markup-shown nil) + ;; Remove any faces, because they will be decoded, too. + (goto-char (point-min)) + (let (match) + (while (setq match (text-property-search-forward 'face)) + (put-text-property (prop-match-beginning match) + (prop-match-end match) + 'face nil))) + (enriched-decode (point-min) (point-max)) + (enriched-mode 1)) + (setq-local enriched--markup-shown t) + (enriched-encode (point-min) (point-max) (current-buffer)) + (enriched-mode -1)))))) + (provide 'enriched) ;;; enriched.el ends here -- 2.39.2