Skip to content

Commit e3103ab

Browse files
committed
introduce regular expressions, upgrade to version 2
1 parent 875c2cf commit e3103ab

3 files changed

Lines changed: 128 additions & 65 deletions

File tree

README.md

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
A color-theme looper for Emacs 24.
99

10+
> Note: Breaking changes in version 2
11+
1012
![Demo](images/demo.gif)
1113

1214
## Background
13-
### (you can skip to Usage)
15+
16+
### (You may directly skip to Usage)
1417

1518
Emacs 24 comes with a set of pre-installed color-themes that can be enabled by a simple command like:
1619

@@ -40,21 +43,45 @@ If you have MELPA-Stable, MELPA or Marmalade added as a repository to your Emacs
4043

4144
## Usage
4245

43-
*Optional:* Set the list of your favorite color themes:
46+
### Set key-bindings to switch themes like a breeze
47+
48+
(global-set-key (kbd "C-|") 'theme-looper-enable-next-theme)
49+
(global-set-key (kbd "C-\") 'theme-looper-enable-random-theme)
50+
51+
### *Optional:* Set a list of your favorite color themes:
52+
53+
By specifying a particular set of themes
54+
55+
(theme-looper-set-favorite-themes '(wombat tango-dark wheatgrass))
56+
57+
or using a regular expression
4458

45-
(theme-looper-set-theme-set '(wombat tango-dark wheatgrass))
59+
(theme-looper-set-favorite-themes-regexp "dark")
4660

47-
*Optional:* Set the list of ignored themes:
61+
### *Optional:* Set a list of ignored themes:
62+
63+
By specifying a particular set of themes
4864

4965
(theme-looper-set-ignored-themes '(cobalt))
5066

51-
*Optional:* Set both, in which case only the favorite themes that are not within the ones to be ignored are used.
67+
or using a regular expression
5268

53-
Set up your key-bindings:
69+
(theme-looper-set-ignored-themes-regexp "green")
5470

55-
(global-set-key (kbd "C-|") 'theme-looper-enable-next-theme)
56-
(global-set-key (kbd "C-\") 'theme-looper-enable-random-theme)
71+
### *Optional:* Set both
72+
73+
In this case, only the favorite themes that are not within the ones to be ignored are used.
74+
75+
### More
76+
77+
If you want to reset your color-theme preferences, simply use
78+
79+
(theme-looper-reset-themes-selection)
80+
81+
You can set some script to be run after every theme switch
82+
83+
(theme-looper-set-post-switch-script 'my-func)
5784

58-
Optional: Set additional customization to be applied after every theme switch:
85+
## Acknowledgments
5986

60-
(theme-looper-set-customizations 'my-func)
87+
Thanks to [protonpopsicle](https://github.com/protonpopsicle), [zombiefungus](https://github.com/zombiefungus) and [romildo](https://github.com/romildo) for their valuable inputs to suggest changes and enhancements.

theme-looper-tests.el

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@
2929
(ert-deftest tl-test:setting-favorite-themes ()
3030
(unwind-protect
3131
(progn
32-
;Should contain all themes as favorite by default
33-
(should (equal theme-looper--favorite-themes
32+
;;Should contain all themes as favorite by default
33+
(should (equal theme-looper--favorite-themes
3434
(custom-available-themes)))
35-
;Should set the themes provided as favorite
36-
(theme-looper-set-theme-set (list 'wombat
37-
'tango-dark
38-
'wheatgrass))
39-
(should (equal theme-looper--favorite-themes
35+
;;Should set the themes provided as favorite
36+
(theme-looper-set-favorite-themes (list 'wombat
37+
'tango-dark
38+
'wheatgrass))
39+
(should (equal theme-looper--favorite-themes
4040
(list 'wombat
4141
'tango-dark
4242
'wheatgrass))))
43-
(setq theme-looper--favorite-themes
43+
(setq theme-looper--favorite-themes
4444
(custom-available-themes))))
4545

4646
(ert-deftest tl-test:disabling-enabled-themes ()
4747
(let ((current-theme (car custom-enabled-themes)))
4848
(unwind-protect
4949
(progn
50-
;Should be able to disable all enabled themes
50+
;;Should be able to disable all enabled themes
5151
(theme-looper--disable-all-themes)
5252
(should (equal custom-enabled-themes
5353
'())))
@@ -58,33 +58,33 @@
5858
(let ((current-theme (car custom-enabled-themes)))
5959
(unwind-protect
6060
(progn
61-
(theme-looper-set-theme-set (list 'wombat
62-
'tango-dark
63-
'wheatgrass))
64-
;Should identify the enabled theme
61+
(theme-looper-set-favorite-themes (list 'wombat
62+
'tango-dark
63+
'wheatgrass))
64+
;;Should identify the enabled theme
6565
(load-theme 'wombat
6666
t)
67-
(should (equal (theme-looper--get-current-theme)
67+
(should (equal (theme-looper--get-current-theme)
6868
'wombat))
69-
;Should identify the next theme position in the list
69+
;;Should identify the next theme position in the list
7070
(should (equal (theme-looper--get-next-theme-index)
7171
1))
72-
;Should identify the next theme
72+
;;Should identify the next theme
7373
(should (equal (theme-looper--get-next-theme)
7474
'tango-dark))
75-
;Should default to first theme as next theme when
76-
;current theme is not in the list
75+
;;Should default to first theme as next theme when
76+
;;current theme is not in the list
7777
(load-theme 'manoj-dark
7878
t)
7979
(should (equal (theme-looper--get-next-theme)
8080
'wombat))
81-
;Should loop back to the first theme when
82-
;current theme is the last in the list
81+
;;Should loop back to the first theme when
82+
;;current theme is the last in the list
8383
(load-theme 'wheatgrass
8484
t)
8585
(should (equal (theme-looper--get-next-theme)
8686
'wombat)))
87-
(setq theme-looper--favorite-themes
87+
(setq theme-looper--favorite-themes
8888
(custom-available-themes))
8989
(load-theme current-theme
9090
t))))
@@ -93,59 +93,59 @@
9393
(let ((current-theme (car custom-enabled-themes)))
9494
(unwind-protect
9595
(progn
96-
(theme-looper-set-theme-set (list 'wombat
97-
'tango-dark
98-
'wheatgrass))
99-
;Should select first theme when the selected theme in not in the list
96+
(theme-looper-set-favorite-themes (list 'wombat
97+
'tango-dark
98+
'wheatgrass))
99+
;;Should select first theme when the selected theme in not in the list
100100
(load-theme 'tango
101101
t)
102102
(theme-looper-enable-next-theme)
103103
(should (equal custom-enabled-themes
104104
'(wombat)))
105-
;Should proceed to the next theme
105+
;;Should proceed to the next theme
106106
(theme-looper-enable-next-theme)
107107
(should (equal custom-enabled-themes
108108
'(tango-dark)))
109-
;Should loop back to the first theme when the cycle completes
109+
;;Should loop back to the first theme when the cycle completes
110110
(theme-looper-enable-next-theme)
111111
(theme-looper-enable-next-theme)
112112
(should (equal custom-enabled-themes
113113
'(wombat))))
114-
(setq theme-looper--favorite-themes
114+
(setq theme-looper--favorite-themes
115115
(custom-available-themes))
116116
(load-theme current-theme
117117
t))))
118118

119119
(ert-deftest tl-test:adding-customization ()
120120
(let ((current-theme (car custom-enabled-themes))
121-
(current-face-height (face-attribute 'default
121+
(current-face-height (face-attribute 'default
122122
:height)))
123123
(unwind-protect
124124
(progn
125-
(message (concatenate 'string
126-
"current-face-height: "
127-
(number-to-string current-face-height)))
128-
(theme-looper-set-theme-set (list 'wombat
129-
'tango-dark
130-
'wheatgrass))
131-
;Should apply customizations when specified
125+
(message (concatenate 'string
126+
"current-face-height: "
127+
(number-to-string current-face-height)))
128+
(theme-looper-set-favorite-themes (list 'wombat
129+
'tango-dark
130+
'wheatgrass))
131+
;;Should apply customizations when specified
132132
(load-theme 'tango
133133
t)
134-
(theme-looper-set-customizations (lambda ()
135-
(set-face-attribute 'default nil
136-
:height 120)))
134+
(theme-looper-set-post-switch-script (lambda ()
135+
(set-face-attribute 'default nil
136+
:height 120)))
137137
(theme-looper-enable-next-theme)
138-
(message (concatenate 'string
139-
"found face-height: "
140-
(number-to-string (face-attribute 'default :height))))
138+
(message (concatenate 'string
139+
"found face-height: "
140+
(number-to-string (face-attribute 'default :height))))
141141
(should (< (abs (- (face-attribute 'default :height)
142142
120))
143143
2)))
144-
(setq theme-looper--favorite-themes
144+
(setq theme-looper--favorite-themes
145145
(custom-available-themes))
146146
(load-theme current-theme
147147
t)
148-
(set-face-attribute 'default nil
148+
(set-face-attribute 'default nil
149149
:height current-face-height))))
150150

151151
;;; theme-looper-tests.el ends here

theme-looper.el

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; This file is not part of Emacs
44

55
;; Author: Mohammed Ismail Ansari <team.terminal@gmail.com>
6-
;; Version: 1.0
6+
;; Version: 2.0
77
;; Keywords: convenience, color-themes
88
;; Maintainer: Mohammed Ismail Ansari <team.terminal@gmail.com>
99
;; Created: 2014/03/22
@@ -33,28 +33,40 @@
3333
;;
3434
;; (require 'theme-looper)
3535
;;
36-
;; And set a key-binding for cycling thru themes
36+
;; And set a key-bindings for cycling thru themes
3737
;;
3838
;; (global-set-key (kbd "C-|") 'theme-looper-enable-next-theme)
3939
;;
4040
;; Or you can switch to a random theme
4141
;;
4242
;; (global-set-key (kbd "C-\\") 'theme-looper-enable-random-theme)
4343
;;
44-
;; You can also set your list of favorite themes
44+
;; You can also set a list of your favorite themes
4545
;;
46-
;; (theme-looper-set-theme-set '(wombat tango-dark wheatgrass))
46+
;; (theme-looper-set-favorite-themes '(wombat tango-dark wheatgrass))
4747
;;
48-
;; You can alternatively set the ignored themes
48+
;; or to use regular expressions
49+
;;
50+
;; (theme-looper-set-favorite-themes-regexp "dark")
51+
;;
52+
;; You can alternatively set the themes to be ignored
4953
;;
5054
;; (theme-looper-set-ignored-themes '(cobalt))
5155
;;
56+
;; or to use regular expressions
57+
;;
58+
;; (theme-looper-set-ignored-themes-regexp "green")
59+
;;
5260
;; Or you can set both, in which case only the favorite themes that are not
5361
;; within the ones to be ignored are used.
5462
;;
55-
;; You can set customization to be applied after every theme switch
63+
;; If you want to reset your color-theme preferences, simply use
5664
;;
57-
;; (theme-looper-set-customizations my-func)
65+
;; (theme-looper-reset-themes-selection)
66+
;;
67+
;; You can set some script to be run after every theme switch
68+
;;
69+
;; (theme-looper-set-post-switch-script my-func)
5870
;;
5971

6072
;;; Commentary:
@@ -82,23 +94,47 @@
8294
nil)
8395

8496
;;;###autoload
85-
(defun theme-looper-set-theme-set (themes)
97+
(defun theme-looper-set-favorite-themes (themes)
8698
"Sets the list of color-themes to cycle thru"
8799
(setq theme-looper--favorite-themes
88100
themes))
89101

102+
;;;###autoload
103+
(defun theme-looper-set-favorite-themes-regexp (regexp)
104+
"Sets the list of color-themes to cycle thru, matching a regular expression"
105+
(setq theme-looper--favorite-themes
106+
(cl-remove-if-not (lambda (theme)
107+
(string-match-p regexp
108+
(symbol-name theme)))
109+
(custom-available-themes))))
110+
90111
;;;###autoload
91112
(defun theme-looper-set-ignored-themes (themes)
92113
"Sets the list of color-themes to ignore"
93114
(setq theme-looper--ignored-themes
94115
themes))
95116

96117
;;;###autoload
97-
(defun theme-looper-set-customizations (func)
98-
"Sets customization to be applied after every theme switch"
118+
(defun theme-looper-set-ignored-themes-regexp (regexp)
119+
"Sets the list of color-themes to ignore, matching a regular expression"
120+
(setq theme-looper--ignored-themes
121+
(cl-remove-if-not (lambda (theme)
122+
(string-match-p regexp
123+
(symbol-name theme)))
124+
(custom-available-themes))))
125+
126+
;;;###autoload
127+
(defun theme-looper-set-post-switch-script (func)
128+
"Sets script to be run after every theme switch"
99129
(setq theme-looper--further-customize
100130
func))
101131

132+
;;;###autoload
133+
(defun theme-looper-reset-themes-selection ()
134+
"Resets themes selection back to default"
135+
(theme-looper-set-favorite-themes (custom-available-themes))
136+
(theme-looper-set-ignored-themes nil))
137+
102138
(defun theme-looper--get-current-theme ()
103139
"Determines the currently enabled theme"
104140
(car custom-enabled-themes))
@@ -163,7 +199,7 @@
163199
(theme-looper--get-looped-themes))))
164200
(theme-looper-enable-theme theme-looper-next-theme)))
165201

166-
(theme-looper-set-theme-set (custom-available-themes))
202+
(theme-looper-reset-themes-selection)
167203

168204
(provide 'theme-looper)
169205

0 commit comments

Comments
 (0)