Skip to content

Commit

Permalink
[Themes] Lay the groundwork for theme support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Miller committed Jun 18, 2019
1 parent 0273e0a commit 4bd9421
Show file tree
Hide file tree
Showing 82 changed files with 287 additions and 306 deletions.
File renamed without changes
Binary file added icons/default/buffer-group-closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/default/buffer-group-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
464 changes: 181 additions & 283 deletions src/elisp/treemacs-icons.el

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/elisp/treemacs-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ Will simply return `treemacs--eldoc-msg'."
(add-to-list 'delete-frame-functions #'treemacs--on-frame-kill)
(add-hook 'post-command-hook #'treemacs--post-command nil t)


(treemacs--build-indentation-cache 6)
(treemacs--adjust-icons-to-window-system)
(treemacs--select-icon-set)
(treemacs--setup-icon-highlight)
(treemacs--setup-icon-background-colors)
(treemacs--setup-mode-line)
Expand Down
6 changes: 3 additions & 3 deletions src/elisp/treemacs-rendering.el
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ set to PARENT."
(setq dir-strings
(treemacs--create-buttons
:nodes dirs
:extra-vars ((dir-prefix (concat prefix treemacs-icon-closed)))
:extra-vars ((dir-prefix (concat prefix treemacs-icon-dir-closed)))
:depth ,depth
:node-name node
:node-action (treemacs--create-dir-button-strings node dir-prefix ,parent ,depth)))
Expand Down Expand Up @@ -529,7 +529,7 @@ RECURSIVE: Bool"
:immediate-insert nil
:button btn
:new-state 'dir-node-open
:new-icon treemacs-icon-open
:new-icon treemacs-icon-dir-open
:open-action
(progn
;; do on-expand first so buttons that need collapsing can quickly find their parent
Expand All @@ -552,7 +552,7 @@ Remove all open dir and tag entries under BTN when RECURSIVE."
(treemacs--button-close
:button btn
:new-state 'dir-node-closed
:new-icon treemacs-icon-closed
:new-icon treemacs-icon-dir-closed
:post-close-action
(-let [path (treemacs-button-get btn :path)]
(treemacs--stop-watching path)
Expand Down
8 changes: 4 additions & 4 deletions src/elisp/treemacs-tags.el
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Recursively open all tags below BTN when RECURSIVE is non-nil."
:open-action (treemacs--create-buttons
:nodes index
:extra-vars
((node-prefix (concat prefix treemacs-icon-tag-node-closed))
((node-prefix (concat prefix treemacs-icon-tag-closed))
(leaf-prefix (concat prefix treemacs-icon-tag-leaf)))
:depth (1+ (treemacs-button-get btn :depth))
:node-name item
Expand Down Expand Up @@ -283,13 +283,13 @@ Open all tag section under BTN when call is RECURSIVE."
:button btn
:immediate-insert t
:new-state 'tag-node-open
:new-icon treemacs-icon-tag-node-open
:new-icon treemacs-icon-tag-open
:open-action (treemacs--create-buttons
:nodes index
:depth (1+ (treemacs-button-get btn :depth))
:node-name item
:extra-vars ((leaf-prefix (concat prefix treemacs-icon-tag-leaf))
(node-prefix (concat prefix treemacs-icon-tag-node-closed)))
(node-prefix (concat prefix treemacs-icon-tag-closed)))
:node-action (if (imenu--subalist-p item)
(treemacs--insert-tag-node item node-prefix btn depth)
(treemacs--insert-tag-leaf item leaf-prefix btn depth)))
Expand Down Expand Up @@ -328,7 +328,7 @@ Remove all open tag entries under BTN when RECURSIVE."
(treemacs--button-close
:button btn
:new-state 'tag-node-closed
:new-icon treemacs-icon-tag-node-closed
:new-icon treemacs-icon-tag-closed
:post-close-action
(treemacs-on-collapse (treemacs--tags-path-of btn)))))

Expand Down
80 changes: 80 additions & 0 deletions src/elisp/treemacs-themes.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
;;; treemacs.el --- A tree style file viewer package -*- lexical-binding: t -*-

;; Copyright (C) 2018 Alexander Miller

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;; Definitions for the theme type, their creation, and, eventually, the means
;;; to change themes.

;;; Code:

(require 'f)
(require 'dash)
(require 'ht)
(require 'cl-lib)
(require 'inline)
(require 'treemacs-macros)
(require 'treemacs-core-utils)

(treemacs--defstruct treemacs-theme
name path gui-icons tui-icons)

(defvar treemacs--current-theme nil "The currently used theme.")

(defvar treemacs--themes nil "List of all known themes.")

(define-inline treemacs--find-theme (name)
"Find theme with the given NAME."
(declare (side-effect-free t))
(inline-letevals (name)
(inline-quote
(--first (string= (treemacs-theme->name it) ,name) treemacs--themes))))

(cl-defmacro treemacs-create-theme (name &key icon-directory extends config)
"Create a new (bare) theme with the given NAME.
- ICON-DIRECTORY is the (mandatory) theme's location.
- BASED-ON is the name of a theme whose icons this one should start with.
- CONFIG is a code block to fill the created theme with icons via
`treemacs-create-icon'."
(declare (indent 1))
`(let* ((gui-icons (make-hash-table :size 300 :test 'equal))
(tui-icons (make-hash-table :size 300 :test 'equal))
(theme (make-treemacs-theme
:name ,name
:path ,icon-directory
:gui-icons gui-icons
:tui-icons tui-icons)))
(add-to-list 'treemacs--themes theme)
(when ,extends
(treemacs-unless-let (base-theme (treemacs--find-theme ,extends))
(treemacs-log "Could not find base theme %s when creating theme %s." ,extends ,name)
(treemacs--maphash (treemacs-theme->gui-icons base-theme) (ext icon)
(ht-set! gui-icons ext icon))
(treemacs--maphash (treemacs-theme->tui-icons base-theme) (ext icon)
(ht-set! tui-icons ext icon))))
(-let [treemacs--current-theme theme]
,config)
theme))

(defun treemacs-load-theme (name)
"Enable the theme with the given NAME."
(treemacs-unless-let (theme (treemacs--find-theme name))
(treemacs-log "Cannot find theme '%s'." name)
(setq treemacs--current-theme theme)))

(provide 'treemacs-themes)

;;; treemacs-themes.el ends here
26 changes: 12 additions & 14 deletions src/elisp/treemacs-visuals.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
(require 'pulse)
(require 'hl-line)
(require 'treemacs-core-utils)
(require 'treemacs-themes)
(require 'treemacs-customization)
(require 'treemacs-fringe-indicator)
(eval-and-compile
Expand All @@ -45,9 +46,6 @@
;; Since it is a marker in the treemacs buffer it is important for it to be reset whenever it might
;; become invalid.

(treemacs-import-functions-from "treemacs-icons"
treemacs--created-icons)

(defvar-local treemacs--last-highlight nil
"The last button treemacs has highlighted.")

Expand Down Expand Up @@ -119,29 +117,29 @@
(advice-remove #'disable-theme #'treemacs--setup-icon-background-colors)))

(defun treemacs--setup-icon-background-colors (&rest _)
"Align icon backgrounds with current theme.
Fetch the current theme's background & hl-line colors and inject them into
`treemacs--created-icons'. Also called as advice after `load-theme', hence the
ignored argument."
"Align icon backgrounds with current Emacs theme.
Fetch the current Emacs theme's background & hl-line colors and inject them into
the gui icons of every theme in `treemacs--themes'.
Also called as advice after `load-theme', hence the ignored argument."
(let* ((default-background (face-attribute 'default :background nil t))
(hl-line-background (face-attribute 'hl-line :background nil t))
(icon (car (treemacs--created-icons)))
(icon-background (treemacs--get-img-property (get-text-property 0 'img-unselected icon) :background))
(icon-hl-background (treemacs--get-img-property (get-text-property 0 'img-selected icon) :background)))
(test-icon (with-no-warnings treemacs-icon-root))
(icon-background (treemacs--get-img-property (get-text-property 0 'img-unselected test-icon) :background))
(icon-hl-background (treemacs--get-img-property (get-text-property 0 'img-selected test-icon) :background)))
(when (eq default-background 'unspecified-bg)
(setq default-background "#2d2d31"))
;; make sure we only change all the icons' colors when we have to
(unless (and (string= default-background icon-background)
(string= hl-line-background icon-hl-background))
(setf treemacs--selected-icon-background hl-line-background
treemacs--not-selected-icon-background default-background)
(--each (treemacs--created-icons)
(progn
(dolist (theme treemacs--themes)
(treemacs--maphash (treemacs-theme->gui-icons theme) (_ icon)
(treemacs--set-img-property
(get-text-property 0 'img-selected it)
(get-text-property 0 'img-selected icon)
:background treemacs--selected-icon-background)
(treemacs--set-img-property
(get-text-property 0 'img-unselected it)
(get-text-property 0 'img-unselected icon)
:background treemacs--not-selected-icon-background))))))

(defun treemacs--update-icon-selection ()
Expand Down
1 change: 1 addition & 0 deletions src/elisp/treemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(require 'f)
(require 'bookmark)
(require 'treemacs-customization)
(require 'treemacs-themes)
(require 'treemacs-icons)
(require 'treemacs-faces)
(require 'treemacs-visuals)
Expand Down
5 changes: 4 additions & 1 deletion src/extra/treemacs-icons-dired.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
(not treemacs-icons-dired-displayed)
dired-subdir-alist)
(setq-local treemacs-icons-dired-displayed t)
(setq-local treemacs-icons (treemacs-theme->gui-icons treemacs--current-theme))
(pcase-dolist (`(,path . ,pos) dired-subdir-alist)
(treemacs-icons-dired--display-icons-for-subdir path pos))))

Expand All @@ -59,7 +60,7 @@
(if (dired-move-to-filename nil)
(let* ((file (dired-get-filename nil t))
(icon (if (file-directory-p file)
treemacs-icon-closed
treemacs-icon-dir-closed
(treemacs-icon-for-file file))))
(insert icon))
(treemacs-return nil))
Expand Down Expand Up @@ -127,13 +128,15 @@ This will make sure the icons' background colors will align with hl-line mode."
(if treemacs-icons-dired-mode
(progn
(add-hook 'dired-after-readin-hook #'treemacs-icons-dired--display)
(add-hook 'dired-mode-hook #'treemacs--select-icon-set)
(add-hook 'dired-mode-hook #'treemacs-icons-dired--enable-highlight-correction)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'dired-mode)
(treemacs-icons-dired--enable-highlight-correction)
(treemacs-icons-dired--display)))))
(remove-hook 'dired-after-readin-hook #'treemacs-icons-dired--display)
(remove-hook 'dired-mode-hook #'treemacs--select-icon-set)
(remove-hook 'dired-mode-hook #'treemacs-icons-dired--enable-highlight-correction)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
Expand Down

0 comments on commit 4bd9421

Please sign in to comment.