From: Michal Nazarewicz <mpn@google.com>
To: emacs-devel@gnu.org
Subject: [PATCH] font-core: add font-lock-{enable, disable}-global-for functions
Date: Sat, 3 Jan 2015 16:51:40 +0100 [thread overview]
Message-ID: <1420300300-29754-1-git-send-email-mpn@google.com> (raw)
From: Michal Nazarewicz <mina86@mina86.com>
* lisp/font-core.el (font-lock-enable-global-for)
(font-lock-disable-global-for): New functions for easy manipulation
of `font-lock-global-modes' variable.
* test/automated/font-core.el (font-lock-test-disable-global-for)
(font-lock-test-enable-global-for): New tests for aforementioned
functions.
* lisp/speedbar.el: Use `font-lock-disable-global-for' instead of
implementing the same functionality.
---
lisp/font-core.el | 41 ++++++++++++++++++++++++++++++
lisp/speedbar.el | 10 ++------
test/automated/font-core.el | 62 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+), 8 deletions(-)
create mode 100644 test/automated/font-core.el
diff --git a/lisp/font-core.el b/lisp/font-core.el
index 5dd6ad3..667d650 100644
--- a/lisp/font-core.el
+++ b/lisp/font-core.el
@@ -276,6 +276,47 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only."
(let (inhibit-quit)
(turn-on-font-lock))))
+;;;###autoload
+(defun font-lock-disable-global-for (mode)
+ "Disable `global-font-lock-mode' for MODE major mode.
+Modify `font-lock-global-modes' variable so that
+`global-font-lock-mode' is disabled for MODE.
+
+If `font-lock-global-modes' is a '(not …) list, make sure MODE is
+on the list; if it's a list, make sure MODE is not on it; if it's
+nil, do nothing; otherwise changes the variable to '(not MODE)."
+ (let ((modes font-lock-global-modes))
+ (cond
+ ;; t, change to '(not MODE) to disable for MODE
+ ((not (listp modes))
+ (setq font-lock-global-modes (list 'not mode)))
+ ;; (not …), add MODE to the list to disable in MODE
+ ((eq (car modes) 'not)
+ (unless (memq mode (cdr modes))
+ (setcdr modes (cons mode (cdr modes)))))
+ ;; list of modes (may be nil), make sure MODE is not on it
+ ((setq font-lock-global-modes (delq mode modes))))))
+
+;;;###autoload
+(defun font-lock-enable-global-for (mode)
+ "Enable `global-font-lock-mode' for MODE major mode.
+Modify `font-lock-global-modes' variable so that
+`global-font-lock-mode' is enabled for MODE.
+
+If `font-lock-global-modes' is a '(not …) list, make sure MODE is
+not on the list; if it's a list, make sure MODE is on it; if it's
+nil, change the variable to '(MODE) list; otherwise do nothing."
+ (let ((modes font-lock-global-modes))
+ (cond
+ ;; t, nothing to do, already enabled for all modes
+ ((not (listp modes)))
+ ;; (not …), make sure MODE is not on the list
+ ((eq (car modes) 'not)
+ (unless (setcdr modes (delq mode (cdr modes)))
+ (setq font-lock-global-modes t)))
+ ;; list of modes (may be nil), make sure MODE is on it
+ ((add-to-list 'font-lock-global-modes mode)))))
+
(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
diff --git a/lisp/speedbar.el b/lisp/speedbar.el
index 2989274..3c980f7 100644
--- a/lisp/speedbar.el
+++ b/lisp/speedbar.el
@@ -4068,14 +4068,8 @@ TEXT is the buffer's name, TOKEN and INDENT are unused."
(def-edebug-spec speedbar-with-writable def-body)))
;; Fix a font lock problem for some versions of Emacs
-(and (boundp 'font-lock-global-modes)
- font-lock-global-modes
- (if (eq font-lock-global-modes t)
- (setq font-lock-global-modes '(not speedbar-mode))
- (if (eq (car font-lock-global-modes) 'not)
- (add-to-list 'font-lock-global-modes 'speedbar-mode t)
- (setq font-lock-global-modes (delq 'speedbar-mode
- font-lock-global-modes)))))
+(when (fboundp 'font-lock-disable-global-for)
+ (font-lock-disable-global-for 'speedbar-mode))
\f
;;; Obsolete variables and functions
diff --git a/test/automated/font-core.el b/test/automated/font-core.el
new file mode 100644
index 0000000..647488b
--- /dev/null
+++ b/test/automated/font-core.el
@@ -0,0 +1,62 @@
+;;; font-core.el --- ERT tests for font-core.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2015 Free Software Foundation, Inc.
+
+;; Author: Michal Nazarewicz <mina86@mina86.com>
+;; Keywords: languages, faces
+;; Package: emacs
+
+;; This file is part of GNU Emacs.
+
+;; 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 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
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package defines regression tests for the font-core package.
+
+;;; Code:
+
+(require 'ert)
+(require 'font-core)
+
+(defun font-lock-test-global-modes (func expected-pairs)
+ (dolist (pair expected-pairs)
+ (let ((font-lock-global-modes (car pair)))
+ (funcall func 'foo-mode)
+ (should (equal (cdr pair) font-lock-global-modes)))))
+
+(ert-deftest font-lock-test-disable-global-for ()
+ "Test `font-lock-disable-global-for' function"
+ (font-lock-test-global-modes 'font-lock-disable-global-for
+ '((nil . nil)
+ (t . (not foo-mode))
+ ((not bar-mode) . (not foo-mode bar-mode))
+ ((not foo-mode) . (not foo-mode))
+ ((foo-mode) . nil)
+ ((foo-mode bar-mode) . (bar-mode)))))
+
+(ert-deftest font-lock-test-enable-global-for ()
+ "Test `font-lock-enable-global-for' function"
+ (font-lock-test-global-modes 'font-lock-enable-global-for
+ '((nil . (foo-mode))
+ (t . t)
+ ((not bar-mode) . (not bar-mode))
+ ((not foo-mode bar-mode) . (not bar-mode))
+ ((not foo-mode) . t)
+ ((foo-mode) . (foo-mode))
+ ((bar-mode) . (foo-mode bar-mode)))))
+
+(provide 'font-core-tests)
+
+;;; font-core.el ends here
--
2.2.0.rc0.207.ga3a616c
next reply other threads:[~2015-01-03 15:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-03 15:51 Michal Nazarewicz [this message]
2015-01-04 2:27 ` [PATCH] font-core: add font-lock-{enable, disable}-global-for functions Stefan Monnier
2015-01-04 3:21 ` Michal Nazarewicz
2015-01-04 4:30 ` Stefan Monnier
2015-01-04 6:07 ` Michal Nazarewicz
2015-01-04 13:39 ` Stefan Monnier
2015-01-04 14:18 ` Dmitry Gutov
2015-01-04 14:43 ` Michal Nazarewicz
2015-01-04 14:56 ` Dmitry Gutov
2015-01-04 19:42 ` Stefan Monnier
2015-01-04 22:07 ` Dmitry Gutov
2015-01-04 23:44 ` Stefan Monnier
2015-01-05 0:02 ` Dmitry Gutov
2015-01-05 0:08 ` Dmitry Gutov
2015-01-05 1:49 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420300300-29754-1-git-send-email-mpn@google.com \
--to=mpn@google.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.