From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel Subject: [PATCH] font-core: add font-lock-{enable, disable}-global-for functions Date: Sat, 3 Jan 2015 16:51:40 +0100 Message-ID: <1420300300-29754-1-git-send-email-mpn@google.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1420300322 17004 80.91.229.3 (3 Jan 2015 15:52:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 3 Jan 2015 15:52:02 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 03 16:51:57 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y7Qzc-0004PW-6D for ged-emacs-devel@m.gmane.org; Sat, 03 Jan 2015 16:51:56 +0100 Original-Received: from localhost ([::1]:54650 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y7Qzb-0004F7-Ov for ged-emacs-devel@m.gmane.org; Sat, 03 Jan 2015 10:51:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y7QzX-0004Eq-6O for emacs-devel@gnu.org; Sat, 03 Jan 2015 10:51:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y7QzS-000706-CT for emacs-devel@gnu.org; Sat, 03 Jan 2015 10:51:51 -0500 Original-Received: from mail-we0-x22d.google.com ([2a00:1450:400c:c03::22d]:44570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y7QzS-0006zv-0k for emacs-devel@gnu.org; Sat, 03 Jan 2015 10:51:46 -0500 Original-Received: by mail-we0-f173.google.com with SMTP id q58so5723609wes.32 for ; Sat, 03 Jan 2015 07:51:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=Z+vqgo118Tm3sHsUymrdNRBt/zsby88+MDHeSUUHcVs=; b=bzy6VR63R4vBNwDvcURr7gtX+PG+pgbTppdsuPDIwd1H6BEXpXhDC48Qb1uGIrbV9E e4b+i0wyFCwF8u8q04b2HVJUwZGKbMEx6dmjB6qw9HOhZnItyC42WrqD3/UzXbpVqYbZ 6g6vZCk0yvUOmOgPBIG4zA45cu6GDWYc80QrYnk62AN8IiYI3aaFd45lmZTyazCt/xBq G8mjXMy6BSKtDA8OMa8EKIMFOiWyOSGaOK7GboqboNESwUG0ovN8jK4AcufAXuH7y7TS 90J4jRgxWAIgurmuXh+Fw9i7RzH0Umpgi0HKx2Nr5iafomlvRpCynZRXeC/2P09RDF1Q u5bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=Z+vqgo118Tm3sHsUymrdNRBt/zsby88+MDHeSUUHcVs=; b=YcLUHN0SV7JzX6F6r5xIXL2GFS0wL01Vk5MBF7zHyXUgZL2Hut17AUMMqBXIPgO4b7 Q0ElMPxzZeVeZjToCVwsJaznNgEC+SDXbDINObkITzQdru7OdjGVbk7CzMMILkIYNIab LGW5U58r0lSHNcEv1cDDYjboQQ4pGuHfwNJRbRGEPcSTnj4RscYvBbqFHe9K49x/8FoS tVaWz88RBRysHYPVP9tfhUuHvM3MzMHz8L/GAGqlDn6qb/sWmSgvttq2T1PnZvgCV5Z8 SOrHLC0AoFDcsmGCReS3m2Dx9kH6d0lzLYU8NZG3hVLk7Mln2pcHokufA2edamYpyWt/ fmmw== X-Gm-Message-State: ALoCoQlz0ue6qkksvnYnnxvGX0qaQkRJMqsgGOXIJONeAq79RQMYnWxxr0iNjXnchI7WzBjE1Oae X-Received: by 10.180.74.146 with SMTP id t18mr7896431wiv.62.1420300304615; Sat, 03 Jan 2015 07:51:44 -0800 (PST) Original-Received: from mpn-glaptop.home (159-205-184-198.adsl.inetia.pl. [159.205.184.198]) by mx.google.com with ESMTPSA id fo12sm2917430wic.19.2015.01.03.07.51.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 03 Jan 2015 07:51:43 -0800 (PST) X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:180944 Archived-At: From: Michal Nazarewicz * 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)) ;;; 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 +;; 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 . + +;;; 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