[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2c9532b 326/433: Simplify mmm-update-mode-info
From: |
Dmitry Gutov |
Subject: |
[elpa] master 2c9532b 326/433: Simplify mmm-update-mode-info |
Date: |
Thu, 15 Mar 2018 19:44:28 -0400 (EDT) |
branch: master
commit 2c9532bd717c302840b6ad9c60021cdf621864a2
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Simplify mmm-update-mode-info
* Use non-hidden name for the temporary buffer, for better font-lock
initialization (and for minor modes that depend on it, like
whitespace-mode).
* Kill the temp buffer in an unwind form, error or not.
* Don't check if it's XEmacs version 20, 21 came out 14 years ago.
* Get rid of `mmm-font-lock-available-p' and `mmm-set-font-lock-defaults'.
The
former was only used with Emacs < 21, the latter is just unused now.
---
mmm-compat.el | 29 ++--------------
mmm-region.el | 109 ++++++++++++++++++++--------------------------------------
mmm-utils.el | 4 +--
mmm-vars.el | 9 +++--
4 files changed, 48 insertions(+), 103 deletions(-)
diff --git a/mmm-compat.el b/mmm-compat.el
index ce9e736..01842fd 100644
--- a/mmm-compat.el
+++ b/mmm-compat.el
@@ -156,38 +156,15 @@ This makes `@' in skeletons act approximately like it
does in FSF."
;;{{{ Make Temp Buffers (XEmacs)
(defmacro mmm-make-temp-buffer (buffer name)
- "Return a buffer called NAME including the text of BUFFER.
+ "Return a buffer with name based on NAME including the text of BUFFER.
This text should not be modified."
(if (fboundp 'make-indirect-buffer)
- `(make-indirect-buffer ,buffer ,name)
+ `(make-indirect-buffer ,buffer (generate-new-buffer-name ,name))
`(save-excursion
- (set-buffer (get-buffer-create ,name))
+ (set-buffer (generate-new-buffer ,name))
(insert-buffer ,buffer)
(current-buffer))))
-;;}}}
-;;{{{ Font Lock Available (Emacs w/o X)
-
-(defvar mmm-font-lock-available-p (or window-system mmm-xemacs)
- "Whether font-locking is available.
-Emacs 19 and 20 only provide font-lock with a window system in use.")
-
-;;}}}
-;;{{{ Font Lock Defaults (XEmacs)
-
-(defmacro mmm-set-font-lock-defaults ()
- "Set font-lock defaults without trying to turn font-lock on.
-In XEmacs, `font-lock-set-defaults' calls `font-lock-set-defaults-1'
-to do the real work but then `turn-on-font-lock', which in turn calls
-`font-lock-mode', which unsets the defaults if running in a hidden
-buffer \(name begins with a space). So in XEmacs, we just call
-`font-lock-set-defaults-1' directly."
- (if mmm-xemacs
- `(font-lock-set-defaults-1)
- `(font-lock-set-defaults)))
-
-;;}}}
-
(provide 'mmm-compat)
;;; mmm-compat.el ends here
diff --git a/mmm-region.el b/mmm-region.el
index 6608490..4c04515 100644
--- a/mmm-region.el
+++ b/mmm-region.el
@@ -495,69 +495,36 @@ which is set here as well. See
`mmm-save-local-variables'. If FORCE
is non-nil, don't quit if the info is already there."
(let ((buffer-entry (assq mode mmm-buffer-saved-locals))
(region-entry (assq mode mmm-region-saved-locals-defaults))
- global-vars buffer-vars region-vars
- ;; kludge for XEmacs 20
- (html-helper-build-new-buffer nil))
+ global-vars buffer-vars region-vars)
(unless (and (not force)
(get mode 'mmm-local-variables)
buffer-entry
region-entry)
- (save-excursion
- (let ((filename (buffer-file-name)))
- ;; On errors, the temporary buffers don't get deleted, so here
- ;; we get rid of any old ones that may be hanging around.
- (when (buffer-live-p (get-buffer mmm-temp-buffer-name))
- (with-current-buffer (get-buffer mmm-temp-buffer-name)
- (set-buffer-modified-p nil)
- (kill-buffer (current-buffer))))
- ;; Now make a new temporary buffer.
- (set-buffer (mmm-make-temp-buffer (current-buffer)
- mmm-temp-buffer-name))
- ;; Handle stupid modes that need the file name set
- (if (memq mode mmm-set-file-name-for-modes)
- (setq buffer-file-name filename)))
- (funcall mode)
- (when (featurep 'font-lock)
- ;; XEmacs doesn't have global-font-lock-mode (or rather, it
- ;; has nothing but global-font-lock-mode).
- (when (or mmm-xemacs
- ;; Code copied from font-lock.el to detect when font-lock
- ;; should be on via global-font-lock-mode.
- (and (or font-lock-defaults
- (and (boundp 'font-lock-defaults-alist)
- (assq major-mode font-lock-defaults-alist))
- (assq major-mode font-lock-keywords-alist))
- (or (eq font-lock-global-modes t)
- (if (eq (car-safe font-lock-global-modes) 'not)
- (not (memq major-mode
- (cdr font-lock-global-modes)))
- (memq major-mode font-lock-global-modes)))))
- ;; Don't actually fontify in the temp buffer, but note
- ;; that we should fontify when we use this mode.
- (put mode 'mmm-font-lock-mode t))
- ;; Get the font-lock variables
- (when mmm-font-lock-available-p
- ;; To fool `font-lock-add-keywords'
- (let ((font-lock-mode t))
- (mmm-set-font-lock-defaults)))
- ;; These can't be in the local variables list, because we
- ;; replace their actual values, but we want to use their
- ;; original values elsewhere.
- (unless (and mmm-xemacs (= emacs-major-version 20))
- ;; XEmacs 20 doesn't have this variable. This effectively
- ;; prevents the MMM font-lock support from working, but we
- ;; just ignore it and go on, to prevent an error message.
- (put mode 'mmm-fontify-region-function
- font-lock-fontify-region-function))
- (put mode 'mmm-beginning-of-syntax-function
- font-lock-beginning-of-syntax-function))
- ;; Get variables
- (setq global-vars (mmm-get-locals 'global)
- buffer-vars (mmm-get-locals 'buffer)
- region-vars (mmm-get-locals 'region))
- (put mode 'mmm-mode-name mode-name)
- (set-buffer-modified-p nil)
- (kill-buffer (current-buffer)))
+ (let ((temp-buffer (mmm-make-temp-buffer (current-buffer)
+ mmm-temp-buffer-name))
+ (mmm-in-temp-buffer t))
+ (unwind-protect
+ (with-current-buffer temp-buffer
+ ;; Handle stupid modes that need the file name set.
+ (when (memq mode mmm-set-file-name-for-modes)
+ (setq buffer-file-name filename))
+ (funcall mode)
+ (when (featurep 'font-lock)
+ (put mode 'mmm-font-lock-mode font-lock-mode)
+ ;; These can't be in the local variables list, because we
+ ;; replace their actual values, but we want to use their
+ ;; original values elsewhere.
+ (put mode 'mmm-fontify-region-function
+ font-lock-fontify-region-function)
+ (put mode 'mmm-beginning-of-syntax-function
+ font-lock-beginning-of-syntax-function))
+ ;; Get variables
+ (setq global-vars (mmm-get-locals 'global)
+ buffer-vars (mmm-get-locals 'buffer)
+ region-vars (mmm-get-locals 'region))
+ (put mode 'mmm-mode-name mode-name))
+ (set-buffer-modified-p nil)
+ (kill-buffer temp-buffer)))
(put mode 'mmm-local-variables global-vars)
(if buffer-entry
(setcdr buffer-entry buffer-vars)
@@ -692,23 +659,21 @@ region and mode for the previous position."
(defun mmm-enable-font-lock (mode)
"Turn on font lock if it is not already on and MODE enables it."
(mmm-update-mode-info mode)
- (and mmm-font-lock-available-p
- (not font-lock-mode)
+ (and (not font-lock-mode)
(get mode 'mmm-font-lock-mode)
(font-lock-mode 1)))
(defun mmm-update-font-lock-buffer ()
- "Turn on font lock iff any mode in the buffer enables it."
- (when mmm-font-lock-available-p
- (if (some #'(lambda (mode)
- (get mode 'mmm-font-lock-mode))
- (cons mmm-primary-mode
- (mapcar #'(lambda (ovl)
- (overlay-get ovl 'mmm-mode))
- (mmm-overlays-overlapping
- (point-min) (point-max)))))
- (font-lock-mode 1)
- (font-lock-mode 0))))
+ "Turn on font lock if any mode in the buffer enables it."
+ (if (some #'(lambda (mode)
+ (get mode 'mmm-font-lock-mode))
+ (cons mmm-primary-mode
+ (mapcar #'(lambda (ovl)
+ (overlay-get ovl 'mmm-mode))
+ (mmm-overlays-overlapping
+ (point-min) (point-max)))))
+ (font-lock-mode 1)
+ (font-lock-mode 0)))
(defun mmm-refontify-maybe (&optional start stop)
"Re-fontify from START to STOP, or entire buffer, if enabled."
diff --git a/mmm-utils.el b/mmm-utils.el
index 98abdb8..dffbd73 100644
--- a/mmm-utils.el
+++ b/mmm-utils.el
@@ -46,9 +46,7 @@ means not hidden, not a minibuffer, not in batch mode, and
not in of
(window-minibuffer-p (selected-window))
(memq major-mode mmm-never-modes)
noninteractive
- ;; Unnecessary as now hidden
-;;; (equal (buffer-name) mmm-temp-buffer-name)
- )
+ mmm-in-temp-buffer)
,@body))
;;;(def-edebug-spec mmm-valid-buffer t)
diff --git a/mmm-vars.el b/mmm-vars.el
index 35076d6..aa1dafd 100644
--- a/mmm-vars.el
+++ b/mmm-vars.el
@@ -1026,8 +1026,13 @@ The CLASSES are all made private, i.e. non-user-visible."
;;}}}
;;{{{ Temp Buffer Name
-(defvar mmm-temp-buffer-name " *mmm-temp*"
- "Name for temporary buffers created by MMM Mode.")
+(defvar mmm-temp-buffer-name "mmm-temp-buffer"
+ "Name for temporary buffers created by MMM Mode.
+Using non-special name, so that font-lock-mode will be enabled
+automatically when appropriate, and will set all related vars.")
+
+(defvar mmm-in-temp-buffer nil
+ "Bound to t when working in the temp buffer.")
;;}}}
;;{{{ Interactive History
- [elpa] master 16d937d 019/433: Added files required by automake., (continued)
- [elpa] master 16d937d 019/433: Added files required by automake., Dmitry Gutov, 2018/03/15
- [elpa] master 8e205dd 400/433: Don't use version.texi at all, Dmitry Gutov, 2018/03/15
- [elpa] master 2ca7e6a 300/433: Add header comment, provide description, Dmitry Gutov, 2018/03/15
- [elpa] master 956354f 375/433: Fix missing var declaration, Dmitry Gutov, 2018/03/15
- [elpa] master fff25f6 311/433: Note that 'autogen.sh' should be run to generate 'configure' and 'Makefile.in' (see #11), Dmitry Gutov, 2018/03/15
- [elpa] master 3fb2964 416/433: Update Michael's email address to an active one, Dmitry Gutov, 2018/03/15
- [elpa] master 6c5d442 425/433: Fix copyright entry, Dmitry Gutov, 2018/03/15
- [elpa] master e848ef1 323/433: * mmm-fontify-region: Save and restore submode, overlay and local vars, Dmitry Gutov, 2018/03/15
- [elpa] master 004a618 370/433: Fix #23, Dmitry Gutov, 2018/03/15
- [elpa] master 53524db 389/433: Remove version.texi from the repo, Dmitry Gutov, 2018/03/15
- [elpa] master 2c9532b 326/433: Simplify mmm-update-mode-info,
Dmitry Gutov <=
- [elpa] master e767fa2 265/433: Added script and documentation for installing from CVS, Dmitry Gutov, 2018/03/15
- [elpa] master 7965887 279/433: Fix error in mmm-mode when Emacs 23 immediately evaporates zero-width submode regions, Dmitry Gutov, 2018/03/15
- [elpa] master 7da80fb 422/433: Add cl-lib package dependency, Dmitry Gutov, 2018/03/15
- [elpa] master cd66bdd 316/433: Improve mmm-erb usage instructions, Dmitry Gutov, 2018/03/15
- [elpa] master 2e06d3d 356/433: Remove the useless CVS $Id tags, Dmitry Gutov, 2018/03/15
- [elpa] master 68fe94d 274/433: (mmm-ify): Change defaults for front-delim and, Dmitry Gutov, 2018/03/15
- [elpa] master 28d51d2 312/433: Note availability of Melpa packages, Dmitry Gutov, 2018/03/15
- [elpa] master 406e120 330/433: Merge pull request #19 from dgutov/font-lock, Dmitry Gutov, 2018/03/15
- [elpa] master 509660a 354/433: Merge pull request #22 from purcell/indentation, Dmitry Gutov, 2018/03/15
- [elpa] master e583767 284/433: Provide more sensible face defaults for dark and light backgrounds, Dmitry Gutov, 2018/03/15