X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/41882805d6711e32ac0f066119226d84dbdedc13..4628bef1eea0f60e846fe6b6591725aa92952de9:/lisp/font-core.el diff --git a/lisp/font-core.el b/lisp/font-core.el index cfddbca5f5..5f8af5a521 100644 --- a/lisp/font-core.el +++ b/lisp/font-core.el @@ -1,17 +1,19 @@ ;;; font-core.el --- Core interface to font-lock ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -;; 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 +;; Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: languages, faces +;; Package: emacs ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs 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 2, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,9 +21,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Code: @@ -34,10 +34,15 @@ Defaults should be of the form: (KEYWORDS [KEYWORDS-ONLY [CASE-FOLD [SYNTAX-ALIST [SYNTAX-BEGIN ...]]]]) -KEYWORDS may be a symbol (a variable or function whose value is the keywords to -use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil, -syntactic fontification (strings and comments) is not performed. +KEYWORDS may be a symbol (a variable or function whose value is the keywords +to use for fontification) or a list of symbols (specifying different levels +of fontification). + +If KEYWORDS-ONLY is non-nil, syntactic fontification (strings and +comments) is not performed. + If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying. + If SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form \(CHAR-OR-STRING . STRING) used to set the local Font Lock syntax table, for keyword and syntactic fontification (see `modify-syntax-entry'). @@ -50,6 +55,8 @@ be outside a syntactic block), or `beginning-of-defun' for programming modes or known to move outside a syntactic block). If nil, the beginning of the buffer is used as a position outside of a syntactic block, in the worst case. +\(See also Info node `(elisp)Font Lock Basics'.) + These item elements are used by Font Lock mode to set the variables `font-lock-keywords', `font-lock-keywords-only', `font-lock-keywords-case-fold-search', `font-lock-syntax-table' and @@ -70,26 +77,17 @@ Other variables include that for syntactic keyword fontification, functions, `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function', `font-lock-fontify-region-function', `font-lock-unfontify-region-function', and `font-lock-inhibit-thing-lock'.") +;;;###autoload +(put 'font-lock-defaults 'risky-local-variable t) (make-variable-buffer-local 'font-lock-defaults) -(defvar font-lock-defaults-alist nil - "Alist of fall-back Font Lock defaults for major modes. - -Each item should be a list of the form: - - (MAJOR-MODE . FONT-LOCK-DEFAULTS) - -where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default -settings. See the variable `font-lock-defaults', which takes precedence.") -(make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults) - (defvar font-lock-function 'font-lock-default-function "A function which is called when `font-lock-mode' is toggled. It will be passed one argument, which is the current value of `font-lock-mode'.") ;; The mode for which font-lock was initialized, or nil if none. -(defvar font-lock-mode-major-mode) +(defvar font-lock-major-mode) (define-minor-mode font-lock-mode "Toggle Font Lock mode. With arg, turn Font Lock mode off if and only if arg is a non-positive @@ -124,10 +122,6 @@ generally prefer. When you turn Font Lock mode on/off the buffer is fontified/defontified, though fontification occurs only if the buffer is less than `font-lock-maximum-size'. -For example, to use maximum levels of fontification, put in your ~/.emacs: - - (setq font-lock-maximum-decoration t) - To add your own highlighting for some major mode, and modify the highlighting selected automatically via the variable `font-lock-maximum-decoration', you can use `font-lock-add-keywords'. @@ -139,8 +133,7 @@ To fontify a block (the function or paragraph containing point, or a number of lines around point), perhaps because modification on the current line caused syntactic change on other lines, you can use \\[font-lock-fontify-block]. -See the variable `font-lock-defaults-alist' for the Font Lock mode default -settings. You can set your own default settings for some mode, by setting a +You can set your own default settings for some mode, by setting a buffer local value for `font-lock-defaults', via its mode hook. The above is the default behavior of `font-lock-mode'; you may specify @@ -149,15 +142,13 @@ your own function which is called when `font-lock-mode' is toggled via nil nil nil ;; Don't turn on Font Lock mode if we don't have a display (we're running a ;; batch job) or if the buffer is invisible (the name starts with a space). - (when (or noninteractive (eq (aref (buffer-name) 0) ?\ )) + (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) (setq font-lock-mode nil)) (funcall font-lock-function font-lock-mode) ;; Arrange to unfontify this buffer if we change major mode later. (if font-lock-mode (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t) - (remove-hook 'change-major-mode-hook 'font-lock-change-mode t)) - (when font-lock-mode - (setq font-lock-mode-major-mode major-mode))) + (remove-hook 'change-major-mode-hook 'font-lock-change-mode t))) ;; Get rid of fontification for the old major mode. ;; We do this when changing major modes. @@ -204,13 +195,11 @@ this function onto `change-major-mode-hook'." ;; `font-lock-defaults'. (when (or font-lock-defaults (if (boundp 'font-lock-keywords) font-lock-keywords) - (with-no-warnings - (cdr (assq major-mode font-lock-defaults-alist))) (and mode (boundp 'font-lock-set-defaults) font-lock-set-defaults - font-lock-mode-major-mode - (not (eq font-lock-mode-major-mode major-mode)))) + font-lock-major-mode + (not (eq font-lock-major-mode major-mode)))) (font-lock-mode-internal mode))) (defun turn-on-font-lock () @@ -238,7 +227,7 @@ this function onto `change-major-mode-hook'." ;; hook is run, the major mode is in the process of being changed and we do not ;; know what the final major mode will be. So, `font-lock-change-major-mode' ;; only (a) notes the name of the current buffer, and (b) adds our function -;; `turn-on-font-lock-if-enabled' to the hook variables +;; `turn-on-font-lock-if-desired' to the hook variables ;; `after-change-major-mode-hook' and `post-command-hook' (for modes ;; that do not yet run `after-change-major-mode-hook'). By the time ;; the functions on the first of these hooks to be run are run, the new major @@ -258,7 +247,7 @@ this function onto `change-major-mode-hook'." ;; Although Global Font Lock mode is a pseudo-mode, I think that the user ;; interface should conform to the usual Emacs convention for modes, i.e., a ;; command to toggle the feature (`global-font-lock-mode') with a variable for -;; finer control of the mode's behaviour (`font-lock-global-modes'). +;; finer control of the mode's behavior (`font-lock-global-modes'). ;; ;; The feature should not be enabled by loading font-lock.el, since other ;; mechanisms for turning on Font Lock mode, such as M-x font-lock-mode RET or @@ -268,7 +257,7 @@ this function onto `change-major-mode-hook'." ;; would also be contrary to the Principle of Least Surprise. sm. (defcustom font-lock-global-modes t - "*Modes for which Font Lock mode is automagically turned on. + "Modes for which Font Lock mode is automagically turned on. Global Font Lock mode is controlled by the command `global-font-lock-mode'. If nil, means no modes have Font Lock mode automatically turned on. If t, all modes that support Font Lock mode have it automatically turned on. @@ -285,16 +274,20 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only." (repeat :inline t (symbol :tag "mode")))) :group 'font-lock) -(defun turn-on-font-lock-if-enabled () - (unless (and (eq (car-safe font-lock-global-modes) 'not) - (memq major-mode (cdr font-lock-global-modes))) +(defun turn-on-font-lock-if-desired () + (when (cond ((eq font-lock-global-modes t) + t) + ((eq (car-safe font-lock-global-modes) 'not) + (not (memq major-mode (cdr font-lock-global-modes)))) + (t (memq major-mode font-lock-global-modes))) (let (inhibit-quit) (turn-on-font-lock)))) -(define-global-minor-mode global-font-lock-mode - font-lock-mode turn-on-font-lock-if-enabled - :extra-args (dummy) - :initialize 'custom-initialize-safe-default +(define-globalized-minor-mode global-font-lock-mode + font-lock-mode turn-on-font-lock-if-desired + ;; What was this :extra-args thingy for? --Stef + ;; :extra-args (dummy) + :initialize 'custom-initialize-delay :init-value (not (or noninteractive emacs-basic-display)) :group 'font-lock :version "22.1") @@ -303,5 +296,4 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only." (provide 'font-core) -;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71 ;;; font-core.el ends here