From 191ab3b73cd136ee07cee7a6dd51394370b3c6a4 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Thu, 13 Jul 2017 11:21:20 +0200 Subject: [PATCH] added stripes mode * provides alternating background color. Signed-off-by: Andreas Gerler --- bba.org | 10 ++++ lisp/stripes.el | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 lisp/stripes.el diff --git a/bba.org b/bba.org index 4afac6ff..87429a75 100644 --- a/bba.org +++ b/bba.org @@ -2261,6 +2261,15 @@ Combine abbrev with Ispell: #+END_SRC +* [[https://www.emacswiki.org/emacs/stripes.el][stripes]] +[2017-07-11 Tue 15:17] + +#+BEGIN_SRC emacs-lisp :tangle yes + (load-file (expand-file-name "~/.emacs.d/lisp/stripes.el")) + (custom-set-faces + '(stripes-face ((t :background "gray0")))) + +#+END_SRC * syntax-highlighting #+BEGIN_SRC emacs-lisp :tangle yes (font-lock-mode) @@ -3226,6 +3235,7 @@ character before any spaces." (define-key bba/toggle "p" 'smartparens-mode) (define-key bba/toggle "r" 'rainbow-delimiters-mode) (define-key bba/toggle "s" 'flyspell-mode) + (define-key bba/toggle (kbd "s-s") 'stripes-mode) (define-key bba/toggle "\S-s" 'smerge-mode) (define-key bba/toggle "t" 'toggle-truncate-lines) (define-key bba/toggle "v" 'visual-line-mode) diff --git a/lisp/stripes.el b/lisp/stripes.el new file mode 100644 index 00000000..759cd714 --- /dev/null +++ b/lisp/stripes.el @@ -0,0 +1,155 @@ +;;; stripes.el --- alternate the background color of lines + +;; Copyright (C) 2003 Michael Schierl + +;; Author: Michael Schierl +;; Created: 02 October 2003 +;; Keywords: list alternation color +;; Version: 0.2 + +(defconst stripes-version "0.2" + "Version of color alternation mode.") + +;; This file is not part of GNU Emacs. + +;; This program 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. + +;; This program 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; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; highlights every even line with an alternative background +;; color. Useful for buffers that display lists of any kind - as a +;; guide for your eyes to follow these lines. + +;; when invoked with a numeric prefix arg, color that many lines +;; instead of every other line. + +;; Put this file into your load path, +;; (require 'stripes) and do a (turn-on-stripes-mode) +;; whenever you need this (e.g. in hooks). + +;; Changelog + +; --- Version 0.2 (2003-11-01) + +;; - added autoload cookies +;; - added turn-on method (for hooks) +;; - prefix arg specifies how many lines to treat as one line +;; - renamed the file from stripes-mode.el to stripes.el to +;; make the name fit into the Emacs file naming conventions +;; - widen all restrictions when refreshing + +; --- Version 0.1 (2003-10-02) + +;;; Code: +(defvar stripes-mode nil) +(make-variable-buffer-local 'stripes-mode) + +(defvar stripes-lcount 1) +(make-variable-buffer-local 'stripes-lcount) + +(or (assq 'stripes-mode minor-mode-alist) + (setq minor-mode-alist + (cons '(stripes-mode " ==") + minor-mode-alist))) + +(defface stripes-face + `((t (:background "#f4f4f4"))) + "Face for alternate lines." + :group 'stripes) + +;;;###autoload +(defun stripes-mode (arg) + "Toggle Color alternation mode. +With prefix ARG, enable Color alternation mode iff arg is nonzero. In +that case the numeric arg (unless it is made by (multiple) +`\\[universal-argument]'s) specifies the number of subsequent lines +that should +be in one color (without alternation)." + (interactive "P") + (setq stripes-mode + (if (null arg) + (not stripes-mode) + (> (prefix-numeric-value arg) 0))) + (setq stripes-lcount + (if (numberp arg) + arg + 1)) + (force-mode-line-update) + (if stripes-mode + (stripes-create) + (stripes-remove)) + (if (interactive-p) + (if stripes-mode + (if (= stripes-lcount 1) + (message "Color alternation mode enabled") + (message "Color alternation mode (%i lines) enabled" + stripes-lcount)) + (message "Color alternation mode disabled")))) + +;;;###autoload +(defun turn-on-stripes-mode () + "Turn on color alternation mode. +Useful for adding to a major mode hook variable. +Example: + (add-hook 'gnus-summary-mode-hook 'turn-on-stripes-mode) +to automatically turn on color alternation when viewing the Gnus +article buffer." + (interactive) + (stripes-mode 1)) + +(defun stripes-remove () + "Remove all alternation colors." + (let ((oli (overlays-in (point-min) (point-max))) ol) + (while oli + (setq ol (car oli) + oli (cdr oli)) + (when (eq (overlay-get ol 'face) 'stripes-face) + (delete-overlay ol))))) + +(defun stripes-create () + "Colors lines in current buffer alternatively. +This will not monitor changes of the buffer." + (save-excursion + (save-restriction + (widen) + (stripes-remove) + (goto-char (point-min)) + (while (not (eobp)) + (forward-line stripes-lcount) + (let ((ppp (point)) + ovl) + (unless (eobp) + (forward-line stripes-lcount) + (setq ovl (make-overlay ppp (point))) + (overlay-put ovl 'face 'stripes-face))))))) + +(defun stripes-after-change-function (beg end length) + "After change function for color alternation mode. +Refreshes all the highlighting. This is slow, but as mostly lists are +not changed that often, it should be acceptable. Arguments BEG END +and LENGTH are not used." + (if stripes-mode + (stripes-create))) + +(add-hook 'after-change-functions + 'stripes-after-change-function) + +;; legacy provide (if you have installed an old version as well) +(provide 'stripes-mode) + +(provide 'stripes) + +;;; stripes.el ends here -- 2.47.3