├── .github ├── ISSUE_TEMPLATE │ ├── BUG-REPORT.yml │ ├── FEATURE-REQUEST.yml │ └── config.yml └── workflows │ └── test.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── autothemer.el ├── bin ├── setup └── test ├── function-reference.md └── tests └── autothemer-tests.el /.github/ISSUE_TEMPLATE/BUG-REPORT.yml: -------------------------------------------------------------------------------- 1 | name: "🪲 Bug Report" 2 | description: Create a new issue for a bug. 3 | title: "🪲 [BUG] - " 4 | labels: [ 5 | "bug" 6 | ] 7 | body: 8 | - type: textarea 9 | id: description 10 | attributes: 11 | label: "Description" 12 | description: Please enter a short/clear description of your issue 13 | placeholder: Enter a short/clear description of your issue. 14 | validations: 15 | required: true 16 | - type: textarea 17 | id: reprod 18 | attributes: 19 | label: "Steps to Reproduce the issue. (Issues that cannot be reproduced will be closed.)" 20 | description: Please enter accurate steps to reproduce the issue. 21 | value: | 22 | 1. Open foobar.rs '...' 23 | 2. M-x doctor'....' 24 | 3. Doctor says: What seems to be the problem? '....' 25 | 4. Debugger opens with error 'void function foo-bae' 26 | render: bash 27 | validations: 28 | required: true 29 | - type: textarea 30 | id: screenshot 31 | attributes: 32 | label: "Screenshots" 33 | description: If applicable, add screenshots to help explain your problem. (link to an image.) 34 | value: | 35 | ![DESCRIPTION](LINK.png) 36 | render: bash 37 | validations: 38 | required: false 39 | - type: textarea 40 | id: logs 41 | attributes: 42 | label: "Logs" 43 | description: Please copy and paste any relevant log or debug output. This will be automatically formatted into code, so no need for backticks. 44 | render: bash 45 | validations: 46 | required: false 47 | - type: dropdown 48 | id: browsers 49 | attributes: 50 | label: "Emacs version" 51 | description: What Emacs version are you seeing the problem on ? 52 | multiple: true 53 | options: 54 | - 26.1 55 | - 26.2 56 | - 26.3 57 | - 27.1 58 | - 27.2 59 | - 28.1 60 | - snapshot 61 | validations: 62 | required: false 63 | - type: dropdown 64 | id: display 65 | attributes: 66 | label: "Emacs running on GUI, Terminal or Daemon?" 67 | description: How was Emacs being run? GUI, Terminal or Daemon? 68 | multiple: true 69 | options: 70 | - "GUI" 71 | - "Terminal COLORTERM=truecolor" 72 | - "Terminal TERM=xterm256colors" 73 | - "Terminal other (tell us about it in the description.)" 74 | - "Daemon" 75 | validations: 76 | required: false 77 | - type: dropdown 78 | id: os 79 | attributes: 80 | label: "OS" 81 | description: What is the impacted environment ? 82 | multiple: true 83 | options: 84 | - Windows 85 | - Linux 86 | - Mac 87 | - Solaris 88 | - AiX 89 | - HP/UX 90 | validations: 91 | required: false 92 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/FEATURE-REQUEST.yml: -------------------------------------------------------------------------------- 1 | name: "🐣 Feature Request" 2 | description: Create a new issue for a new feature request 3 | title: "🐣 [REQUEST] - <title>" 4 | labels: [ 5 | "question" 6 | ] 7 | body: 8 | - type: textarea 9 | id: implementation_pr 10 | attributes: 11 | label: "Implementation PR" 12 | description: Pull request used 13 | placeholder: "#Pull Request ID" 14 | validations: 15 | required: false 16 | - type: textarea 17 | id: reference_issues 18 | attributes: 19 | label: "Reference Issues" 20 | description: Common issues 21 | placeholder: "#Issues IDs" 22 | validations: 23 | required: false 24 | - type: textarea 25 | id: summary 26 | attributes: 27 | label: "Summary" 28 | description: Provide a brief explanation of the feature 29 | placeholder: Describe in a few lines your feature request 30 | validations: 31 | required: true 32 | - type: textarea 33 | id: basic_example 34 | attributes: 35 | label: "Basic Example" 36 | description: Indicate here some basic examples of your feature. If the feature exists in another product, this is a good place to mention and link to it. 37 | placeholder: A few specific words about your feature request. 38 | validations: 39 | required: true 40 | - type: textarea 41 | id: drawbacks 42 | attributes: 43 | label: "Drawbacks" 44 | description: What are the drawbacks/impacts of your feature request ? 45 | placeholder: Identify the drawbacks and impacts while being neutral on your feature request 46 | validations: 47 | required: true 48 | - type: textarea 49 | id: unresolved_question 50 | attributes: 51 | label: "Unresolved questions" 52 | description: What questions still remain unresolved ? 53 | placeholder: Any unresolved issues? 54 | validations: 55 | required: false 56 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Autothemer Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | emacs_version: 15 | - 26.1 16 | - 26.2 17 | - 26.3 18 | - 27.1 19 | - 27.2 20 | - 28.1 21 | - 28.2 22 | - snapshot 23 | fail-fast: false 24 | steps: 25 | - uses: actions/checkout@v3 26 | - name: Set up Emacs 27 | uses: purcell/setup-emacs@v4.0 28 | with: 29 | version: ${{ matrix.emacs_version }} 30 | 31 | - name: Test 32 | run: | 33 | bin/setup 34 | bin/test 35 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Welcome to Emacs AutoThemer. You can contribute to the project in the following ways: 4 | 5 | - **Bug reports:** One liner reports are difficult to understand and review. 6 | - Follow the bug reporting issue template and provide clear, concise descriptions and steps to reproduce the bug. 7 | - Ensure that you have searched the existing issues to avoid duplicates. 8 | - Maintainers may close unclear issues that lack enough information to reproduce a bug. [Report a bug here](https://github.com/jasonm23/autothemer/issues/new/choose). 9 | - Maintainers WILL close issues if they cannot be reliably and repeatedly reproduced, without loading your config. 10 | 11 | - **Feature suggestions:** If you feel there is a nice enhancement or feature that can benefit many users, please open a feature request issue. 12 | - Ensure that you have searched the existing issues to avoid duplicates. 13 | - What makes sense for the project, what suits its scope and goals, and its future direction are at the discretion of the maintainers who put in the time, effort, and energy in building and maintaining the project for free. Please be respectful of this and keep discussions friendly and fruitful. 14 | - It is the responsibility of the requester to clearly explain and justify why a change is warranted. It is not the responsibility of the maintainers to coax this information out of a requester. So, please post well researched, well thought out, and detailed feature requests saving everyone time. 15 | - Maintainers may close unclear feature requests that lack enough information. [Suggest a feature here](https://github.com/jasonm23/autothemer/issues/new/choose). 16 | 17 | - **Pull requests** 18 | This is a tricky one for many reasons. A PR, be it a new feature or a small enhancement, has to make sense to the project's overall scope, goals, and technical aspects. The quality, style, and conventions of the code have to conform to that of the project's. Performance, usability, stability and other kinds of impacts of a PR should be well understood. 19 | 20 | This makes reviewing PRs a difficult and time consuming task. The bigger a PR, the more difficult it is to understand. Reviewing a PR in detail, engaging in back and forth discussions to improve it, and deciding that it is meaningful and safe to merge can often require more time and effort than what has gone into creating a PR. Thus, ultimately, whether a PR gets accepted or not, for whatever reason, is at the discretion of the maintainers. Please be respectful of the fact that maintainers have a much deeper understanding of the overall project. So, nitpicking on micro aspects may not be meaningful. 21 | 22 | To keep the process smooth **send small PRs:** Whenever possible, send small PRs with well defined scopes. The smaller the PR, the easier it is to review and test. Bundling multiple features into a single PR is highly discouraged. 23 | 24 | - **Be respectful** 25 | Remember, most FOSS projects are fruits of love and labour of maintainers who share them with the world for free with no expectations of any returns. Free as in freedom, and free as in beer too. Really, *some people just want to watch the world turn*. 26 | 27 | ### So: 28 | 29 | - Please be respectful and refrain from using aggressive or snarky language. It wastes time, energy, cognitive bandwidth, and goodwill. 30 | - Please refrain from demanding. How badly you want a feature has no bearing on whether it warrants a maintainer's time or attention. It is entirely up to the maintainers, if, how, and when they want to implement something. 31 | - Please do not nitpick and generate unnecessary discussions that waste time. 32 | - Please make sure you have searched the docs and issues before asking support questions. 33 | - **Please remember, FOSS project maintainers owe you nothing** (unless you have an explicit agreement with them, of course) including their time in responding to your messages or providing free customer support. If you want to be heard, please be respectful and establish goodwill. 34 | - If these are unacceptable to you 35 | - You don't have to use the project 36 | - You can always fork the project and change it to your liking while adhering to the terms of the license. That is the beauty of FOSS, afterall. 37 | 38 | Thank you 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see <http://www.gnu.org/licenses/>. 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | <http://www.gnu.org/licenses/>. 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Autothemer 2 | 3 | [![Autothemer Tests](https://github.com/jasonm23/autothemer/actions/workflows/test.yml/badge.svg)](https://github.com/jasonm23/autothemer/actions/workflows/test.yml) 4 | 5 | [![NonGNU ELPA](https://elpa.nongnu.org/nongnu/autothemer.svg?cache=invalidate)](https://elpa.nongnu.org/nongnu/autothemer.html) 6 | [![MELPA](https://melpa.org/packages/autothemer-badge.svg)](https://melpa.org/#/autothemer) 7 | [![MELPA Stable](https://stable.melpa.org/packages/autothemer-badge.svg)](https://stable.melpa.org/#/autothemer) 8 | 9 | Autothemer provides `autothemer-deftheme` a macro wrapper for `deftheme` and 10 | `custom-theme-set-faces` which creates a custom color theme. 11 | 12 | The package also includes useful theme development features see below. 13 | 14 | --- 15 | 16 | ## News 17 | 18 | We've added new things to AutoThemer in recent weeks: 19 | 20 | - Color distance is using CIELAB colorspace and CIE DE2000 distance algorithm. 21 | - As a result all missing face commands generate better color matches from the theme palette. 22 | - Colors which use color names (Red1, Burlywood and other gems. now get color matched properly.) 23 | - You can interactively insert a single face spec from the un-themed / missing theme specs, with approximated colors as noted above. 24 | - [Updates to the list of themes using autothemer](#themes-using-autothemer) (More to come...) 25 | - [Theme Variant Architecture/TVA](#tva) A convention for developing themes with multiple versions. 26 | - [Generate a cool SVG Palette image](#generate-a-svg-image-of-the-palette) Generate a cool SVG Palette image [like this one...](https://raw.githubusercontent.com/emacsfodder/emacs-theme-orangey-bits/master/palette.svg) 27 | - [Select colors from the theme in development](#select-colors-from-the-palette) Select, and insert a palette color name, or it's color value. 28 | - [Colorize palette color names](#colorize-color-names-from-the-palette) 29 | - [Autothemer-let-palette macro](#let-palette) 30 | - [Generate missing specs, updated to allow filtering](#auto-generating-missing-specs) 31 | 32 | ## Overview 33 | 34 | `autothemer-deftheme` uses a color class(es)/palette(s) which simplify the `deftheme` style and 35 | simplified face specifications to be applied to Emacs faces. 36 | 37 | See the example below. 38 | 39 | ```lisp 40 | (autothemer-deftheme example-name "Autothemer example..." 41 | 42 | ;; Specify the color classes used by the theme 43 | ((((class color) (min-colors #xFFFFFF)) 44 | ((class color) (min-colors #xFF))) 45 | 46 | ;; Specify the color palette, color columns correspond to each of the classes above. 47 | (example-red "#781210" "#FF0000") 48 | (example-green "#22881F" "#00D700") 49 | (example-blue "#212288" "#0000FF") 50 | (example-purple "#812FFF" "#Af00FF") 51 | (example-yellow "#EFFE00" "#FFFF00") 52 | (example-orange "#E06500" "#FF6600") 53 | (example-cyan "#22DDFF" "#00FFFF")) 54 | 55 | ;; Specifications for Emacs faces. 56 | ;; Simpler than deftheme, just specify a face name and 57 | ;; a plist of face definitions (nested for :underline, :box etc.) 58 | ((button (:underline t :weight 'bold :foreground example-yellow)) 59 | (error (:foreground example-red))) 60 | 61 | ;; Forms after the face specifications are evaluated. 62 | ;; (palette vars can be used, read below for details.) 63 | 64 | (custom-theme-set-variables 'example-name 65 | `(ansi-color-names-vector [,example-red 66 | ,example-green 67 | ,example-blue 68 | ,example-purple 69 | ,example-yellow 70 | ,example-orange 71 | ,example-cyan]))) 72 | ``` 73 | 74 | ## Faces and Color Classes 75 | 76 | One of the things that makes writing themes for Emacs painful is the syntax of `defface`, 77 | the macro used to configre Emacs `face` definitions. 78 | 79 | Because the syntax isn't developer friendly it usually results in themes with limited support. Especially for 80 | different color displays. Usually GUI / 24bit themes are made, and the results in the terminal are often sub par. 81 | On occassion a theme does appear that provides better support for multiple display types, but due to the manual work 82 | involved in adding face specs, mode support is limited and development often stalls. 83 | 84 | On the plus side the complexity of face specifcations means we can in theory design themes that support any display 85 | with any number of colors, we can support dark and light background modes. Until now it's been hard to fully 86 | exploit the potential. 87 | 88 | Autothemer attempts to solve the problems that a theme developer faces. By defining a simple set of 89 | color class rules we can remove repetitive face specs. 90 | 91 | Looking again at the example above. 92 | 93 | ```lisp 94 | (((class color) (min-colors #xFFFFFF)) 95 | ((class color) (min-colors #xFF))) 96 | ``` 97 | 98 | Here we've setup a color class for 16.8million (0xFFFFFF) color display i.e. 24bit, 99 | which will be read from first column in the palette. Next we setup a color class for 256 (0xFF) color 100 | displays i.e. `xterm-256color`, the color palette values for this will be read from 101 | the corresponding second column. 102 | 103 | We can setup as many columns as we'd like to support, here's a few more examples. 104 | 105 | For a two color display: 106 | 107 | ```lisp 108 | ((class color) (monochrome))) 109 | ``` 110 | 111 | For a light background 24bit 112 | 113 | ```lisp 114 | ((class color) (min-colors #xFFFFFF) (background light)) 115 | ``` 116 | 117 | For a dark background 24bit 118 | 119 | ```lisp 120 | ((class color) (min-colors #xFFFFFF) (background dark)) 121 | ``` 122 | 123 | You can read more about defining faces in the Emacs manual, 124 | [display types and class color is covered here.](https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Faces.html) 125 | 126 | ### Palette 127 | 128 | The palette definition is specified as a list of lists, each of the nested lists is a 129 | color name and then color values that correspond to each of the display/color classes 130 | defined above. 131 | 132 | You can set color values as nil and the first color to the left will be used. 133 | 134 | For example, if we have three display classes defined, 256, 24bit, 16 color: 135 | 136 | ```lisp 137 | ((((class color) (min-colors #xFF)) 138 | ((class color) (min-colors #xFFFFFF)) 139 | ((class color) (min-colors 16))) 140 | 141 | ;; We define my-red in 256 color mode only. 142 | (my-red "#FF0000" nil nil)) 143 | ``` 144 | 145 | Note we only specify 256 color mode's `my-red` value, and leave the 146 | others as nil. Autothemer will copy the value `#FF0000` to the other 147 | color classes at the same paletee index if they are nil. 148 | 149 | ### Simplified face specs 150 | 151 | In a regular theme (created with the `deftheme` macro) we have to 152 | specify faces with the display attributes included for every face. 153 | Autothemer's primary purpose is to reduce this down to a minimum. 154 | 155 | As we can see in the example above face specs now look like this: 156 | 157 | ```lisp 158 | ;; specifications for Emacs faces. 159 | ((button (:underline t :weight 'bold :foreground example-yellow)) 160 | (error (:foreground example-red))) 161 | ``` 162 | 163 | color names from the palette can be used directly, as we can see here. 164 | The faces are using colors named `example-yellow` and `example-red`. 165 | 166 | One important thing to remember is that we are in a different context 167 | to `deftheme` so symbols like `bold` or faces we want to `:inherit` 168 | from must use the `'` quote-mark. (See the example above `'bold` would 169 | usually not be quoted.) The following face attributes will be 170 | affected. 171 | 172 | - `:inherit` 173 | - `:weight` 174 | - `:slant` 175 | - `:style` 176 | 177 | (NOTE: there may be others I have missed. Please open an [issue] if you find 178 | another attribute that needs quoting.) 179 | 180 | ### Body / Evaluated Forms 181 | 182 | After defining the display specs, palette and simplified face specs, 183 | you can include other code to be evaluated. 184 | 185 | Be aware that colors named in the palette will need to be `,` 186 | comma-ed so they evaluate correctly. For example if you wanted to use 187 | the color `my-red` somewhere in the `body` section, you would refer to it 188 | as `,my-red`, so that it's evaluated properly. 189 | 190 | ### Auto generating missing specs 191 | 192 | You can automatically generate specs for faces that are not in your 193 | theme using the command 194 | 195 | ``` 196 | M-x autothemer-generate-templates 197 | ``` 198 | There's an alternative command to use if you'd like to filter by regexp. 199 | 200 | ``` 201 | M-x autothemer-generate-templates-filtered 202 | ``` 203 | 204 | These commands will create a new buffer with simplified specs for all the 205 | unthemed faces (or the subset you filtered by). Colors will be selected from the theme palette based on the 206 | nearest RGB distance to the un-themed color. 207 | 208 | ### Re-using the color palette 209 | 210 | While autothemer doesn't export the defined color variables for external 211 | use, you can define simple advice on `autothemer-deftheme` to do so: 212 | 213 | ```lisp 214 | (define-advice autothemer-deftheme (:before (_ _ palette &rest _) defcolors) 215 | (mapcar (lambda (e) 216 | (setf (symbol-value (car e)) 217 | (cadr e))) 218 | (cdr palette))) 219 | ``` 220 | 221 | If you place the advice definition before the autothemer-generated theme 222 | is loaded, e.g. `my-red` from the example above will be available as a 223 | variable that can be used in other parts of your emacs configuration. 224 | 225 | ### Let palette 226 | 227 | Alternatively you can create a let-like block using the macro `autothemer-let-palette`. 228 | You will need to load/eval the required autothemer theme source (not byte-compiled), before 229 | executing it. 230 | 231 | The palette color values will autocomplete, and you can check the palette 232 | with `M-x macrostep-expand`(place the cursor to the left of the macro call.) 233 | 234 | ![macrostep-expand on autothemer-let-palette](https://raw.githubusercontent.com/jasonm23/autothemer/images/let-palette-macrostep-expand.png) 235 | 236 | ### Colorize color-names from the palette 237 | 238 | Color names in the palette can be colorized, in any buffer. 239 | Make sure there's a current theme in `autothemer--current-theme` (eval your autothemer based theme from source, not byte-code) and use: 240 | 241 | ``` 242 | M-x autothemer-colorize 243 | ``` 244 | For example, with [Soothe Theme](https://github.com/emacsfodder/emacs-soothe-theme) viewing `soothe-tva.el`: 245 | 246 | ![colorize](https://raw.githubusercontent.com/jasonm23/autothemer/images/autothemer-colorize.png) 247 | 248 | For even more feedback, install and use the excellet [Fontify-Face](https://github.com/Fuco1/fontify-face) so you 249 | can see the current face definitions too. 250 | 251 | ![fontify-face](https://raw.githubusercontent.com/jasonm23/autothemer/images/autothemer-colorize-and-fontify-face.png) 252 | 253 | In these images `rainbow-mode` is also swiched on, so we can see hex colors and system palette names colorized. 254 | 255 | ``` 256 | M-x rainbow-mode 257 | ``` 258 | 259 | To edit colors interatively [Kurecolor](https://github.com/emacsfodder/kurecolor) will serve you well. 260 | 261 | ### Select colors from the palette 262 | 263 | Since version 0.2.8 it is possible to select a color from the palette (using the `completing-read` style.) 264 | 265 | `autothemer-select-color` returns an `autothemer--color` struct (`name`,`value`) 266 | 267 | ![](https://raw.githubusercontent.com/jasonm23/autothemer/images/autothemer-select-color-01.png) 268 | 269 | There are also commands to insert a selected color name or it's value. 270 | 271 | ``` 272 | M-x autothemer-insert-color-name 273 | ``` 274 | and... 275 | 276 | ``` 277 | M-x autothemer-insert-color 278 | ``` 279 | 280 | If `autothemer--current-theme` is `nil`, you'll need to eval an autothemer based 281 | theme before use. 282 | 283 | ### Generate a SVG image of the palette 284 | 285 | You can generate a SVG image of a theme palette: 286 | 287 | ![](https://raw.githubusercontent.com/emacsfodder/emacs-soothe-theme/images/soothe-palette-preview.png) 288 | 289 | Using `autothemer-generate-palette-svg` interactively, emacs will ask for the relevant parameters required. You can use `options` (a `plist`) to provide some or all of the required options. 290 | 291 | For example: 292 | 293 | ```lisp 294 | (autothemer-generate-palette-svg 295 | '(:theme-file "path/folder/my-autotheme.el" 296 | :svg-out-file "path/folder/my-autotheme-palette.svg" 297 | :bg-color "#190700" 298 | :text-color "#FFE0C0" 299 | :text-accent-color "#90776C" 300 | :swatch-height 160 301 | :swatch-width 120 302 | :theme-name "Orangey Bits" 303 | :font-family "Helvetica Neue")) 304 | ``` 305 | 306 | #### autothemer-generate-palette-svg options 307 | 308 | | Option | Description | 309 | |-----------------------|-------------------------------------------------------| 310 | | `theme-file` | Theme filename | 311 | | `theme-name` | Override the title found in `:theme-file` | 312 | | `theme-description` | Override the description found in `:theme-file` | 313 | | `theme-url` | Override the url found in `:theme-file` | 314 | | `font-family` | Font name to use in the generated SVG | 315 | | `columns` | Number of columns for each palette row (default: `6`) | 316 | | `bg-color` | Page background color | 317 | | `text-color` | Main text color | 318 | | `text-accent-color` | Accent text color | 319 | | `page-template` | See page-template below | 320 | | `page-top-margin` | Top margin of page (Default: `120`) | 321 | | `page-right-margin` | Right margin of page (Default: `30`) | 322 | | `page-bottom-margin` | Bottom margin of page (Default: `60`) | 323 | | `page-left-margin` | Left margin of page (Default: `30`) | 324 | | `swatch-template` | See swatch-template below | 325 | | `swatch-border-color` | The border color of a color swatch | 326 | | `swatch-width` | Px spacing width of a color swatch (default: `100`) | 327 | | `swatch-height` | Px spacing height of a color swatch (default: `150`) | 328 | | `swatch-rotate` | Degrees of rotation for swatch (default: `45`) | 329 | | `h-space` | Horizontal-space between swatches (default: `10`) | 330 | | `v-space` | Vertical-space between swatches (default: `10`) | 331 | | `sort-palette` | Arrange palette using a function see below | 332 | | `svg-out-file` | The file/pathname to save SVG output | 333 | 334 | ##### :page-template and :swatch-template 335 | 336 | For advanced customization the options `:page-template` and `:swatch-template`, 337 | can supplied as customized SVG templates. 338 | 339 | Note: Template parameters are `format` style, we mark them as follows: 340 | 341 | ###### Page Template parameters 342 | 343 | | Param | name | 344 | |---------|---------------------| 345 | | `%1$s` | `width` | 346 | | `%2$s` | `height` | 347 | | `%3$s` | `font-family` | 348 | | `%4$s` | `text-color` | 349 | | `%5$s` | `text-accent-color` | 350 | | `%6$s` | `bg-color` | 351 | | `%7$s` | `theme-name` | 352 | | `%8$s` | `theme-description` | 353 | | `%9$s` | `theme-url` | 354 | | `%10$s` | `swatches` | 355 | 356 | The builtin page template 357 | 358 | ```svg 359 | <?xml version="1.0" standalone="no"?> 360 | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 361 | "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 362 | <svg width="%1$spx" height="%2$spx" 363 | version="1.1" 364 | xmlns="http://www.w3.org/2000/svg" 365 | xmlns:xlink="http://www.w3.org/1999/xlink"> 366 | <style> 367 | text { 368 | font-family: "%3$s"; 369 | fill: %4$s; 370 | } 371 | </style> 372 | <rect x="0" y="0" rx="10" width="%1$spx" height="%2$spx" id="background-panel" fill="%6$s"/> 373 | <g transform="translate(14,10)"> 374 | <a xlink:href="%9$s"> 375 | <text style="font-size:42pt;" font-weight="bold" x="3%%" y="50" id="theme-name">%7$s</text> 376 | <text style="font-size:12pt;" x="4%%" y="75" id="theme-description">%8$s</text> 377 | <text style="font-size:8pt;fill: %5$s" text-anchor="end" x="95%%" y="20" id="theme-url">%9$s</text> 378 | </a> 379 | </g> 380 | <g transform="translate(70,-40)"> 381 | %10$s 382 | </g> 383 | </svg> 384 | ``` 385 | 386 | ###### Swatch Template parameters 387 | 388 | | Param | Description | 389 | |--------|-----------------------| 390 | | `%1$s` | `x` | 391 | | `%2$s` | `y` | 392 | | `%3$s` | `swatch-border-color` | 393 | | `%4$s` | `color` | 394 | | `%5$s` | `text-accent-color` | 395 | | `%6$s` | `name` | 396 | | `%7$s` | `swatch-width` | 397 | | `%8$s` | `swatch-height` | 398 | | `%9$s` | `swatch-rotate` | 399 | 400 | The builtin swatch template: 401 | 402 | ``` svg 403 | <g transform="translate(%1$s,%2$s),rotate(%9$s)"> 404 | <ellipse cx="70" cy="70" rx="45" ry="45" id="background-color" fill="%3$s"/> 405 | <ellipse cx="70" cy="70" rx="42" ry="42" id="color" fill="%4$s"/> 406 | <text style="font-size:7pt" font-weight="bold" x="52" y="125" id="color-name">%6$s</text> 407 | <text style="font-size:7pt; fill:%5$s;" font-weight="bold" x="52" y="134" id="color">%4$s</text> 408 | <!-- Rect below is for debug set stroke width to be visible --> 409 | <rect x="0" y="0" width="%7$spx" height="%8$spx" class="debug-rect" fill-opacity="0.0" stroke-width="0.0mm" stroke="#FF8000"/> 410 | </g> 411 | ``` 412 | ###### Sorting / Grouping palette colors 413 | 414 | The option `sort-palette` can be a `sort function`, or a `plist`. 415 | 416 | Options is a plist of: 417 | 418 | :group-fn - mandatory group function 419 | :group-args - optional group args (to use a non-default group) 420 | :sort-fn - optional sort function 421 | 422 | ###### Sorting: 423 | 424 | The sort/ordering functions take args A and B, which are expected 425 | to be `autothemer--color` structs. 426 | 427 | - Darkest to lightest: `autothemer-darkest-order` 428 | - Lightest to darkest: `autothemer-lightest-order` 429 | - Hue: `autothemer-hue-order` 430 | - Saturated to desaturated: `autothemer-saturated-order` 431 | - Desaturated to saturated: `autothemer-desaturated-order` 432 | 433 | ###### Grouping 434 | 435 | Hue grouping: 436 | 437 | autothemer-hue-group 438 | 439 | Builtin hue groups: 440 | 441 | autothemer-hue-groups 442 | autothemer-simple-hue-groups 443 | 444 | Brightness grouping: 445 | 446 | autothemer-brightness-group 447 | 448 | Builtin brightness groups: 449 | 450 | autothemer-dark-mid-light-brightness-groups 451 | autothemer-10-percent-brightness-groups 452 | autothemer-20-percent-brightness-groups 453 | 454 | Saturation grouping: 455 | 456 | autothemer-saturation-group 457 | 458 | Builtin saturation groups: 459 | 460 | autothemer-low-mid-high-saturation-groups 461 | autothemer-10-percent-saturation-groups 462 | autothemer-20-percent-saturation-groups 463 | 464 | #### SVG palette templates in the Wiki 465 | 466 | I'll add some more palette SVG templates in the Wiki, link to any more you create there too. I think gists are a good way to share them. 467 | 468 | [Wiki page here](/jasonm23/autothemer/wiki/Palette-SVG-Templates) 469 | 470 | ### [Complete Command/Function Reference](function-reference.md) 471 | 472 | # TVA 473 | 474 | Theme Variance Architecture is the pattern used in the Gruvbox theme for creating theme variants. 475 | 476 | For tooling compatibility you should use this architecture when creating theme variants with [Autothemer]. 477 | 478 | ### TVA Specification 479 | 480 | TVA requires package, themes and variants to be named using a specific convention. 481 | 482 | ### Convert an autothemer based theme to the TVA style. 483 | 484 | For example, let's say we've created a standalone theme called: 485 | 486 | ``` 487 | foo 488 | ``` 489 | 490 | Given the `package.el` and Emacs convention we will have named the Emacs lisp file: 491 | 492 | ``` 493 | foo-theme.el 494 | ``` 495 | 496 | To prepare to add variants, we'll create a macro for the `foo` theme family. It'll look after setting all the face specs in emacs, and allow us to define our variant palette elsewhere. **As long as the same palette variable names are used, we should be ok.** 497 | 498 | [Let's take a look at how this 499 | was done in Gruvbox](https://github.com/greduan/emacs-theme-gruvbox/blob/3929f29674ac1cb59efaa017e3c534e0d8d72a2d/gruvbox.el#L88) 500 | 501 | For our `foo-theme` we'd do the following. 502 | 503 | - Create a file called `foo.el` in the package folder. 504 | - Create `deftheme-foo` in `foo.el`. 505 | ``` 506 | (require 'autothemer) 507 | 508 | (defmacro deftheme-foo (name description palette &rest body) 509 | ,(autothemer ,name 510 | ,description 511 | ,palette 512 | 513 | ((face (specs...))) 514 | 515 | ,@body) 516 | ``` 517 | - Move the face specs from `foo-theme.el` into the `deftheme-foo` macro definition replacing: 518 | ``` 519 | ((face (specs...))) 520 | ``` 521 | For Gruvbox's development, [this commit captures the face specs move.](https://github.com/greduan/emacs-theme-gruvbox/commit/250df251d0972aecd259144ad1ad3daf33c97cb2). Although we'd already created variants at that point, and had a lot of code duplication. (TVA is the way we've DRYed up this duplication, giving `gruvbox.el` the status of single point where we add new mode support.) 522 | - Modify `foo-theme.el` 523 | - use `deftheme-foo` instead of `autothemer-deftheme` 524 | - Replace `(require 'autothemer)` with `(require 'foo)` 525 | 526 | ### Creating variants. 527 | 528 | Once we've completed the conversion to TVA style above. We can create a variant by copying `foo-theme.el` to a new name. 529 | 530 | For a light variant of our theme, we'll copy `foo-theme.el` to `foo-light-theme.el`. 531 | 532 | We can now modify the palette (use the same palette names and just modify the color values). We must also update the theme name. 533 | 534 | Check the differences in [`gruvbox-theme.el`](https://github.com/greduan/emacs-theme-gruvbox/blob/e9f8e6ee52727f6008c125b71a26c80cfa59c0af/gruvbox-theme.el) and [`gruvbox-dark-hard-theme.el`](https://github.com/greduan/emacs-theme-gruvbox/blob/e9f8e6ee52727f6008c125b71a26c80cfa59c0af/gruvbox-dark-hard-theme.el) 535 | 536 | `gruvbox-theme.el` 537 | 538 | ```lisp 539 | 1 ;;; gruvbox-theme.el --- A retro-groove colour theme for Emacs -*- lexical-binding: t -*- 540 | 541 | 53 (gruvbox-deftheme) 542 | 54 gruvbox 543 | 55 "A retro-groove colour theme" 544 | 545 | 146 (custom-theme-set-variables 'gruvbox) 546 | 547 | 165 (provide-theme 'gruvbox) 548 | 549 | 172 ;;; gruvbox-theme.el ends here 550 | ``` 551 | 552 | `gruvbox-dark-hard-theme.el` 553 | 554 | ```lisp 555 | 1 ;;; gruvbox-dark-hard-theme.el --- A retro-groove colour theme for Emacs -*- lexical-binding: t -*- 556 | 557 | 55 (gruvbox-deftheme) 558 | 56 gruvbox-dark-hard 559 | 57 "A retro-groove colour theme (dark version, hard contrast)" 560 | 561 | 148 (custom-theme-set-variables 'gruvbox-dark-hard) 562 | 563 | 167 (provide-theme 'gruvbox-dark-hard) 564 | 565 | 173 ;;; gruvbox-dark-hard-theme.el ends here 566 | ``` 567 | 568 | Once this is done you test your theme. 569 | 570 | (I use `disable-theme` and `enable-theme` to test/use themes under development. 571 | Make sure you eval all the theme's elisp files before enabling the theme.) 572 | 573 | ### Themes using Autothemer 574 | 575 | - [Patrick-Poitras/emacs-material-ocean](https://github.com/Patrick-Poitras/emacs-material-ocean) 576 | - [ajgrf/Parchment](https://github.com/ajgrf/parchment/) 577 | - [ed9w2in6/wood-theme](https://github.com/ed9w2in6/wood-theme) 578 | - [emacsfodder/Creamsody](https://github.com/emacsfodder/emacs-theme-creamsody) 579 | - [emacsfodder/Cyanometric](https://github.com/emacsfodder/emacs-theme-cyanometric) 580 | - [emacsfodder/Darktooth](https://github.com/emacsfodder/emacs-theme-darktooth) 581 | - [emacsfodder/Orangey Bits](https://github.com/emacsfodder/emacs-theme-orangey-bits) 582 | - [emacsfodder/Sakura](https://github.com/emacsfodder/emacs-theme-sakura) 583 | - [emacsfodder/Soothe](https://github.com/emacsfodder/emacs-soothe-theme) 584 | - [emacsfodder/Vegetative](https://github.com/emacsfodder/emacs-theme-vegetative) 585 | - [greduan/Gruvbox](https://github.com/greduan/emacs-theme-gruvbox) 586 | - [mtreca/Sorcery](https://github.com/mtreca/emacs-theme-sorcery) 587 | - [ogdenwebb/Kaolin](https://github.com/ogdenwebb/emacs-kaolin-themes) 588 | - [thongpv87/Rose Pine](https://github.com/thongpv87/rose-pine-emacs) 589 | 590 | If you are creating themes with Autothemer, please let us know, you can add the 591 | theme info to README and open a pull request. If you haven't released it as a 592 | package, via a common source, open an [issue], we can help. 593 | 594 | ### Contributing 595 | 596 | See [CONTRIBUTING](CONTRIBUTING.md) 597 | 598 | ### Licence 599 | 600 | See [LICENCE](LICENCE) 601 | 602 | [Autothemer]: https://github.com/jasonm23/autothemer 603 | [issue]: https://github.com/jasonm23/autothemer/issues/new/choose 604 | -------------------------------------------------------------------------------- /autothemer.el: -------------------------------------------------------------------------------- 1 | ;;; autothemer.el --- Conveniently define themes -*- lexical-binding: t -*- 2 | ;; 3 | ;; Authors: Sebastian Sturm, Jason Milkins 4 | ;; 5 | ;; Copyright 2015-2022 Sebastian Sturm, Jason Milkins 6 | ;; 7 | ;; Maintainer: Jason Milkins <jasonm23@gmail.com> 8 | ;; 9 | ;; URL: https://github.com/jasonm23/autothemer 10 | ;; Version: 0.2.18 11 | ;; Package-Requires: ((dash "2.10.0") (emacs "26.1")) 12 | ;; 13 | ;;; License: 14 | ;; This program is free software; you can redistribute it and/or modify 15 | ;; it under the terms of the GNU General Public License as published by 16 | ;; the Free Software Foundation, either version 3 of the License, or 17 | ;; (at your option) any later version. 18 | 19 | ;; This program is distributed in the hope that it will be useful, 20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | ;; GNU General Public License for more details. 23 | 24 | ;; You should have received a copy of the GNU General Public License 25 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 26 | 27 | ;;; Commentary: 28 | ;; 29 | ;; Reduce the amount of pain and boilerplate code needed to create custom themes using `autothemer-deftheme'. 30 | ;; 31 | ;; Autothemer also includes interactive commands and functions to 32 | ;; assist with theme building, here are a few highlights... 33 | ;; 34 | ;; - Generate specs for unthemed faces using the theme color palette. 35 | ;; - `autothemer-generate-templates' 36 | ;; - `autothemer-generate-templates-filtered' (filter by regexp) 37 | ;; - `autothemer-insert-missing-face' 38 | ;; - `autothemer-insert-missing-faces' 39 | ;; - Generate a palette SVG image 40 | ;; - `autothemer-generate-palette-svg' 41 | ;; - Insert a color name or color from the active palette 42 | ;; - `autothemer-insert-color-name' 43 | ;; - `autothemer-insert-color' 44 | ;; - Colorize/font-lock palette color names in the buffer 45 | ;; - `autothemer-colorize' (requires `rainbow-mode' during development.) 46 | ;; 47 | ;;; Code: 48 | (require 'cl-lib) 49 | (require 'dash) 50 | (require 'lisp-mnt) 51 | (require 'color) 52 | (require 'subr-x) 53 | 54 | (cl-defstruct 55 | autothemer--color 56 | name 57 | value) 58 | 59 | (cl-defstruct 60 | autothemer--theme 61 | colors 62 | defined-faces 63 | name 64 | description) 65 | 66 | (defvar autothemer-current-theme nil 67 | "Palette and face list for last evaluated `autothemer-deftheme'.") 68 | 69 | (defvar autothemer-hue-groups 70 | '((red (345 . 10)) 71 | (red-orange (10 . 20)) 72 | (orange-brown (20 . 40)) 73 | (orange-yellow (40 . 50)) 74 | (yellow (50 . 60)) 75 | (yellow-green (60 . 80)) 76 | (green (80 . 140)) 77 | (green-cyan (140 . 170)) 78 | (cyan (170 . 200)) 79 | (cyan-blue (200 . 220)) 80 | (blue (220 . 240)) 81 | (blue-magenta (240 . 280)) 82 | (magenta (280 . 320)) 83 | (magenta-pink (320 . 330)) 84 | (pink (330 . 345))) 85 | "Set of perceptual color ranges.") 86 | 87 | (defvar autothemer-simple-hue-groups 88 | '((red (345 . 20)) 89 | (orange (20 . 50)) 90 | (yellow (50 . 60)) 91 | (green (60 . 140)) 92 | (cyan (140 . 220)) 93 | (blue (220 . 280)) 94 | (magenta (280 . 345))) 95 | "Simple set of color groups.") 96 | 97 | (defvar autothemer-low-mid-high-saturation-groups 98 | '((low (0.0 . 0.3333333333333333)) 99 | (mid (0.3333333333333334 . 0.6666666666666666)) 100 | (high (0.6666666666666667 . 1.0))) 101 | "Low, mid & high saturation groups.") 102 | 103 | (defvar autothemer-20-percent-saturation-groups 104 | '((saturation-000-020-percent (0.0 . 0.2)) 105 | (saturation-020-040-percent (0.2 . 0.4)) 106 | (saturation-040-060-percent (0.4 . 0.6)) 107 | (saturation-060-080-percent (0.6 . 0.8)) 108 | (saturation-080-100-percent (0.8 . 1.0))) 109 | "Saturation grouping at 20% intervals. 110 | This is the default for `autothemer-saturation-group'.") 111 | 112 | (defvar autothemer-10-percent-saturation-groups 113 | '((saturation-000-010-percent (0.0 . 0.1)) 114 | (saturation-010-020-percent (0.1 . 0.2)) 115 | (saturation-020-030-percent (0.2 . 0.3)) 116 | (saturation-030-040-percent (0.3 . 0.4)) 117 | (saturation-040-050-percent (0.4 . 0.5)) 118 | (saturation-050-060-percent (0.5 . 0.6)) 119 | (saturation-060-070-percent (0.6 . 0.7)) 120 | (saturation-070-080-percent (0.7 . 0.8)) 121 | (saturation-080-090-percent (0.8 . 0.9)) 122 | (saturation-090-100-percent (0.9 . 1.0))) 123 | "Saturation grouping at 10% intervals.") 124 | 125 | (defvar autothemer-dark-mid-light-brightness-groups 126 | '((dark (0.0 . 0.3333333333333333)) 127 | (mid (0.3333333333333334 . 0.6666666666666666)) 128 | (light (0.6666666666666667 . 1.0))) 129 | "Dark, mid & light brightness groups.") 130 | 131 | (defvar autothemer-20-percent-brightness-groups 132 | '((brightness-000-020-percent (0.0 . 0.2)) 133 | (brightness-020-040-percent (0.2 . 0.4)) 134 | (brightness-040-060-percent (0.4 . 0.6)) 135 | (brightness-060-080-percent (0.6 . 0.8)) 136 | (brightness-080-100-percent (0.8 . 1.0))) 137 | "Brightness groups at 20% intervals. 138 | This is the default `autothemer-brightness-group'.") 139 | 140 | (defvar autothemer-10-percent-brightness-groups 141 | '((brightness-000-010-percent (0.0 . 0.1)) 142 | (brightness-010-020-percent (0.1 . 0.2)) 143 | (brightness-020-030-percent (0.2 . 0.3)) 144 | (brightness-030-040-percent (0.3 . 0.4)) 145 | (brightness-040-050-percent (0.4 . 0.5)) 146 | (brightness-050-060-percent (0.5 . 0.6)) 147 | (brightness-060-070-percent (0.6 . 0.7)) 148 | (brightness-070-080-percent (0.7 . 0.8)) 149 | (brightness-080-090-percent (0.8 . 0.9)) 150 | (brightness-090-100-percent (0.9 . 1.0))) 151 | "Brightness grouping at 10% intervals.") 152 | 153 | (defun autothemer--reduced-spec-to-facespec (display reduced-specs) 154 | "Create a face spec for DISPLAY, with specs REDUCED-SPECS. 155 | 156 | For example: 157 | 158 | (autothemer--reduced-spec-to-facespec 159 | '(min-colors 60) 160 | '(button (:underline t :foreground red))) 161 | ;; => `(button (((min-colors 60) (:underline ,t :foreground ,red))))." 162 | (let* ((face (elt reduced-specs 0)) 163 | (properties (elt reduced-specs 1)) 164 | (spec (autothemer--demote-heads `(list (,display ,properties))))) 165 | `(list ',face ,spec))) 166 | 167 | (defun autothemer--demote-heads (expr) 168 | "Demote every list head within EXPR by one element. 169 | E.g., (a (b c d) e (f g)) -> (list a (list b c d) e (list f g))." 170 | (if (listp expr) 171 | `(list ,@(mapcar 172 | (lambda (it) 173 | (if (and (listp it) (not (eq (car it) 'quote))) 174 | (autothemer--demote-heads it) it)) 175 | expr)) 176 | expr)) 177 | 178 | ;;;###autoload 179 | (defmacro autothemer-deftheme (name description palette reduced-specs &rest body) 180 | "Define a theme NAME with description DESCRIPTION. 181 | A color PALETTE can be used to define `let*'-like 182 | bindings within both the REDUCED-SPECS and the BODY." 183 | (let* ((face-names (-map #'car reduced-specs)) 184 | (color-names (-map #'car (-drop 1 palette))) 185 | (n-displays (length (car palette))) 186 | (n-faces (length reduced-specs)) 187 | (face-customizer) 188 | (full-palette (autothemer--fill-empty-palette-slots palette)) 189 | (face-specs (make-symbol "face-specs")) 190 | (temp-n (make-symbol "n")) 191 | (temp-defined-colors (make-symbol "defined-colors")) 192 | (temp-color-structs (make-symbol "defined-colors-as-structs")) 193 | (temp-color (make-symbol "color")) 194 | (temp-colorname (make-symbol "colorname"))) 195 | (setq face-customizer 196 | `(let ((,face-specs) 197 | (,temp-color-structs) 198 | (,temp-defined-colors)) 199 | (deftheme ,name ,description) 200 | ,@(cl-loop for n from 0 to (1- n-displays) 201 | collect 202 | `(let* ,(autothemer--extract-let-block full-palette n) 203 | ,@(when (and body (eq n 0)) 204 | body) 205 | ,(when (> n 0) 206 | `(ignore ,@color-names)) 207 | ,(when (and (eq n 0) (not (bound-and-true-p byte-compile-current-file))) 208 | `(progn 209 | (setq ,temp-defined-colors 210 | (list ,@(--map (list 'list `',it it) color-names))) 211 | (setq ,temp-color-structs 212 | (cl-loop for (,temp-colorname ,temp-color) 213 | in ,temp-defined-colors 214 | collect (make-autothemer--color :name ,temp-colorname 215 | :value ,temp-color))) 216 | (setq autothemer-current-theme 217 | (make-autothemer--theme 218 | :name ,(symbol-name name) 219 | :description ,description 220 | :colors ,temp-color-structs 221 | :defined-faces ',face-names)))) 222 | (setq ,face-specs 223 | (autothemer--append-column 224 | ,face-specs 225 | (list ,@(--map `(list 226 | (list 227 | ',(autothemer--extract-display palette n) 228 | ,(autothemer--demote-heads (elt it 1)))) 229 | reduced-specs)))))) 230 | (apply #'custom-theme-set-faces ',name 231 | (cl-loop for ,temp-n from 0 to ,(1- n-faces) 232 | collect (list (elt ',face-names ,temp-n) 233 | (elt ,face-specs ,temp-n)))))) 234 | face-customizer)) 235 | 236 | (defun autothemer--color-distance (color palette-color) 237 | "Return the distance in rgb space between COLOR and PALETTE-COLOR. 238 | Here, COLOR is an Emacs color specification and PALETTE-COLOR is of 239 | type `autothemer--color'." 240 | (declare (obsolete 'autothemer--cie-de2000 "0.2.13")) 241 | (let ((rgb-1 (autothemer-hex-to-rgb color)) 242 | (rgb-2 (autothemer-hex-to-rgb palette-color))) 243 | (-sum (--zip-with (abs (- it other)) rgb-1 rgb-2)))) 244 | 245 | (defun autothemer-cie-de2000 (color-a color-b) 246 | "Return the color distance in CIE Lab space, between COLOR-A and COLOR-B. 247 | Using the CIE-DE2000 algorithm." 248 | (let ((lab-1 (apply 'color-srgb-to-lab (autothemer-hex-to-srgb color-a))) 249 | (lab-2 (apply 'color-srgb-to-lab (autothemer-hex-to-srgb color-b)))) 250 | (color-cie-de2000 lab-1 lab-2))) 251 | 252 | (defun autothemer--find-closest-color (colors color) 253 | "Return the element of COLORS that is closest in CIE Lab space to COLOR. 254 | Here, COLOR is an Emacs color specification and COLORS is a list 255 | of `autothemer--color' structs." 256 | (let ((min-distance 0) 257 | (color (if (string-match-p "#[[:xdigit:]]\\{6\\}" color) 258 | color 259 | (autothemer-rgb-to-hex (color-values color)))) 260 | (closest-color nil)) 261 | (mapc (lambda (candidate) 262 | (when (color-defined-p (autothemer--color-value candidate)) 263 | (let ((distance (autothemer-cie-de2000 color candidate))) 264 | (if (or (not closest-color) (< distance min-distance)) 265 | (setq closest-color candidate 266 | min-distance distance))))) 267 | colors) 268 | closest-color)) 269 | 270 | (defun autothemer--unthemed-faces () 271 | "Find uncustomized faces. 272 | Iterate through all currently defined faces and return those that 273 | were left uncustomized by the most recent call to 274 | `autothemer-deftheme'." 275 | (let ((all-faces (face-list)) 276 | (themed-faces (autothemer--theme-defined-faces autothemer-current-theme))) 277 | (--filter (not (-contains? themed-faces it)) all-faces))) 278 | 279 | (defun autothemer--face-to-alist (face) 280 | "Return the attribute alist for FACE in frame (selected-frame)." 281 | (face-all-attributes face (selected-frame))) 282 | 283 | (defun autothemer--cons-to-tree (the-cons) 284 | "Turn THE-CONS into a list, unless its cdr is `unspecified'." 285 | (let ((property-name (car the-cons)) 286 | (property-value (cdr the-cons)) 287 | (result)) 288 | (unless (eq property-value 'unspecified) 289 | (setq result (list property-name property-value))) 290 | result)) 291 | 292 | (defun autothemer--alist-to-reduced-spec (facename alist) 293 | "Generate a reduced-spec for FACENAME, based on the face attribute ALIST." 294 | (list facename 295 | (--reduce-from (append acc it) nil 296 | (mapcar 'autothemer--cons-to-tree 297 | alist)))) 298 | 299 | (defun autothemer--approximate-spec (reduced-spec theme) 300 | "Replace colors in REDUCED-SPEC by their closest approximations in THEME. 301 | Replace every expression in REDUCED-SPEC that passes 302 | `color-defined-p' by the closest approximation found in 303 | `autothemer-current-theme'. Also quote all face names and 304 | unbound symbols, such as `normal' or `demibold'." 305 | (let ((colors (autothemer--theme-colors theme)) 306 | (face (car reduced-spec)) 307 | (spec (cdr reduced-spec))) 308 | `(,face ,@(--tree-map (cond ((and (stringp it) (color-defined-p it)) 309 | (autothemer--color-name 310 | (autothemer--find-closest-color colors it))) 311 | ((stringp it) it) 312 | ((numberp it) it) 313 | ((facep it) `(quote ,it)) 314 | ((consp it) it) 315 | ((not (boundp it)) `(quote ,it)) 316 | (t it)) 317 | spec)))) 318 | 319 | (defun autothemer--pad-with-nil (row min-number-of-elements) 320 | "Make sure that ROW has at least MIN-NUMBER-OF-ELEMENTS. 321 | Pad with nil if necessary." 322 | (append 323 | row 324 | (-repeat 325 | (max 0 326 | (- min-number-of-elements 327 | (length row))) 328 | nil))) 329 | 330 | (defun autothemer--replace-nil-by-precursor(palette-row) 331 | "Replace nil colors in PALETTE-ROW with their precursor. 332 | 333 | PALETTE-ROW is of the form `(name color [color ...])' Where the 334 | first `color' must be non nil. Any subsequent nil color will be 335 | replaced by the previous value. 336 | 337 | For example: 338 | (\"red-foo\" \"#FF0000\" nil) 339 | Will become: 340 | (\"red-foo\" \"#FF0000\" \"#FF0000\")" 341 | (cl-assert (car palette-row)) 342 | (let* ((color-name (car palette-row)) 343 | (color-definitions (cdr palette-row)) 344 | (last-definition)) 345 | (cons color-name 346 | (cl-loop for definition in color-definitions 347 | do (when definition (setq last-definition definition)) 348 | collect last-definition)))) 349 | 350 | (defun autothemer--fill-empty-palette-slots (palette) 351 | "Fill empty PALETTE slots so each display has all color-definitions." 352 | (let ((n-displays (length (car palette)))) 353 | (cons (car palette) 354 | (cl-loop for row in (cdr palette) 355 | collect (autothemer--replace-nil-by-precursor 356 | (autothemer--pad-with-nil row (1+ n-displays))))))) 357 | 358 | (defun autothemer--extract-display (palette n) 359 | "Extract from PALETTE display specification #N." 360 | (elt (car palette) n)) 361 | 362 | (defun autothemer--extract-let-block (palette n) 363 | "Extract a variable definition block from PALETTE for display type N." 364 | (cl-loop for row in (cdr palette) 365 | collect (list (car row) (elt row (1+ n))))) 366 | 367 | ;;;###autoload 368 | (defun autothemer-insert-missing-face () 369 | "Insert a face spec template for an unthemed face. 370 | An approximate color from the palette will be used for 371 | color attributes." 372 | (interactive) 373 | (let ((selected (completing-read "Select an un-themed face: " (autothemer--unthemed-faces)))) 374 | (insert 375 | (replace-regexp-in-string "\n" "" 376 | (pp-to-string 377 | (autothemer--approximate-spec 378 | (autothemer--alist-to-reduced-spec (intern selected) (autothemer--face-to-alist (intern selected))) 379 | autothemer-current-theme)))))) 380 | 381 | ;;;###autoload 382 | (defun autothemer-insert-missing-faces (&optional regexp) 383 | "Insert face spec templates for unthemed faces matching REGEXP. 384 | An error is shown when no current theme is available." 385 | (interactive) 386 | (autothemer--current-theme-guard) 387 | (let* ((regexp (or regexp 388 | (completing-read 389 | "(Match un-themed face set) Regexp: " 390 | (autothemer--unthemed-faces)))) 391 | (missing-faces 392 | (if (null regexp) 393 | (autothemer--unthemed-faces) 394 | (--filter 395 | (string-match-p regexp (symbol-name it)) 396 | (autothemer--unthemed-faces)))) 397 | (templates (--reduce 398 | (format "%s%s" acc it) 399 | (--map 400 | (format "%s\n" 401 | (replace-regexp-in-string 402 | "\n" "" 403 | (pp-to-string 404 | (autothemer--approximate-spec 405 | (autothemer--alist-to-reduced-spec 406 | it (autothemer--face-to-alist it)) 407 | autothemer-current-theme)))) 408 | missing-faces)))) 409 | (insert templates))) 410 | 411 | ;;;###autoload 412 | (defun autothemer-generate-templates-filtered (regexp) 413 | "Autogenerate customizations for unthemed faces matching REGEXP. 414 | 415 | Calls `autothemer-generate-templates' after user provides REGEXP interactively." 416 | (interactive "sGenerate face templates matching regexp: ") 417 | (autothemer-generate-templates regexp)) 418 | 419 | ;;;###autoload 420 | (defun autothemer-generate-templates (&optional regexp) 421 | "Autogenerate customizations for unthemed faces (optionally by REGEXP). 422 | 423 | Generate customizations that approximate current face definitions using the 424 | nearest colors in the color palette of `autothemer-current-theme'. 425 | 426 | An error is shown when no current theme is available." 427 | (interactive) 428 | (unless autothemer-current-theme 429 | (user-error "No autothemer-current-theme available. Please evaluate an autothemer-deftheme")) 430 | (let* ((missing-faces 431 | (if (null regexp) 432 | (autothemer--unthemed-faces) 433 | (--filter 434 | (string-match-p 435 | regexp 436 | (symbol-name it)) 437 | (autothemer--unthemed-faces)))) 438 | (templates 439 | (--map (autothemer--approximate-spec 440 | (autothemer--alist-to-reduced-spec 441 | it (autothemer--face-to-alist it)) 442 | autothemer-current-theme) 443 | missing-faces)) 444 | (buffer 445 | (get-buffer-create 446 | (generate-new-buffer-name "*Autothemer: unthemed faces*")))) 447 | (with-current-buffer buffer (emacs-lisp-mode) (insert (pp templates))) 448 | (switch-to-buffer buffer))) 449 | 450 | (cl-defsubst autothemer--append-column (lists new-column) 451 | "If LISTS is nil, return NEW-COLUMN. 452 | Otherwise, append NEW-COLUMN to every element of LISTS." 453 | (cl-assert (or (not lists) (eq (length lists) (length new-column)))) 454 | (if lists (inline (-zip-with #'append lists new-column)) 455 | new-column)) 456 | 457 | (defun autothemer--current-theme-guard () 458 | "Guard functions from executing when there's no current theme." 459 | (unless autothemer-current-theme 460 | (user-error "No current theme available. Evaluate an autotheme definition"))) 461 | 462 | ;;; Get colors from theme palette 463 | 464 | (defun autothemer--get-color (color-name) 465 | "Return color palette object for (string) COLOR-NAME. 466 | 467 | Search the `autothemer-current-theme' color palette for COLOR-NAME 468 | and returns a color in the form of `autothemer--color' struct. 469 | 470 | See also `autothemer--color-p', 471 | `autothemer--color-name', 472 | `autothemer--color-value'." 473 | (autothemer--current-theme-guard) 474 | (--find 475 | (eql (intern color-name) 476 | (autothemer--color-name it)) 477 | (autothemer--theme-colors autothemer-current-theme))) 478 | 479 | (defun autothemer--select-color (&optional prompt) 480 | "Select a color from the current palette, optionally use PROMPT. 481 | Current palette is read from `autothemer-current-theme'. 482 | 483 | The selected color will be in the form of a `autothemer--color' 484 | 485 | See also `autothemer--color-p', 486 | `autothemer--color-name', 487 | `autothemer--color-value'." 488 | (autothemer--current-theme-guard) 489 | (let* 490 | ((selected 491 | (completing-read (if (null prompt) 492 | "Select a color: " 493 | prompt) 494 | (mapcar #'(lambda (it) 495 | (let ((color (autothemer--color-value it)) 496 | (name (autothemer--color-name it))) 497 | (format 498 | "%s %s %-45s" 499 | (propertize " " 500 | 'face (list ':background color 501 | ':foreground (readable-foreground-color color))) 502 | (propertize color 503 | 'face (list ':background color 504 | ':foreground (readable-foreground-color color))) 505 | name))) 506 | (autothemer--theme-colors autothemer-current-theme)))) 507 | (color-name (cadr (split-string selected " " t " ")))) 508 | (autothemer--get-color color-name))) 509 | 510 | (defun autothemer-insert-color () 511 | "Select and insert a color from the current autotheme palette." 512 | (interactive) 513 | (autothemer--current-theme-guard) 514 | (let ((color (autothemer--color-value 515 | (autothemer--select-color "Insert a color: ")))) 516 | (insert color))) 517 | 518 | (defun autothemer-insert-color-name () 519 | "Select and insert a color name from the current autotheme palette." 520 | (interactive) 521 | (autothemer--current-theme-guard) 522 | (let ((color-name (autothemer--color-name 523 | (autothemer--select-color "Insert a color name: ")))) 524 | (insert (format"%s" color-name)))) 525 | 526 | ;;; Helper Functions 527 | 528 | (defmacro autothemer--plist-bind (args plist &rest body) 529 | "Evaluate BODY with using ARGS to access PLIST values. 530 | 531 | For example: 532 | 533 | (autothemer--plist-bind (a b c) '(:a 1 :b 2 :c 3) (list a b)) 534 | => '(1 2) 535 | 536 | If PLIST is nil, ARGS are bound to BODY nil values." 537 | `(if (listp ,plist) 538 | (cl-destructuring-bind (&key ,@args &allow-other-keys) ,plist ,@body) 539 | (let (,@args) ,@body))) 540 | 541 | (defun autothemer--unindent (s) 542 | "Unindent string S marked with | chars." 543 | (replace-regexp-in-string "^ *|" "" s)) 544 | 545 | ;;; let palette... 546 | (defmacro autothemer-let-palette (&rest body) 547 | "Provide a let block for BODY from `autothemer-current-theme'. 548 | 549 | Load/eval the required autothemer theme source (not 550 | byte-compiled) to set `autothemer-current-theme'." 551 | (autothemer--current-theme-guard) 552 | `(let ,(--map (list (autothemer--color-name it) (autothemer--color-value it)) 553 | (autothemer--theme-colors autothemer-current-theme)) 554 | ,@body)) 555 | 556 | ;;; Colorize alist for rainbow-mode 557 | (defun autothemer--colorize-alist () 558 | "Generate an alist for use with rainbow-mode. 559 | 560 | To colorize use: 561 | 562 | (rainbow-colorize-by-assoc (autothemer--colorize-alist)) 563 | 564 | Colors are from `autothemer-current-theme'." 565 | (autothemer--current-theme-guard) 566 | (--map (cons (format "%s" (autothemer--color-name it)) 567 | (autothemer--color-value it)) 568 | (autothemer--theme-colors autothemer-current-theme))) 569 | 570 | (defvar autothemer--colors-font-lock-keywords nil) 571 | 572 | (defun autothemer-colorize () 573 | "In the current buffer, colorize palette names, from the last evaluated theme." 574 | (interactive) 575 | (setq autothemer--colors-font-lock-keywords 576 | `((,(regexp-opt (mapcar 'car (autothemer--colorize-alist)) 'words) 577 | (0 (rainbow-colorize-by-assoc (autothemer--colorize-alist)))))) 578 | (font-lock-add-keywords nil autothemer--colors-font-lock-keywords t)) 579 | 580 | ;;; Color conversion 581 | 582 | (defun autothemer--color-to-hsv (rgb) 583 | "Convert RGB, a list of `(r g b)' to list `(h s v)'. 584 | The `r' `g' `b' values can range between `0..65535'. 585 | 586 | In `(h s v)' `h', `s' and `v' are `0.0..1.0'." 587 | (cl-destructuring-bind 588 | (r g b) (--map (/ it 65535.0) rgb) 589 | (let* 590 | ((bri (max r g b)) 591 | (delta (- bri (min r g b))) 592 | (sat (if (cl-plusp bri) 593 | (/ delta bri) 594 | 0.0)) 595 | (normalize #'(lambda 596 | (constant right left) 597 | (let ((hue (+ constant (/ (* 60.0 (- right left)) delta)))) 598 | (if (cl-minusp hue) 599 | (+ hue 360.0) 600 | hue))))) 601 | (list (/ (cond 602 | ((zerop sat) 0.0) 603 | ((= r bri) (funcall normalize 0.0 g b)) ; dominant r 604 | ((= g bri) (funcall normalize 120.0 b r)) ; dominant g 605 | (t (funcall normalize 240.0 r g))) ; dominant b 606 | 360.0) 607 | sat 608 | bri)))) 609 | 610 | (defun autothemer-hex-to-rgb (hex) 611 | "Convert HEX to `(r g b)'. 612 | `r', `g', `b' will be values `0..65535'" 613 | (let* ((hex (cond ((stringp hex) hex) 614 | ((autothemer--color-p hex) (autothemer--color-value hex)))) 615 | (rgb (string-to-number (substring hex 1) 16))) 616 | (list 617 | (* #x101 (ash (logand #xFF0000 rgb) -16)) 618 | (* #x101 (ash (logand #xFF00 rgb) -8)) 619 | (* #x101 (logand #xFF rgb))))) 620 | 621 | (defun autothemer-hex-to-srgb (hex) 622 | "Convert HEX to `(r g b)'. 623 | `r', `g', `b' will be values `0.0..1.0'" 624 | (let* ((hex (cond ((stringp hex) hex) 625 | ((autothemer--color-p hex) (autothemer--color-value hex)))) 626 | (rgb (string-to-number (substring hex 1) 16))) 627 | (list 628 | (/ (ash (logand #xFF0000 rgb) -16) 255.0) 629 | (/ (ash (logand #xFF00 rgb) -8) 255.0) 630 | (/ (logand #xFF rgb) 255.0)))) 631 | 632 | (defun autothemer-rgb-to-hex (rgb) 633 | "0..65535 based RGB to hex string." 634 | (eval `(format "#%02X%02X%02X" ,@(mapcar (lambda (it) (round (* 255 (/ it 65535.0)))) rgb)))) 635 | 636 | (defun autothemer-color-hue (color) 637 | "Return the HSV hue of COLOR (hex color or autothemer--color struct)." 638 | (car (autothemer--color-to-hsv (autothemer-hex-to-rgb color)))) 639 | 640 | (defun autothemer-color-sat (color) 641 | "Return the HSV saturation of COLOR (hex color or autothemer--color struct)." 642 | (cadr (autothemer--color-to-hsv (autothemer-hex-to-rgb color)))) 643 | 644 | (defun autothemer-color-brightness (color) 645 | "Return the HSV brightness of COLOR (hex color or autothemer--color struct)." 646 | (caddr (autothemer--color-to-hsv (autothemer-hex-to-rgb color)))) 647 | 648 | ;;; Sort/Order of autothemer--color structs. 649 | 650 | (defun autothemer-darkest-order (a b) 651 | "Return t if the darkness of A > B." 652 | (let ((a (autothemer-color-brightness (autothemer--color-value a))) 653 | (b (autothemer-color-brightness (autothemer--color-value b)))) 654 | (> b a))) 655 | 656 | (defun autothemer-lightest-order (a b) 657 | "Return t if the lightness of A > B." 658 | (let ((a (autothemer-color-brightness (autothemer--color-value a))) 659 | (b (autothemer-color-brightness (autothemer--color-value b)))) 660 | (> a b))) 661 | 662 | (defun autothemer-saturated-order (a b) 663 | "Return t if the saturation of A > B." 664 | (let ((a (autothemer-color-sat (autothemer--color-value a))) 665 | (b (autothemer-color-sat (autothemer--color-value b)))) 666 | (> a b))) 667 | 668 | (defun autothemer-desaturated-order (a b) 669 | "Return t if the saturation of A < B." 670 | (let ((a (autothemer-color-sat (autothemer--color-value a))) 671 | (b (autothemer-color-sat (autothemer--color-value b)))) 672 | (< a b))) 673 | 674 | (defun autothemer-hue-order (a b) 675 | "Return t if the hue of A > B." 676 | (let ((a (autothemer-color-hue (autothemer--color-value a))) 677 | (b (autothemer-color-hue (autothemer--color-value b)))) 678 | (> a b))) 679 | 680 | (defun autothemer-sort-palette (theme-colors &optional sort-fn group-fn group-args) 681 | "Produce a list of sorted THEME-COLORS using SORT-FN. 682 | If SORT-FN is nil, sort by default `autothemer-darkest-order'. 683 | Grouping is supported via GROUP-FN & GROUP-ARGS. 684 | 685 | See `autothemer-group-and-sort' for a full list." 686 | (let ((sort-fn (or sort-fn 'autothemer-darkest-order)) 687 | (sorted (-sort sort-fn theme-colors))) 688 | sorted)) 689 | 690 | ;; Color Grouping 691 | 692 | (defun autothemer-color-to-group (color fn groups) 693 | "Group COLOR using FN, in GROUPS." 694 | (let ((value (funcall fn color))) 695 | (-reduce-from 696 | (lambda (acc range) 697 | (let ((a (car (cadr range))) 698 | (b (cdr (cadr range)))) 699 | (if (<= a value b) 700 | (car range) 701 | acc))) 702 | nil 703 | groups))) 704 | 705 | (defun autothemer-saturation-grouping (color &optional saturation-groups) 706 | "Return the saturation group of COLOR. 707 | Functionally identical to `autothemer-hue-groups' for saturation. 708 | Optionally provide a list of SATURATION-GROUPS. 709 | The default is `autothemer-20-percent-saturation-groups'." 710 | (autothemer-color-to-group 711 | color 712 | 'autothemer-color-sat 713 | (or saturation-groups autothemer-20-percent-saturation-groups))) 714 | 715 | (defun autothemer-brightness-grouping (color &optional brightness-groups) 716 | "Return the brightness group of COLOR. 717 | Functionally identical to `autothemer-hue-groups' for brightness. 718 | Optionally provide a list of BRIGHTNESS-GROUPS. 719 | The default is `autothemer-20-percent-brightness-groups'." 720 | (autothemer-color-to-group 721 | color 722 | 'autothemer-color-brightness 723 | (or brightness-groups autothemer-20-percent-brightness-groups))) 724 | 725 | (defun autothemer-hue-grouping (color &optional hue-groups) 726 | "Return the color hue group for COLOR. 727 | 728 | Optionally provide a list of HUE-GROUPS. 729 | \(default uses `autothemer-hue-groups'.) 730 | Also available is `autothemer-simple-hue-groups', 731 | both are customizable, or define your own. 732 | 733 | This facilitates hue grouping & sorting by a secondary axis. 734 | For example sort a list of colors by some axis (brightness or 735 | saturation). Then group by hue groups, and sort the groups. 736 | The format of each group in the list is: 737 | 738 | (group-name (n1 . n2)) 739 | 740 | Where `group-name' is a symbol to name the group, 741 | `(n1 . n2)' is a hue range specifier (in degrees) 742 | low `n1' to high `n2'. 743 | 744 | A hue range which crosses the apex (i.e. `360°..0°') is permitted." 745 | (let* ((init-hue-groups (or (and (listp hue-groups) hue-groups) 746 | (and (listp (symbol-value hue-groups)) 747 | (symbol-value hue-groups)) 748 | autothemer-hue-groups)) 749 | (hue-groups (-reduce-from 750 | (lambda (acc range) 751 | (let* ((a (car (cadr range))) 752 | (b (cdr (cadr range))) 753 | (r (if (> a b) ;; hue apex check 360..0 754 | `(,(list (car range) (cons a 360)) 755 | ,(list (car range) (cons 0 b))) 756 | `(,range)))) 757 | (if acc 758 | (cl-concatenate 'list acc r) 759 | r))) 760 | nil 761 | init-hue-groups)) 762 | (hue (autothemer-color-hue color))) 763 | (-reduce-from 764 | (lambda (acc range) 765 | (let ((a (car (cadr range))) 766 | (b (cdr (cadr range)))) 767 | (if (<= a (* hue 360) b) 768 | (car range) 769 | acc))) 770 | nil 771 | hue-groups))) 772 | 773 | ;;; Group and sort 774 | 775 | (defun autothemer-group-sort (groups sort-fn) 776 | "Sort GROUPS of colors using SORT-FN. 777 | GROUPS are produced by `autothemer-group-colors'." 778 | (mapcar 779 | (lambda (group) 780 | "Groups are alists with car as key, cdr as colors." 781 | (let* ((name (car group)) 782 | (colors (cdr group)) 783 | (sorted-colors (--sort 784 | (funcall sort-fn it other) 785 | colors))) 786 | (cons name sorted-colors))) 787 | groups)) 788 | 789 | (defun autothemer-group-colors (palette options) 790 | "Group PALETTE colors into groups as defined in plist OPTIONS: 791 | `:group-fn' - mandatory group function 792 | `:group-args' - args for `group-fn'" 793 | (autothemer--plist-bind (group-fn group-args) options 794 | (let* ((group-keys (mapcar 'car group-args)) 795 | (colors-with-groups (mapcar (lambda (color) 796 | (list (funcall group-fn (autothemer--color-value color) 797 | group-args) 798 | color)) 799 | palette)) 800 | (grouped-colors (mapcar (lambda (group) (--reduce (-flatten (cons acc (cdr it))) group)) 801 | (-group-by 'car colors-with-groups))) 802 | (grouped-colors (-filter 'car (mapcar (lambda (group) (assoc group grouped-colors)) group-keys)))) 803 | grouped-colors))) 804 | 805 | (defun autothemer-group-and-sort (palette options) 806 | "Group and sort PALETTE using OPTIONS. 807 | 808 | Options is a plist of: 809 | 810 | #TABLE Option - Description # 811 | :group-fn - mandatory group function 812 | :group-args - optional group args (to use a non-default group) 813 | :sort-fn - optional sort function 814 | #TABLE# 815 | 816 | See color grouping functions and group lists: 817 | 818 | Hue grouping: 819 | 820 | #TABLE Function - Description # 821 | autothemer-hue-grouping - color hue group for COLOR 822 | #TABLE# 823 | 824 | #TABLE Hue Groups - Description # 825 | autothemer-hue-groups - group colors into major hue groups (default) 826 | autothemer-simple-hue-groups - group colors into broad hue groups 827 | #TABLE# 828 | 829 | Brightness grouping: 830 | 831 | #TABLE Function - Description # 832 | autothemer-brightness-grouping - brightness group for COLOR 833 | #TABLE# 834 | 835 | #TABLE Brightness Groups - Description # 836 | autothemer-dark-mid-light-brightness-groups - 3 brightness groups 837 | autothemer-10-percent-brightness-groups - 10 brightness groups 838 | autothemer-20-percent-brightness-groups - 5 brightness groups (default) 839 | #TABLE# 840 | 841 | Saturation grouping: 842 | 843 | #TABLE Function - Description # 844 | autothemer-saturation-grouping - saturation group for COLOR 845 | #TABLE# 846 | 847 | #TABLE Saturation Groups - Description # 848 | autothemer-low-mid-high-saturation-groups - 3 saturation groups 849 | autothemer-10-percent-saturation-groups - 10 saturation groups 850 | autothemer-20-percent-saturation-groups - 5 saturation groups (default) 851 | #TABLE# 852 | - - - 853 | 854 | Sorting: 855 | 856 | The sort/ordering functions take args A and B, which are expected 857 | to be `autothemer--color' structs. 858 | 859 | #TABLE Sort Functions - Description# 860 | autothemer-darkest-order - darkest to lightest 861 | autothemer-lightest-order - lightest to darkest 862 | autothemer-hue-order - sort by hue 863 | autothemer-saturated-order - sort by most saturated to least 864 | autothemer-desaturated-order - sort by least saturated to most 865 | #TABLE#" 866 | (autothemer--plist-bind 867 | (group-fn 868 | group-args 869 | sort-fn) 870 | options 871 | (let* ((grouped-colors (autothemer-group-colors palette (list :group-fn (eval group-fn) :group-args (eval group-args)))) 872 | (sorted-groups (autothemer-group-sort grouped-colors (eval sort-fn)))) 873 | sorted-groups))) 874 | 875 | (defun autothemer-groups-to-palette (grouped-palette) 876 | "Flatten a GROUPED-PALETTE from `autothemer-group-and-sort' to a single list." 877 | (-flatten (--map (cdr it) grouped-palette))) 878 | 879 | ;;; SVG Palette generator... 880 | 881 | (defun autothemer-generate-palette-svg (&optional options) 882 | "Create an SVG palette image for a theme. 883 | 884 | Optional parameter `options` (a plist). Any required values not 885 | supplied in OPTIONS will use defaults or prompt interactively. 886 | 887 | #TABLE Option - Description # 888 | :theme-file - theme filename 889 | :theme-name - override the title found in :theme-file 890 | :theme-description - override the description found in :theme-file 891 | :theme-url - override the url found in :theme-file 892 | :font-family - font name to use in the generated SVG 893 | :columns - number of columns for each palette row (default: 6) 894 | :bg-color - Page background color 895 | :text-color - Main text color 896 | :text-accent-color - Text accent color 897 | :page-template - see page-template below 898 | :page-top-margin - (default: 120) 899 | :page-right-margin - (default: 30) 900 | :page-bottom-margin - (default: 60) 901 | :page-left-margin - (default: 30) 902 | :swatch-template - see swatch-template below 903 | :swatch-border-color - the border color of a color swatch 904 | :swatch-width - px spacing width of a color swatch (default: 100) 905 | :swatch-height - px spacing height of a color swatch (default: 150) 906 | :swatch-rotate - degrees of rotation for swatch (default: 45) 907 | :h-space - horizontal-space between swatches (default: 10) 908 | :v-space - vertical-space between swatches (default: 10) 909 | :sort-palette - arrange palette using a function name 910 | :visually-group-swatches - boolean (default: nil) 911 | :svg-out-file - the file/pathname to save SVG output 912 | #TABLE# 913 | 914 | For advanced customization the :page-template and :swatch-template can be 915 | used to provide customize the SVG templates. 916 | 917 | Note: Template parameters are filled by `format' so we mark them as follows: 918 | 919 | Page Template parameters: 920 | 921 | #TABLE Parameter - Description# 922 | %1$s - width 923 | %2$s - height 924 | %3$s - font-family 925 | %4$s - text-color 926 | %5$s - text-accent-color 927 | %6$s - bg-color 928 | %7$s - theme-name 929 | %8$s - theme-description 930 | %9$s - theme-url 931 | %10$s - color swatches 932 | #TABLE# 933 | 934 | Swatch Template parameters: 935 | 936 | #TABLE Parameter - Description# 937 | %1$s - x 938 | %2$s - y 939 | %3$s - swatch-border-color 940 | %4$s - swatch-color 941 | %5$s - text-accent-color 942 | %6$s - swatch-color-name 943 | #TABLE#" 944 | (interactive) 945 | (autothemer--plist-bind 946 | (theme-file 947 | theme-name 948 | theme-description 949 | theme-url 950 | font-family 951 | columns 952 | bg-color 953 | text-color 954 | text-accent-color 955 | page-template 956 | page-top-margin 957 | page-right-margin 958 | page-bottom-margin 959 | page-left-margin 960 | swatch-template 961 | swatch-border-color 962 | swatch-width 963 | swatch-height 964 | swatch-rotate 965 | h-space 966 | v-space 967 | sort-palette 968 | visually-group-swatches 969 | svg-out-file) 970 | options 971 | (let ((theme-file (or theme-file (read-file-name "Select autothemer theme .el file: ")))) 972 | (load-file theme-file) ;; make it the current-theme 973 | (let* ((page-template 974 | (or page-template 975 | (autothemer--unindent "<?xml version=\"1.0\" standalone=\"no\"?> 976 | |<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" 977 | |\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> 978 | |<svg width=\"%1$spx\" height=\"%2$spx\" 979 | | version=\"1.1\" 980 | | xmlns=\"http://www.w3.org/2000/svg\" 981 | | xmlns:xlink=\"http://www.w3.org/1999/xlink\"> 982 | | <style> 983 | | text { 984 | | font-family: \"%3$s\"; 985 | | fill: %4$s; 986 | | } 987 | | </style> 988 | | <rect x=\"0\" y=\"0\" rx=\"10\" width=\"%1$spx\" height=\"%2$spx\" id=\"background-panel\" fill=\"%6$s\"/> 989 | | <g transform=\"translate(14,10)\"> 990 | | <a xlink:href=\"%9$s\"> 991 | | <text style=\"font-size:42pt;\" font-weight=\"bold\" x=\"3%%\" y=\"50\" id=\"theme-name\">%7$s</text> 992 | | <text style=\"font-size:12pt;\" x=\"4%%\" y=\"75\" id=\"theme-description\">%8$s</text> 993 | | <text style=\"font-size:8pt;fill: %5$s\" text-anchor=\"end\" x=\"95%%\" y=\"20\" id=\"theme-url\">%9$s</text> 994 | | </a> 995 | | </g> 996 | | <g transform=\"translate(70,-40)\"> 997 | | %10$s 998 | | </g> 999 | |</svg> 1000 | |"))) 1001 | 1002 | (swatch-template 1003 | (or swatch-template 1004 | (autothemer--unindent "<g transform=\"translate(%1$s,%2$s),rotate(%9$s)\"> 1005 | | <ellipse cx=\"70\" cy=\"70\" rx=\"45\" ry=\"45\" id=\"background-color\" fill=\"%3$s\"/> 1006 | | <ellipse cx=\"70\" cy=\"70\" rx=\"42\" ry=\"42\" id=\"color\" fill=\"%4$s\"/> 1007 | | <text style=\"font-size:7pt\" font-weight=\"bold\" x=\"52\" y=\"125\" id=\"color-name\">%6$s</text> 1008 | | <text style=\"font-size:7pt; fill:%5$s;\" font-weight=\"bold\" x=\"52\" y=\"134\" id=\"color\">%4$s</text> 1009 | | <!-- Rect below is for debug set stroke width to be visible --> 1010 | | <rect x=\"0\" y=\"0\" width=\"%7$spx\" height=\"%8$spx\" class=\"debug-rect\" fill-opacity=\"0.0\" stroke-width=\"0.0mm\" stroke=\"#FF8000\"/> 1011 | |</g> 1012 | |"))) 1013 | 1014 | (autotheme-name (autothemer--theme-name autothemer-current-theme)) 1015 | (colors (autothemer--theme-colors autothemer-current-theme)) 1016 | (theme-name (or theme-name (autothemer--theme-name autothemer-current-theme))) 1017 | (theme-description (or theme-description (autothemer--theme-description autothemer-current-theme))) 1018 | (theme-url (or theme-url (lm-homepage theme-file) (read-string "Enter theme URL: " "https://github.com/"))) 1019 | 1020 | (font-family (or font-family (read-string "Font family name: " "Helvetica Neue"))) 1021 | (swatch-width (or swatch-width (read-number "Swatch width: " 100))) 1022 | (swatch-height (or swatch-height (read-number "Swatch height: " 150))) 1023 | (swatch-rotate (or swatch-rotate (read-number "Swatch rotate: " 45))) 1024 | (columns (or columns (read-number "Number or columns: " 6))) 1025 | (page-top-margin (or page-top-margin (read-number "Page Top margin: " 120))) 1026 | (page-bottom-margin (or page-bottom-margin (read-number "Page Bottom margin: " 60))) 1027 | (page-left-margin (or page-left-margin (read-number "Page Left margin: " 30))) 1028 | (page-right-margin (or page-right-margin (read-number "Page Right margin: " 30))) 1029 | (h-space (or h-space (read-number "Swatch horiztonal spacing: " 10))) 1030 | (v-space (or v-space (read-number "Swatch vertical spacing: " 10))) 1031 | 1032 | (rows (/ (length colors) columns)) 1033 | (width (+ page-right-margin page-left-margin 1034 | (* h-space columns) 1035 | (* swatch-width columns))) 1036 | (height (+ page-top-margin page-bottom-margin 1037 | (* v-space rows) 1038 | (* swatch-height (+ 1 rows)))) 1039 | 1040 | (background-color (or bg-color (autothemer--color-value (autothemer--select-color "Select Background color: ")))) 1041 | (text-color (or text-color (autothemer--color-value (autothemer--select-color "Select Text color: ")))) 1042 | (text-accent-color (or text-accent-color (autothemer--color-value (autothemer--select-color "Select Text accent color: ")))) 1043 | (swatch-border-color (or swatch-border-color (autothemer--color-value (autothemer--select-color "Select swatch border color: ")))) 1044 | (sort-palette (or sort-palette 1045 | (list 1046 | :sort-fn (read--expression "Sort function (TAB completion, enter nil to skip): " "'autothemer-") 1047 | :group-fn (read--expression "Group function (TAB completion, enter nil to skip): " "'autothemer-") 1048 | :group-args (read--expression "Group list (TAB completion, enter nil to skip): " "autothemer-")))) 1049 | (visually-group-swatches (or visually-group-swatches (y-or-n-p "Visually group swatches?"))) 1050 | (svg-out-file (or svg-out-file (read-file-name (format "Enter a Filename to save SVG palette for %s." theme-name)))) 1051 | 1052 | ;(svg-grouped-swatches ()) 1053 | (svg-swatches (string-join 1054 | (-map-indexed 1055 | (lambda (index it) 1056 | (let ((color (autothemer--color-value it)) 1057 | (name (upcase (replace-regexp-in-string 1058 | (concat autotheme-name "-") "" 1059 | (format "%s" (autothemer--color-name it))))) 1060 | (x (+ page-left-margin (* (+ h-space swatch-width) (% index columns)))) 1061 | (y (+ page-top-margin (* (+ v-space swatch-height) (/ index columns))))) 1062 | (format swatch-template 1063 | x 1064 | y 1065 | swatch-border-color 1066 | color 1067 | text-accent-color 1068 | name swatch-width swatch-height swatch-rotate))) 1069 | (if sort-palette 1070 | (autothemer-groups-to-palette 1071 | (autothemer-group-and-sort colors sort-palette)) 1072 | colors)) 1073 | "\n"))) 1074 | (with-temp-file svg-out-file 1075 | (insert 1076 | (format page-template 1077 | width 1078 | height 1079 | font-family 1080 | text-color 1081 | text-accent-color 1082 | background-color 1083 | theme-name 1084 | theme-description 1085 | theme-url 1086 | svg-swatches))) 1087 | (message "%s generated." svg-out-file))))) 1088 | 1089 | (defun autothemer--locate-source () 1090 | "Return the absolute file path of autothemer source. 1091 | 1092 | Return nil if not found." 1093 | (let* ((lib-file-name "autothemer.el") 1094 | (located-file (file-truename (locate-library "autothemer"))) 1095 | (is-byte-compiled (string= "elc" (file-name-extension located-file))) 1096 | (el-name (format "%s.el" (file-name-sans-extension located-file))) 1097 | (located-el (file-truename (if (and is-byte-compiled (file-exists-p el-name)) 1098 | el-name 1099 | located-file))) 1100 | (located-folder (file-name-directory located-el))) 1101 | (if (file-directory-p located-folder) 1102 | located-folder 1103 | nil))) 1104 | 1105 | (provide 'autothemer) 1106 | ;;; autothemer.el ends here 1107 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # For CI / Github Actions 3 | 4 | EMACS="${EMACS:=emacs}" 5 | 6 | NEEDED_PACKAGES="dash" 7 | 8 | INIT_PACKAGE_EL="(progn \ 9 | (require 'package) \ 10 | (push '(\"melpa\" . \"https://melpa.org/packages/\") package-archives) \ 11 | (package-initialize) \ 12 | (unless package-archive-contents \ 13 | (package-refresh-contents)) \ 14 | (dolist (pkg '(${NEEDED_PACKAGES})) \ 15 | (unless (package-installed-p pkg) \ 16 | (package-install pkg))))" 17 | 18 | # Refresh package archives, because the test suite needs to see at least 19 | # package-lint and cl-lib. 20 | "$EMACS" -batch \ 21 | --eval "$INIT_PACKAGE_EL" 22 | -------------------------------------------------------------------------------- /bin/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | dash="$(dirname "$(find ~/.emacs.d | grep "/dash.el$" | tail -1)")" 3 | 4 | EMACS="${EMACS:=emacs}" 5 | 6 | cat <<INFO 7 | ════════════════════════════════════════════════════════════════════════════════ 8 | _ _ _____ _ 9 | / \ _ _| |_ __|_ _| |__ ___ _ __ ___ ___ _ __ 10 | / _ \| | | | __/ _ \| | | '_ \ / _ \ '_ ' _ \ / _ \ '__| 11 | / ___ \ |_| | || (_) | | | | | | __/ | | | | | __/ | 12 | /_/ \_\__,_|\__\___/|_| |_| |_|\___|_| |_| |_|\___|_| 13 | _____ _ 14 | |_ _|__ ___| |_ ___ 15 | | |/ _ \/ __| __/ __| 16 | | | __/\__ \ |_\__ \\ 17 | |_|\___||___/\__|___/ 18 | 19 | ──────────────────────────────────────────────────────────────────────────────── 20 | Required packages present: 21 | Dash: $dash 22 | ════════════════════════════════════════════════════════════════════════════════ 23 | $("$EMACS" --version) 24 | ════════════════════════════════════════════════════════════════════════════════ 25 | INFO 26 | 27 | "$EMACS" --batch \ 28 | -eval "(setq load-prefer-newer t)" \ 29 | -eval "(add-to-list 'load-path \"${dash}\")" \ 30 | -eval "(add-to-list 'load-path \".\")" \ 31 | -l ert \ 32 | -l dash \ 33 | -l autothemer.el \ 34 | -l tests/autothemer-tests.el \ 35 | -f ert-run-tests-batch-and-exit 36 | exitcode=$? 37 | 38 | echo " 39 | ════════════════════════════════════════════════════════════════════════════════" 40 | exit ${exitcode} 41 | -------------------------------------------------------------------------------- /function-reference.md: -------------------------------------------------------------------------------- 1 | # Autothemer 2 | 3 | Reduce the amount of pain and boilerplate code needed to create custom themes using `autothemer-deftheme`. 4 | 5 | Autothemer also includes interactive commands and functions to 6 | assist with theme building, here are a few highlights... 7 | 8 | - Generate specs for unthemed faces using the theme color palette. 9 | - `autothemer-generate-templates` 10 | - `autothemer-generate-templates-filtered` (filter by regexp) 11 | - Generate a palette SVG image 12 | - `autothemer-generate-palette-svg` 13 | - Insert a color name or color from the active palette 14 | - `autothemer-insert-color-name` 15 | - `autothemer-insert-color` 16 | - Colorize/font-lock palette color names in the buffer 17 | - `autothemer-colorize` (requires `rainbow-mode` during development.) 18 | 19 | - - - 20 | # Function reference 21 | 22 | ### Commands 23 | - [autothemer-colorize](#autothemer-colorize-) 24 | - [autothemer-generate-palette-svg](#autothemer-generate-palette-svg---options) 25 | - [autothemer-generate-templates](#autothemer-generate-templates---regexp) 26 | - [autothemer-generate-templates-filtered](#autothemer-generate-templates-filtered--regexp) 27 | - [autothemer-insert-color](#autothemer-insert-color-) 28 | - [autothemer-insert-color-name](#autothemer-insert-color-name-) 29 | ### User Functions 30 | - [autothemer-brightness-group](#autothemer-brightness-group--color--brightness-groups) 31 | - [autothemer-color-brightness](#autothemer-color-brightness--color) 32 | - [autothemer-color-hue](#autothemer-color-hue--color) 33 | - [autothemer-color-sat](#autothemer-color-sat--color) 34 | - [autothemer-color-to-group](#autothemer-color-to-group--color-fn-groups) 35 | - [autothemer-darkest-order](#autothemer-darkest-order--a-b) 36 | - [autothemer-desaturated-order](#autothemer-desaturated-order--a-b) 37 | - [autothemer-group-and-sort](#autothemer-group-and-sort--palette-options) 38 | - [autothemer-group-colors](#autothemer-group-colors--palette-options) 39 | - [autothemer-group-sort](#autothemer-group-sort--groups-sort-fn) 40 | - [autothemer-groups-to-palette](#autothemer-groups-to-palette--grouped-palette) 41 | - [autothemer-hex-to-rgb](#autothemer-hex-to-rgb--hex) 42 | - [autothemer-hue-group](#autothemer-hue-group--color--hue-groups) 43 | - [autothemer-hue-order](#autothemer-hue-order--a-b) 44 | - [autothemer-lightest-order](#autothemer-lightest-order--a-b) 45 | - [autothemer-saturated-order](#autothemer-saturated-order--a-b) 46 | - [autothemer-saturation-group](#autothemer-saturation-group--color--saturation-groups) 47 | - [autothemer-sort-palette](#autothemer-sort-palette--theme-colors--sort-fn-group-fn-group-args) 48 | - [autothemer-let-palette](#autothemer-let-palette) 49 | ### Internal Functions 50 | - [autothemer--alist-to-reduced-spec](#autothemer--alist-to-reduced-spec--facename-alist) 51 | - [autothemer--approximate-spec](#autothemer--approximate-spec--reduced-spec-theme) 52 | - [autothemer--color-distance](#autothemer--color-distance--color-autothemer-color) 53 | - [autothemer--color-to-hsv](#autothemer--color-to-hsv--rgb) 54 | - [autothemer--colorize-alist](#autothemer--colorize-alist-) 55 | - [autothemer--cons-to-tree](#autothemer--cons-to-tree--the-cons) 56 | - [autothemer--current-theme-guard](#autothemer--current-theme-guard-) 57 | - [autothemer--demote-heads](#autothemer--demote-heads--expr) 58 | - [autothemer--extract-display](#autothemer--extract-display--palette-n) 59 | - [autothemer--extract-let-block](#autothemer--extract-let-block--palette-n) 60 | - [autothemer--face-to-alist](#autothemer--face-to-alist--face) 61 | - [autothemer--fill-empty-palette-slots](#autothemer--fill-empty-palette-slots--palette) 62 | - [autothemer--find-closest-color](#autothemer--find-closest-color--colors-color) 63 | - [autothemer--get-color](#autothemer--get-color--color-name) 64 | - [autothemer--pad-with-nil](#autothemer--pad-with-nil--row-min-number-of-elements) 65 | - [autothemer--reduced-spec-to-facespec](#autothemer--reduced-spec-to-facespec--display-reduced-specs) 66 | - [autothemer--replace-nil-by-precursor](#autothemer--replace-nil-by-precursor--palette-row) 67 | - [autothemer--select-color](#autothemer--select-color---prompt) 68 | - [autothemer--unindent](#autothemer--unindent--s) 69 | - [autothemer--unthemed-faces](#autothemer--unthemed-faces-) 70 | ### <a id="autothemer-colorize-" aria-hidden="true"></a>autothemer-colorize command 71 | 72 | In the current buffer, colorize palette color names, from the last evaluated theme, by their color value. 73 | 74 | <sup>function signature</sup> 75 | ```lisp 76 | (autothemer-colorize) 77 | ``` 78 | 79 | - - - 80 | 81 | ### <a id="autothemer-generate-palette-svg---options" aria-hidden="true"></a>autothemer-generate-palette-svg command 82 | 83 | Create an SVG palette image for a theme. 84 | 85 | Optional parameter `options` (a plist). Any required values not 86 | supplied in `options` will use defaults or prompt interactively. 87 | 88 | | Option | Description | 89 | |------------------------|-----------------------------------------------------| 90 | | `:theme-file` | theme filename | 91 | | `:theme-name` | override the title found in :theme-file | 92 | | `:theme-description` | override the description found in :theme-file | 93 | | `:theme-url` | override the url found in :theme-file | 94 | | `:font-family` | font name to use in the generated SVG | 95 | | `:columns` | number of columns for each palette row (default: 6) | 96 | | `:bg-color` | Page background color | 97 | | `:text-color` | Main text color | 98 | | `:text-accent-color` | Text accent color | 99 | | `:page-template` | see page-template below | 100 | | `:page-top-margin` | (default: 120) | 101 | | `:page-right-margin` | (default: 30) | 102 | | `:page-bottom-margin` | (default: 60) | 103 | | `:page-left-margin` | (default: 30) | 104 | | `:swatch-template` | see swatch-template below | 105 | | `:swatch-border-color` | the border color of a color swatch | 106 | | `:swatch-width` | px spacing width of a color swatch (default: 100) | 107 | | `:swatch-height` | px spacing height of a color swatch (default: 150) | 108 | | `:swatch-rotate` | degrees of rotation for swatch (default: 45) | 109 | | `:h-space` | horizontal-space between swatches (default: 10) | 110 | | `:v-space` | vertical-space between swatches (default: 10) | 111 | | `:sort-palette` | arrange palette using a function name | 112 | | `:group-swatches` | boolean | 113 | | `:svg-out-file` | the file/pathname to save SVG output | 114 | 115 | For advanced customization the :page-template and :swatch-template can be 116 | used to provide customize the SVG templates. 117 | 118 | Note: Template parameters are filled by `format` so we mark them as follows: 119 | 120 | Page Template parameters: 121 | 122 | | Parameter | Description | 123 | |-----------|-------------------| 124 | | `%1$s` | width | 125 | | `%2$s` | height | 126 | | `%3$s` | font-family | 127 | | `%4$s` | text-color | 128 | | `%5$s` | text-accent-color | 129 | | `%6$s` | bg-color | 130 | | `%7$s` | theme-name | 131 | | `%8$s` | theme-description | 132 | | `%9$s` | theme-url | 133 | | `%10$s` | color swatches | 134 | 135 | Swatch Template parameters: 136 | 137 | | Parameter | Description | 138 | |-----------|---------------------| 139 | | `%1$s` | x | 140 | | `%2$s` | y | 141 | | `%3$s` | swatch-border-color | 142 | | `%4$s` | swatch-color | 143 | | `%5$s` | text-accent-color | 144 | | `%6$s` | swatch-color-name | 145 | 146 | <sup>function signature</sup> 147 | ```lisp 148 | (autothemer-generate-palette-svg (&optional options)) 149 | ``` 150 | 151 | - - - 152 | 153 | ### <a id="autothemer-generate-templates---regexp" aria-hidden="true"></a>autothemer-generate-templates command 154 | 155 | Autogenerate customizations for unthemed faces (optionally by `regexp`). 156 | 157 | Generate customizations that approximate current face definitions using the 158 | nearest colors in the color palette of `autothemer-current-theme`. 159 | 160 | An error is shown when no current theme is available. 161 | 162 | <sup>function signature</sup> 163 | ```lisp 164 | (autothemer-generate-templates (&optional regexp)) 165 | ``` 166 | 167 | - - - 168 | 169 | ### <a id="autothemer-generate-templates-filtered--regexp" aria-hidden="true"></a>autothemer-generate-templates-filtered command 170 | 171 | Autogenerate customizations for unthemed faces matching `regexp`. 172 | 173 | Calls `autothemer-generate-templates` after user provides `regexp` interactively. 174 | 175 | <sup>function signature</sup> 176 | ```lisp 177 | (autothemer-generate-templates-filtered (regexp)) 178 | ``` 179 | 180 | - - - 181 | 182 | ### <a id="autothemer-insert-color-" aria-hidden="true"></a>autothemer-insert-color command 183 | 184 | Select and insert a color from the current autotheme palette. 185 | 186 | <sup>function signature</sup> 187 | ```lisp 188 | (autothemer-insert-color) 189 | ``` 190 | 191 | - - - 192 | 193 | ### <a id="autothemer-insert-color-name-" aria-hidden="true"></a>autothemer-insert-color-name command 194 | 195 | Select and insert a color name from the current autotheme palette. 196 | 197 | <sup>function signature</sup> 198 | ```lisp 199 | (autothemer-insert-color-name) 200 | ``` 201 | 202 | - - - 203 | 204 | ### <a id="autothemer-brightness-group--color--brightness-groups" aria-hidden="true"></a>autothemer-brightness-group 205 | 206 | Return the brightness group of `color`. 207 | Functionally identical to `autothemer-hue-groups` for brightness. 208 | Optionally provide a list of `brightness-groups`. 209 | The default is `autothemer-20-percent-brightness-groups`. 210 | 211 | <sup>function signature</sup> 212 | ```lisp 213 | (autothemer-brightness-group (color &optional brightness-groups)) 214 | ``` 215 | 216 | - - - 217 | 218 | ### <a id="autothemer-color-brightness--color" aria-hidden="true"></a>autothemer-color-brightness 219 | 220 | Return the HSV brightness of `color` (hex color or autothemer--color struct). 221 | 222 | <sup>function signature</sup> 223 | ```lisp 224 | (autothemer-color-brightness (color)) 225 | ``` 226 | 227 | - - - 228 | 229 | ### <a id="autothemer-color-hue--color" aria-hidden="true"></a>autothemer-color-hue 230 | 231 | Return the HSV hue of `color` (hex color or autothemer--color struct). 232 | 233 | <sup>function signature</sup> 234 | ```lisp 235 | (autothemer-color-hue (color)) 236 | ``` 237 | 238 | - - - 239 | 240 | ### <a id="autothemer-color-sat--color" aria-hidden="true"></a>autothemer-color-sat 241 | 242 | Return the HSV saturation of `color` (hex color or autothemer--color struct). 243 | 244 | <sup>function signature</sup> 245 | ```lisp 246 | (autothemer-color-sat (color)) 247 | ``` 248 | 249 | - - - 250 | 251 | ### <a id="autothemer-color-to-group--color-fn-groups" aria-hidden="true"></a>autothemer-color-to-group 252 | 253 | Group `color` using `fn`, in `groups`. 254 | 255 | <sup>function signature</sup> 256 | ```lisp 257 | (autothemer-color-to-group (color fn groups)) 258 | ``` 259 | 260 | - - - 261 | 262 | ### <a id="autothemer-darkest-order--a-b" aria-hidden="true"></a>autothemer-darkest-order 263 | 264 | Return t if the darkness of `a` > `b`. 265 | 266 | <sup>function signature</sup> 267 | ```lisp 268 | (autothemer-darkest-order (a b)) 269 | ``` 270 | 271 | - - - 272 | 273 | ### <a id="autothemer-desaturated-order--a-b" aria-hidden="true"></a>autothemer-desaturated-order 274 | 275 | Return t if the saturation of `a` < `b`. 276 | 277 | <sup>function signature</sup> 278 | ```lisp 279 | (autothemer-desaturated-order (a b)) 280 | ``` 281 | 282 | - - - 283 | 284 | ### <a id="autothemer-group-and-sort--palette-options" aria-hidden="true"></a>autothemer-group-and-sort 285 | 286 | Group and sort `palette` using `options`. 287 | 288 | Options is a plist of: 289 | 290 | | Option | Description | 291 | |---------------|--------------------------------------------------| 292 | | `:group-fn` | mandatory group function | 293 | | `:group-args` | optional group args (to use a non-default group) | 294 | | `:sort-fn` | optional sort function | 295 | 296 | See color grouping functions and group lists: 297 | 298 | Hue grouping: 299 | 300 | | Function | Description | 301 | |------------------------|---------------------------| 302 | | `autothemer-hue-group` | color hue group for COLOR | 303 | 304 | | Hue Groups | Description | 305 | |--------------------------------|----------------------------------------------| 306 | | `autothemer-hue-groups` | group colors into major hue groups (default) | 307 | | `autothemer-simple-hue-groups` | group colors into broad hue groups | 308 | 309 | Brightness grouping: 310 | 311 | | Function | Description | 312 | |-------------------------------|----------------------------| 313 | | `autothemer-brightness-group` | brightness group for COLOR | 314 | 315 | | Brightness Groups | Description | 316 | |-----------------------------------------------|-------------------------------| 317 | | `autothemer-dark-mid-light-brightness-groups` | 3 brightness groups | 318 | | `autothemer-10-percent-brightness-groups` | 10 brightness groups | 319 | | `autothemer-20-percent-brightness-groups` | 5 brightness groups (default) | 320 | 321 | Saturation grouping: 322 | 323 | | Function | Description | 324 | |-------------------------------|----------------------------| 325 | | `autothemer-saturation-group` | saturation group for COLOR | 326 | 327 | | Saturation Groups | Description | 328 | |---------------------------------------------|-------------------------------| 329 | | `autothemer-low-mid-high-saturation-groups` | 3 saturation groups | 330 | | `autothemer-10-percent-saturation-groups` | 10 saturation groups | 331 | | `autothemer-20-percent-saturation-groups` | 5 saturation groups (default) | 332 | - - - 333 | 334 | Sorting: 335 | 336 | The sort/ordering functions take args A and B, which are expected 337 | to be `autothemer--color` structs. 338 | 339 | | Sort Functions | Description | 340 | |--------------------------------|---------------------------------| 341 | | `autothemer-darkest-order` | darkest to lightest | 342 | | `autothemer-lightest-order` | lightest to darkest | 343 | | `autothemer-hue-order` | sort by hue | 344 | | `autothemer-saturated-order` | sort by most saturated to least | 345 | | `autothemer-desaturated-order` | sort by least saturated to most | 346 | 347 | <sup>function signature</sup> 348 | ```lisp 349 | (autothemer-group-and-sort (palette options)) 350 | ``` 351 | 352 | - - - 353 | 354 | ### <a id="autothemer-group-colors--palette-options" aria-hidden="true"></a>autothemer-group-colors 355 | 356 | Group `palette` colors into groups as defined in plist `options`: 357 | `:group-fn` - mandatory group function 358 | `:group-args` - args for `group-fn` 359 | 360 | <sup>function signature</sup> 361 | ```lisp 362 | (autothemer-group-colors (palette options)) 363 | ``` 364 | 365 | - - - 366 | 367 | ### <a id="autothemer-group-sort--groups-sort-fn" aria-hidden="true"></a>autothemer-group-sort 368 | 369 | Sort `groups` of colors using `sort-fn`. 370 | `groups` are produced by `autothemer-group-colors`. 371 | 372 | <sup>function signature</sup> 373 | ```lisp 374 | (autothemer-group-sort (groups sort-fn)) 375 | ``` 376 | 377 | - - - 378 | 379 | ### <a id="autothemer-groups-to-palette--grouped-palette" aria-hidden="true"></a>autothemer-groups-to-palette 380 | 381 | Flatten a `grouped-palette` from `autothemer-group-and-sort` to a single list. 382 | 383 | <sup>function signature</sup> 384 | ```lisp 385 | (autothemer-groups-to-palette (grouped-palette)) 386 | ``` 387 | 388 | - - - 389 | 390 | ### <a id="autothemer-hex-to-rgb--hex" aria-hidden="true"></a>autothemer-hex-to-rgb 391 | 392 | Convert `hex` to `(r g b)`. 393 | `r`, `g`, `b` will be values `0..65535` 394 | 395 | <sup>function signature</sup> 396 | ```lisp 397 | (autothemer-hex-to-rgb (hex)) 398 | ``` 399 | 400 | - - - 401 | 402 | ### <a id="autothemer-hue-group--color--hue-groups" aria-hidden="true"></a>autothemer-hue-group 403 | 404 | Return the color hue group for `color`. 405 | 406 | Optionally provide a list of `hue-groups`. 407 | (default uses `autothemer-hue-groups`.) 408 | Also available is `autothemer-simple-hue-groups`, 409 | both are customizable, or define your own. 410 | 411 | This facilitates hue grouping & sorting by a secondary axis. 412 | For example sort a list of colors by some axis (brightness or 413 | saturation). Then group by hue groups, and sort the groups. 414 | The format of each group in the list is: 415 | 416 | (group-name (n1 . n2)) 417 | 418 | Where `group-name` is a symbol to name the group, 419 | `(n1 . n2)` is a hue range specifier (in degrees) 420 | low `n1` to high `n2`. 421 | 422 | A hue range which crosses the apex (i.e. `360°..0°`) is permitted. 423 | 424 | <sup>function signature</sup> 425 | ```lisp 426 | (autothemer-hue-group (color &optional hue-groups)) 427 | ``` 428 | 429 | - - - 430 | 431 | ### <a id="autothemer-hue-order--a-b" aria-hidden="true"></a>autothemer-hue-order 432 | 433 | Return t if the hue of `a` > `b`. 434 | 435 | <sup>function signature</sup> 436 | ```lisp 437 | (autothemer-hue-order (a b)) 438 | ``` 439 | 440 | - - - 441 | 442 | ### <a id="autothemer-lightest-order--a-b" aria-hidden="true"></a>autothemer-lightest-order 443 | 444 | Return t if the lightness of `a` > `b`. 445 | 446 | <sup>function signature</sup> 447 | ```lisp 448 | (autothemer-lightest-order (a b)) 449 | ``` 450 | 451 | - - - 452 | 453 | ### <a id="autothemer-saturated-order--a-b" aria-hidden="true"></a>autothemer-saturated-order 454 | 455 | Return t if the saturation of `a` > `b`. 456 | 457 | <sup>function signature</sup> 458 | ```lisp 459 | (autothemer-saturated-order (a b)) 460 | ``` 461 | 462 | - - - 463 | 464 | ### <a id="autothemer-saturation-group--color--saturation-groups" aria-hidden="true"></a>autothemer-saturation-group 465 | 466 | Return the saturation group of `color`. 467 | Functionally identical to `autothemer-hue-groups` for saturation. 468 | Optionally provide a list of `saturation-groups`. 469 | The default is `autothemer-20-percent-saturation-groups`. 470 | 471 | <sup>function signature</sup> 472 | ```lisp 473 | (autothemer-saturation-group (color &optional saturation-groups)) 474 | ``` 475 | 476 | - - - 477 | 478 | ### <a id="autothemer-sort-palette--theme-colors--sort-fn-group-fn-group-args" aria-hidden="true"></a>autothemer-sort-palette 479 | 480 | Produce a list of sorted `theme-colors` using `sort-fn`. 481 | If `sort-fn` is nil, sort by default `autothemer-darkest-order`. 482 | Grouping is supported via `group-fn` & `group-args`. 483 | 484 | See `autothemer-group-and-sort` for a full list. 485 | 486 | <sup>function signature</sup> 487 | ```lisp 488 | (autothemer-sort-palette (theme-colors &optional sort-fn group-fn group-args)) 489 | ``` 490 | 491 | - - - 492 | ### <a id="autothemer-let-palette"></a>autothemer-let-palette 493 | 494 | Provide a let block for `body` from `autothemer-current-theme`. 495 | 496 | Load/eval the required autothemer source (not byte-compiled) to set 497 | `autothemer-current-theme', before using `autothemer-let-palette` 498 | 499 | <sup>function signature</sup> 500 | ```lisp 501 | ;; assuming your theme has a palette color of juicy-watermelon 502 | (autothemer-let-palette ;; 503 | (message "%s" juicy-watermelon)) 504 | ``` 505 | 506 | - - - 507 | 508 | ### <a id="autothemer--alist-to-reduced-spec--facename-alist" aria-hidden="true"></a>autothemer--alist-to-reduced-spec internal 509 | 510 | Generate a reduced-spec for `facename`, based on the face attribute `alist`. 511 | 512 | <sup>function signature</sup> 513 | ```lisp 514 | (autothemer--alist-to-reduced-spec (facename alist)) 515 | ``` 516 | 517 | - - - 518 | 519 | ### <a id="autothemer--approximate-spec--reduced-spec-theme" aria-hidden="true"></a>autothemer--approximate-spec internal 520 | 521 | Replace colors in `reduced-spec` by their closest approximations in `theme`. 522 | Replace every expression in `reduced-spec` that passes 523 | `color-defined-p` by the closest approximation found in 524 | `autothemer-current-theme`. Also quote all face names and 525 | unbound symbols, such as `normal` or `demibold`. 526 | 527 | <sup>function signature</sup> 528 | ```lisp 529 | (autothemer--approximate-spec (reduced-spec theme)) 530 | ``` 531 | 532 | - - - 533 | 534 | ### <a id="autothemer--color-distance--color-autothemer-color" aria-hidden="true"></a>autothemer--color-distance internal 535 | 536 | Return the distance in rgb space between `color` and AUTOTHEMER-`color`. 537 | Here, `color` is an Emacs color specification and AUTOTHEMER-`color` is of 538 | type `autothemer--color`. 539 | 540 | <sup>function signature</sup> 541 | ```lisp 542 | (autothemer--color-distance (color autothemer-color)) 543 | ``` 544 | 545 | - - - 546 | 547 | ### <a id="autothemer--color-to-hsv--rgb" aria-hidden="true"></a>autothemer--color-to-hsv internal 548 | 549 | Convert `rgb`, a list of `(r g b)` to list `(h s v)`. 550 | The `r` `g` `b` values can range between `0..65535`. 551 | 552 | In `(h s v)` `h`, `s` and `v` are `0.0..1.0`. 553 | 554 | <sup>function signature</sup> 555 | ```lisp 556 | (autothemer--color-to-hsv (rgb)) 557 | ``` 558 | 559 | - - - 560 | 561 | ### <a id="autothemer--colorize-alist-" aria-hidden="true"></a>autothemer--colorize-alist internal 562 | 563 | Generate an alist for use with rainbow-mode. 564 | 565 | To colorize use: 566 | 567 | (rainbow-colorize-by-assoc (autothemer--colorize-alist)) 568 | 569 | Colors are from `autothemer-current-theme`. 570 | 571 | <sup>function signature</sup> 572 | ```lisp 573 | (autothemer--colorize-alist) 574 | ``` 575 | 576 | - - - 577 | 578 | ### <a id="autothemer--cons-to-tree--the-cons" aria-hidden="true"></a>autothemer--cons-to-tree internal 579 | 580 | Turn `the-cons` into a list, unless its cdr is `unspecified`. 581 | 582 | <sup>function signature</sup> 583 | ```lisp 584 | (autothemer--cons-to-tree (the-cons)) 585 | ``` 586 | 587 | - - - 588 | 589 | ### <a id="autothemer--current-theme-guard-" aria-hidden="true"></a>autothemer--current-theme-guard internal 590 | 591 | Guard functions from executing when there's no current theme. 592 | 593 | <sup>function signature</sup> 594 | ```lisp 595 | (autothemer--current-theme-guard) 596 | ``` 597 | 598 | - - - 599 | 600 | ### <a id="autothemer--demote-heads--expr" aria-hidden="true"></a>autothemer--demote-heads internal 601 | 602 | Demote every list head within `expr` by one element. 603 | E.g., (a (b c d) e (f g)) -> (list a (list b c d) e (list f g)). 604 | 605 | <sup>function signature</sup> 606 | ```lisp 607 | (autothemer--demote-heads (expr)) 608 | ``` 609 | 610 | - - - 611 | 612 | ### <a id="autothemer--extract-display--palette-n" aria-hidden="true"></a>autothemer--extract-display internal 613 | 614 | Extract from `palette` display specification #`n`. 615 | 616 | <sup>function signature</sup> 617 | ```lisp 618 | (autothemer--extract-display (palette n)) 619 | ``` 620 | 621 | - - - 622 | 623 | ### <a id="autothemer--extract-let-block--palette-n" aria-hidden="true"></a>autothemer--extract-let-block internal 624 | 625 | Extract a variable definition block from `palette` for display type `n`. 626 | 627 | <sup>function signature</sup> 628 | ```lisp 629 | (autothemer--extract-let-block (palette n)) 630 | ``` 631 | 632 | - - - 633 | 634 | ### <a id="autothemer--face-to-alist--face" aria-hidden="true"></a>autothemer--face-to-alist internal 635 | 636 | Return the attribute alist for `face` in frame (selected-frame). 637 | 638 | <sup>function signature</sup> 639 | ```lisp 640 | (autothemer--face-to-alist (face)) 641 | ``` 642 | 643 | - - - 644 | 645 | ### <a id="autothemer--fill-empty-palette-slots--palette" aria-hidden="true"></a>autothemer--fill-empty-palette-slots internal 646 | 647 | Fill empty `palette` slots so each display has all color-definitions. 648 | 649 | <sup>function signature</sup> 650 | ```lisp 651 | (autothemer--fill-empty-palette-slots (palette)) 652 | ``` 653 | 654 | - - - 655 | 656 | ### <a id="autothemer--find-closest-color--colors-color" aria-hidden="true"></a>autothemer--find-closest-color internal 657 | 658 | Return the element of `colors` that is closest in rgb space to `color`. 659 | Here, `color` is an Emacs color specification and `colors` is a list 660 | of `autothemer--color` structs. 661 | 662 | <sup>function signature</sup> 663 | ```lisp 664 | (autothemer--find-closest-color (colors color)) 665 | ``` 666 | 667 | - - - 668 | 669 | ### <a id="autothemer--get-color--color-name" aria-hidden="true"></a>autothemer--get-color internal 670 | 671 | Return color palette object for (string) `color-name`. 672 | 673 | Search the `autothemer-current-theme` color palette for `color-name` 674 | and returns a color in the form of `autothemer--color` struct. 675 | 676 | See also `autothemer--color-p`, 677 | `autothemer--color-name`, 678 | `autothemer--color-value`. 679 | 680 | <sup>function signature</sup> 681 | ```lisp 682 | (autothemer--get-color (color-name)) 683 | ``` 684 | 685 | - - - 686 | 687 | ### <a id="autothemer--pad-with-nil--row-min-number-of-elements" aria-hidden="true"></a>autothemer--pad-with-nil internal 688 | 689 | Make sure that `row` has at least `min-number-of-elements`. 690 | Pad with nil if necessary. 691 | 692 | <sup>function signature</sup> 693 | ```lisp 694 | (autothemer--pad-with-nil (row min-number-of-elements)) 695 | ``` 696 | 697 | - - - 698 | 699 | ### <a id="autothemer--reduced-spec-to-facespec--display-reduced-specs" aria-hidden="true"></a>autothemer--reduced-spec-to-facespec internal 700 | 701 | Create a face spec for `display`, with specs `reduced-specs`. 702 | 703 | For example: 704 | 705 | (autothemer--reduced-spec-to-facespec '(min-colors 60) '(button (:underline t :foreground red))) 706 | ;; => `(button (((min-colors 60) (:underline ,t :foreground ,red)))). 707 | 708 | <sup>function signature</sup> 709 | ```lisp 710 | (autothemer--reduced-spec-to-facespec (display reduced-specs)) 711 | ``` 712 | 713 | - - - 714 | 715 | ### <a id="autothemer--replace-nil-by-precursor--palette-row" aria-hidden="true"></a>autothemer--replace-nil-by-precursor internal 716 | 717 | Replace nil colors in `palette-row` with their precursor. 718 | 719 | `palette-row` is of the form `(name color [color ...])` 720 | 721 | Where the first `color` must be non nil. 722 | 723 | Any subsequent nil color will be replaced by the previous value. 724 | 725 | For example: 726 | 727 | ("red-foo" "#FF0000" nil) 728 | 729 | Will become: 730 | 731 | ("red-foo" "#FF0000" "#FF0000") 732 | 733 | <sup>function signature</sup> 734 | ```lisp 735 | (autothemer--replace-nil-by-precursor (palette-row)) 736 | ``` 737 | 738 | - - - 739 | 740 | ### <a id="autothemer--select-color---prompt" aria-hidden="true"></a>autothemer--select-color internal 741 | 742 | Select a color from the current palette, optionally use `prompt`. 743 | Current palette is read from `autothemer-current-theme`. 744 | 745 | The selected color will be in the form of a `autothemer--color` 746 | 747 | See also `autothemer--color-p`, 748 | `autothemer--color-name`, 749 | `autothemer--color-value`. 750 | 751 | <sup>function signature</sup> 752 | ```lisp 753 | (autothemer--select-color (&optional prompt)) 754 | ``` 755 | 756 | - - - 757 | 758 | ### <a id="autothemer--unindent--s" aria-hidden="true"></a>autothemer--unindent internal 759 | 760 | Unindent string `s` marked with | chars. 761 | 762 | <sup>function signature</sup> 763 | ```lisp 764 | (autothemer--unindent (s)) 765 | ``` 766 | 767 | - - - 768 | 769 | ### <a id="autothemer--unthemed-faces-" aria-hidden="true"></a>autothemer--unthemed-faces internal 770 | 771 | Find uncustomized faces. 772 | Iterate through all currently defined faces and return those that 773 | were left uncustomized by the most recent call to 774 | `autothemer-deftheme`. 775 | 776 | <sup>function signature</sup> 777 | ```lisp 778 | (autothemer--unthemed-faces) 779 | ``` 780 | 781 | - - - 782 | -------------------------------------------------------------------------------- /tests/autothemer-tests.el: -------------------------------------------------------------------------------- 1 | ;; autothemer-tests.el 2 | 3 | ;; Version: 0.2.18 4 | 5 | ;;; Code: 6 | 7 | (require 'autothemer) 8 | 9 | ;;; Test Helpers 10 | 11 | (defun name-color-to-struct (C) 12 | "Cons C with name & value to `autothemer--color` struct." 13 | (make-autothemer--color :name (car C) :value (cdr C))) 14 | 15 | (defun struct-to-cons-name-color (S) 16 | "S (`autothemer--color` struct) to `(cons name color)'." 17 | (cons 18 | (autothemer--color-name S) 19 | (autothemer--color-value S))) 20 | 21 | ;;; Tests 22 | 23 | (progn "Test autothemer-deftheme" 24 | 25 | ;;; Example theme 26 | (autothemer-deftheme theme-example 27 | "Autothemer example..." 28 | 29 | ;; Specify the color classes used by the theme 30 | ((((class color) (min-colors #xFFFFFF)) 31 | ((class color) (min-colors #xFF))) 32 | 33 | ;; Specify the color palette for each of the classes above. 34 | (example-red "#781210" "#FF0000") 35 | (example-green "#22881F" "#00D700") 36 | (example-blue "#212288" "#0000FF") 37 | (example-purple "#812FFF" "#Af00FF") 38 | (example-yellow "#EFFE00" "#FFFF00") 39 | (example-orange "#E06500" "#FF6600") 40 | (example-cyan "#22DDFF" "#00FFFF")) 41 | 42 | ;; specifications for Emacs faces. 43 | ((button (:underline t :weight 'bold :foreground example-yellow)) 44 | (error (:foreground example-red))) 45 | 46 | ;; Forms after the face specifications are evaluated. 47 | ;; (palette vars can be used, read below for details.) 48 | (custom-theme-set-variables 49 | 'theme-example 50 | `(ansi-color-names-vector 51 | [,example-red 52 | ,example-green 53 | ,example-blue 54 | ,example-purple 55 | ,example-yellow 56 | ,example-orange 57 | ,example-cyan]))) 58 | 59 | ;;; autothemer-current-theme is set. 60 | 61 | (ert-deftest current-theme () 62 | "Test current theme is available." 63 | (should (not (null 64 | autothemer-current-theme)))) 65 | 66 | (ert-deftest theme-has-colors () 67 | "Check theme has colors." 68 | (should (eql 7 (length (autothemer--theme-colors 69 | autothemer-current-theme))))) 70 | 71 | (ert-deftest theme-has-face-specs () 72 | "Check theme has face specs." 73 | (should (eql 2 (length (autothemer--theme-defined-faces 74 | autothemer-current-theme))))) 75 | 76 | (ert-deftest color-value () 77 | "Check color value." 78 | (should (string= "#781210" 79 | (autothemer--color-value 80 | (car (autothemer--theme-colors 81 | autothemer-current-theme)))))) 82 | 83 | (ert-deftest color-name () 84 | "Check color name." 85 | (should (string= "example-red" 86 | (autothemer--color-name 87 | (car (autothemer--theme-colors 88 | autothemer-current-theme)))))) 89 | 90 | (ert-deftest spec-name () 91 | "Check spec name." 92 | (should (equal 'button 93 | (car (autothemer--theme-defined-faces 94 | autothemer-current-theme))))) 95 | 96 | (ert-deftest theme-has-description () 97 | "Check theme description." 98 | (should (string= 99 | "Autothemer example..." 100 | (autothemer--theme-description 101 | autothemer-current-theme)))) 102 | 103 | (ert-deftest theme-has-name () 104 | "Check theme name." 105 | (should (string= 106 | "theme-example" 107 | (autothemer--theme-name 108 | autothemer-current-theme)))) 109 | 110 | ;;; Let palette 111 | 112 | (ert-deftest let-palette () 113 | "Check autothemer-let-palette" 114 | (should (string= 115 | "#781210" 116 | (autothemer-let-palette example-red)))) 117 | 118 | ;;; AT Helper functions 119 | 120 | (ert-deftest unindent () 121 | "Test unindent." 122 | (should 123 | (string= 124 | (autothemer--unindent "|Hello world 125 | | Foo bar 126 | | Indent 127 | |") 128 | "Hello world\n Foo bar\n Indent\n"))) 129 | 130 | (ert-deftest autothemer-plist-bind () 131 | "Test plist-bind." 132 | (autothemer--plist-bind (a b) '(:a 1 :b 2) 133 | (should (eql a 1)) 134 | (should (eql b 2)))) 135 | 136 | ;;; Color conversion 137 | 138 | (ert-deftest autothemer-hex-to-rgb () 139 | "Test hex to rgb." 140 | (should (equal '(0 0 0) (autothemer-hex-to-rgb "#000000"))) 141 | (should (equal '(65535 65535 65535) (autothemer-hex-to-rgb "#FFFFFF"))) 142 | (should (equal '(65535 0 0) (autothemer-hex-to-rgb "#FF0000"))) 143 | (should (equal '(65535 65535 0) (autothemer-hex-to-rgb "#FFFF00"))) 144 | (should (equal '(0 65535 0) (autothemer-hex-to-rgb "#00FF00"))) 145 | (should (equal '(0 65535 65535) (autothemer-hex-to-rgb "#00FFFF"))) 146 | (should (equal '(0 0 65535) (autothemer-hex-to-rgb "#0000FF"))) 147 | (should (equal '(32896 32896 32896) (autothemer-hex-to-rgb "#808080")))) 148 | 149 | (ert-deftest autothemer--color-to-hsv () 150 | "Test color to hsv conversion." 151 | (should (equal (autothemer--color-to-hsv '(0 0 0)) '(0.0 0.0 0.0))) 152 | (should (equal (autothemer--color-to-hsv '(65535 65535 65535)) '(0.0 0.0 1.0))) 153 | (should (equal (autothemer--color-to-hsv '(0 0 65535)) '(0.6666666666666666 1.0 1.0))) 154 | (should (equal (autothemer--color-to-hsv '(12896 0 32896)) '(0.7320038910505837 1.0 0.5019607843137255)))) 155 | 156 | ;;; HSV Color components 157 | 158 | (ert-deftest autothemer-color-hue () 159 | "Test get hue of hex-color." 160 | (should (= (autothemer-color-hue #s(autothemer--color example-color-020 "#2391CB")) 0.5575396825396826)) 161 | (should (= (autothemer-color-hue "#FF0000") 0)) 162 | (should (= (autothemer-color-hue "#FFFF00") 0.16666666666666666)) 163 | (should (= (autothemer-color-hue "#00FF00") 0.33333333333333333)) 164 | (should (= (autothemer-color-hue "#0000FF") 0.66666666666666666))) 165 | 166 | (ert-deftest autothemer-color-sat () 167 | "Test get sat of hex-color." 168 | (should (= (autothemer-color-sat #s(autothemer--color example-color-020 "#2391CB")) 0.8275862068965516)) 169 | (should (= (autothemer-color-sat "#0000FF") 1.0)) 170 | (should (= (autothemer-color-sat "#FF00FF") 1.0)) 171 | (should (= (autothemer-color-sat "#778822") 0.75)) 172 | (should (= (autothemer-color-sat "#772288") 0.75)) 173 | (should (= (autothemer-color-sat "#112233") 0.6666666666666667))) 174 | 175 | (ert-deftest autothemer-color-brightness () 176 | "Test get brightness of hex-color." 177 | (should (= (autothemer-color-brightness #s(autothemer--color example-color-020 "#2391CB")) 0.796078431372549)) 178 | (should (= (autothemer-color-brightness "#0000FF") 1.0)) 179 | (should (= (autothemer-color-brightness "#00FF00") 1.0)) 180 | (should (= (autothemer-color-brightness "#FF00FF") 1.0)) 181 | (should (= (autothemer-color-brightness "#333333") 0.2)) 182 | (should (= (autothemer-color-brightness "#555555") 0.3333333333333333))) 183 | 184 | ;;; Color distance 185 | 186 | (ert-deftest autothemer--color-distance () 187 | "Test color distance." 188 | (let ((color-struct (make-autothemer--color :name "Test" :value "#100000"))) 189 | (should (eql (autothemer--color-distance "#100000" color-struct) 0)) 190 | (should (eql (autothemer--color-distance "#100001" color-struct) 257)) 191 | (should (eql (autothemer--color-distance "#000001" color-struct) 4369)) 192 | (should (eql (autothemer--color-distance "#FF0000" color-struct) 61423)))) 193 | 194 | (ert-deftest autothemer-cie-de2000 () 195 | "Test color distance with CIE DE2000." 196 | (let ((color-struct (make-autothemer--color :name "Test" :value "#100000"))) 197 | (should (eql (autothemer-cie-de2000 "#100000" color-struct) 0.0)) 198 | (should (eql (autothemer-cie-de2000 "#100001" color-struct) 0.38178419390755014)) 199 | (should (eql (autothemer-cie-de2000 "#000001" color-struct) 5.891618859336162)) 200 | (should (eql (autothemer-cie-de2000 "#FF0000" color-struct) 48.817322029166725)))) 201 | 202 | (ert-deftest autothemer-rgb-to-hex () 203 | (should (equal (autothemer-rgb-to-hex '(0 0 0)) "#000000")) 204 | (should (equal (autothemer-rgb-to-hex '(65535 0 0)) "#FF0000")) 205 | (should (equal (autothemer-rgb-to-hex '(65535 65535 65535)) "#FFFFFF"))) 206 | 207 | ;;; Colorization 208 | 209 | (ert-deftest autothemer--colorize-alist () 210 | "Check autothemer-colorize-alist." 211 | (should (equal '(("example-red" . "#781210") 212 | ("example-green" . "#22881F") 213 | ("example-blue" . "#212288") 214 | ("example-purple" . "#812FFF") 215 | ("example-yellow" . "#EFFE00") 216 | ("example-orange" . "#E06500") 217 | ("example-cyan" . "#22DDFF")) 218 | (autothemer--colorize-alist)))) 219 | 220 | ;;; Color/Palette grouping & sorting 221 | 222 | (ert-deftest autothemer-color-hue-grouping () 223 | "Test autothemer-color-hue-group." 224 | (should (equal (autothemer-hue-grouping "#FF0005") 'red)) 225 | (should (equal (autothemer-hue-grouping "#00FF00") 'green)) 226 | (should (equal (autothemer-hue-grouping "#FF00FF") 'magenta)) 227 | (should (equal (autothemer-hue-grouping "#00FFFF") 'cyan)) 228 | (should (equal (autothemer-hue-grouping "#0000FF") 'blue-magenta)) 229 | (should (equal (autothemer-hue-grouping "#FFFF00") 'yellow-green)) 230 | (should (equal (autothemer-hue-grouping "#FFFF00" autothemer-hue-groups) 'yellow-green)) 231 | (should (equal (autothemer-hue-grouping "#FFFF00" autothemer-simple-hue-groups) 'green))) 232 | 233 | (ert-deftest autothemer-brightness-grouping () 234 | "Test autothemer-brightness-group." 235 | (should (equal (autothemer-brightness-grouping "#FF0005") 'brightness-080-100-percent)) 236 | (should (equal (autothemer-brightness-grouping "#007700") 'brightness-040-060-percent)) 237 | (should (equal (autothemer-brightness-grouping "#FF55FF") 'brightness-080-100-percent)) 238 | (should (equal (autothemer-brightness-grouping "#004444") 'brightness-020-040-percent)) 239 | (should (equal (autothemer-brightness-grouping "#020202") 'brightness-000-020-percent)) 240 | (should (equal (autothemer-brightness-grouping 241 | "#020202" 242 | autothemer-dark-mid-light-brightness-groups) 243 | 'dark)) 244 | (should (equal (autothemer-brightness-grouping 245 | "#777777" 246 | autothemer-dark-mid-light-brightness-groups) 247 | 'mid))) 248 | 249 | (ert-deftest autothemer-saturation-grouping () 250 | "Test autothemer-saturation-group." 251 | (should (equal (autothemer-saturation-grouping "#FF0005") 'saturation-080-100-percent)) 252 | (should (equal (autothemer-saturation-grouping "#007700") 'saturation-080-100-percent)) 253 | (should (equal (autothemer-saturation-grouping "#FF55FF") 'saturation-060-080-percent)) 254 | (should (equal (autothemer-saturation-grouping "#004444") 'saturation-080-100-percent)) 255 | (should (equal (autothemer-saturation-grouping "#020202") 'saturation-000-020-percent)) 256 | (should (equal (autothemer-saturation-grouping 257 | "#020202" 258 | autothemer-low-mid-high-saturation-groups) 259 | 'low)) 260 | (should (equal (autothemer-saturation-grouping 261 | "#336677" 262 | autothemer-low-mid-high-saturation-groups) 263 | 'mid))) 264 | 265 | (ert-deftest autothemer-group-colors () 266 | "Group colors into a plist of color lists, with group names as keys." 267 | (should (equal 268 | (autothemer-group-colors 269 | (list 270 | (make-autothemer--color :name 'example-color-005 :value "#112063") 271 | (make-autothemer--color :name 'example-color-006 :value "#88DDCC") 272 | (make-autothemer--color :name 'example-color-006 :value "#99DDCC") 273 | (make-autothemer--color :name 'example-color-006 :value "#FFDDCC") 274 | (make-autothemer--color :name 'example-color-006 :value "#FFEECC") 275 | (make-autothemer--color :name 'example-color-007 :value "#281993") 276 | (make-autothemer--color :name 'example-color-010 :value "#240933")) 277 | (list :group-fn 'autothemer-saturation-grouping 278 | :group-args autothemer-low-mid-high-saturation-groups)) 279 | '((low 280 | #s(autothemer--color example-color-006 "#99DDCC") 281 | #s(autothemer--color example-color-006 "#FFDDCC") 282 | #s(autothemer--color example-color-006 "#FFEECC")) 283 | (mid 284 | #s(autothemer--color example-color-006 "#88DDCC")) 285 | (high 286 | #s(autothemer--color example-color-005 "#112063") 287 | #s(autothemer--color example-color-007 "#281993") 288 | #s(autothemer--color example-color-010 "#240933")))))) 289 | 290 | (ert-deftest autothemer-group-and-sort () 291 | "Group and sort a palette of `autothemer--color' structs." 292 | (let ((result (autothemer-group-and-sort 293 | (mapcar 294 | 'name-color-to-struct 295 | '((example-color-001 . "#702414") 296 | (example-color-002 . "#642C12") 297 | (example-color-003 . "#583410") 298 | (example-color-004 . "#191204") 299 | (example-color-005 . "#181818") 300 | (example-color-006 . "#191904") 301 | (example-color-007 . "#373D0A") 302 | (example-color-008 . "#243108") 303 | (example-color-009 . "#162506") 304 | (example-color-010 . "#224C0E") 305 | (example-color-011 . "#287C16") 306 | (example-color-012 . "#0E4C0E") 307 | (example-color-013 . "#147024") 308 | (example-color-014 . "#0E4C22") 309 | (example-color-015 . "#167C49") 310 | (example-color-016 . "#20BE87") 311 | (example-color-017 . "#28E4C4") 312 | (example-color-018 . "#1AA4A4") 313 | (example-color-019 . "#178297") 314 | (example-color-020 . "#2391CB") 315 | (example-color-021 . "#13416F") 316 | (example-color-022 . "#13306F") 317 | (example-color-023 . "#112063") 318 | (example-color-024 . "#0D0D4B") 319 | (example-color-025 . "#281993") 320 | (example-color-026 . "#170933") 321 | (example-color-027 . "#620FA9") 322 | (example-color-028 . "#240933") 323 | (example-color-029 . "#63136F") 324 | (example-color-030 . "#330933") 325 | (example-color-031 . "#971782") 326 | (example-color-032 . "#D62499") 327 | (example-color-033 . "#A41A5F") 328 | (example-color-034 . "#D82662") 329 | (example-color-035 . "#B11D37") 330 | (example-color-036 . "#E52929"))) 331 | '(:group-fn 'autothemer-hue-grouping 332 | :group-args autothemer-simple-hue-groups 333 | :sort-fn 'autothemer-darkest-order))) 334 | 335 | (expected '((red 336 | #s(autothemer--color example-color-005 "#181818") 337 | #s(autothemer--color example-color-002 "#642C12") 338 | #s(autothemer--color example-color-001 "#702414") 339 | #s(autothemer--color example-color-035 "#B11D37") 340 | #s(autothemer--color example-color-036 "#E52929")) 341 | (orange 342 | #s(autothemer--color example-color-004 "#191204") 343 | #s(autothemer--color example-color-003 "#583410")) 344 | (green 345 | #s(autothemer--color example-color-006 "#191904") 346 | #s(autothemer--color example-color-009 "#162506") 347 | #s(autothemer--color example-color-008 "#243108") 348 | #s(autothemer--color example-color-007 "#373D0A") 349 | #s(autothemer--color example-color-010 "#224C0E") 350 | #s(autothemer--color example-color-012 "#0E4C0E") 351 | #s(autothemer--color example-color-014 "#0E4C22") 352 | #s(autothemer--color example-color-013 "#147024") 353 | #s(autothemer--color example-color-011 "#287C16")) 354 | (cyan 355 | #s(autothemer--color example-color-021 "#13416F") 356 | #s(autothemer--color example-color-015 "#167C49") 357 | #s(autothemer--color example-color-019 "#178297") 358 | #s(autothemer--color example-color-018 "#1AA4A4") 359 | #s(autothemer--color example-color-016 "#20BE87") 360 | #s(autothemer--color example-color-020 "#2391CB") 361 | #s(autothemer--color example-color-017 "#28E4C4")) 362 | (blue 363 | #s(autothemer--color example-color-026 "#170933") 364 | #s(autothemer--color example-color-028 "#240933") 365 | #s(autothemer--color example-color-024 "#0D0D4B") 366 | #s(autothemer--color example-color-023 "#112063") 367 | #s(autothemer--color example-color-022 "#13306F") 368 | #s(autothemer--color example-color-025 "#281993") 369 | #s(autothemer--color example-color-027 "#620FA9")) 370 | (magenta 371 | #s(autothemer--color example-color-030 "#330933") 372 | #s(autothemer--color example-color-029 "#63136F") 373 | #s(autothemer--color example-color-031 "#971782") 374 | #s(autothemer--color example-color-033 "#A41A5F") 375 | #s(autothemer--color example-color-032 "#D62499") 376 | #s(autothemer--color example-color-034 "#D82662"))))) 377 | (should (equal result expected)))) 378 | 379 | (ert-deftest autothemer-groups-to-palette () 380 | "Flatten a grouped palette (keeping order)." 381 | (let ((result 382 | (autothemer-groups-to-palette '((high 383 | #s(autothemer--color example-color-005 "#112063") 384 | #s(autothemer--color example-color-007 "#281993") 385 | #s(autothemer--color example-color-010 "#240933")) 386 | (mid 387 | #s(autothemer--color example-color-006 "#88DDCC")) 388 | (low 389 | #s(autothemer--color example-color-006 "#99DDCC") 390 | #s(autothemer--color example-color-006 "#FFDDCC") 391 | #s(autothemer--color example-color-006 "#FFEECC"))))) 392 | 393 | (expected '( #s(autothemer--color example-color-005 "#112063") 394 | #s(autothemer--color example-color-007 "#281993") 395 | #s(autothemer--color example-color-010 "#240933") 396 | #s(autothemer--color example-color-006 "#88DDCC") 397 | #s(autothemer--color example-color-006 "#99DDCC") 398 | #s(autothemer--color example-color-006 "#FFDDCC") 399 | #s(autothemer--color example-color-006 "#FFEECC"))))))) 400 | 401 | (defun autothemer-groups-to-palette (grouped-palette) 402 | "Flatten a GROUPED-PALETTE from `autothemer-group-and-sort' to a single list." 403 | (-flatten (--map (cdr it) grouped-palette))) 404 | 405 | (autothemer-color-hue #s(autothemer--color example-color-020 "#2391CB")) 406 | 407 | ;;; autothemer-tests.el ends here 408 | --------------------------------------------------------------------------------