Add location contrib layer

This commit is contained in:
Gogs 2015-06-21 16:42:44 +02:00 committed by syl20bnr
parent e72dd8a87d
commit 8c8778bbd7
6 changed files with 202 additions and 0 deletions

View File

@ -0,0 +1,88 @@
#+TITLE: Location contribution layer for Spacemacs
* Table of Contents
* Description
This layer offers few location sensetive adjustment to Emacs, such as
automaticly switching between light (day) and dark (night) themes, weather
forecast and on OS X, also automatic tracking of location, using OS X's
CoreLocation services.
** Supported packages in this layer
- [[https://github.com/hadronzoo/theme-changer][theme-changer]]
- [[https://github.com/aaronbieber/sunshine.el/blob/master/sunshine.el][sunshine]]
- [[https://github.com/purcell/osx-location][osx-location]]
* Install
To enable this contribution layer, add it to your =~/.spacemacs=~ like this:
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(location))
#+END_SRC
All services are disable by default. To enable all, or some of them, add instead
something like this:
#+BEGIN_SRC emacs-lisp
(location :variables
enable-osx-location-service-support t
enable-weather-forecast t
enable-automatic-theme-managment t)
#+END_SRC
To set location manually, add something like this inside the ~dotspacemacs/config
defun~.
#+BEGIN_SRC emacs-lisp
(setq calendar-location-name "Barcelona, Spain"
calendar-latitude 41.23
calendar-longitude 1.80)
#+END_SRC
On OS X, all of these variables get setup automatically by the ~osx-location~
service, when enabled. If ~calendar-location-name~ was ommitted, it'll be
stringed-up like so: "41.23, 1.80".
* Key Bindings
New keybindings for this layer are for using ~sunshine~.
| Evil | Holy | Command |
|-----------+------+-----------------------------------------------|
| ~SPC a w~ | | Display pretty weather forecast |
| ~SPC a W~ | | Display quick weather forecast in mini buffer |
* Customize it!
** theme-changer
Theme changer will switch between two given themes, depending on time at
geographical location. By default, it will use first two themes the user has setup in
~dotemacs-themes~.
If the list is empty, for whatever reason, it'll swap ~spacemacs-light~ and
~spacemacs-dark~ by default.
** sunshine (weather forecast)
Sunshine uses the imperial unit system by default. To switch to metric, do this:
#+BEGIN_SRC emacs-lisp
(setq sunshine-units 'metric)
#+END_SRC
Weather forecast icons are disabled by default, but can be toggled by pressing
`i' within this mode's main buffer. To display weather forecast icons by default
("pretty mode"), change the settings to this:
#+BEGIN_SRC emacs-lisp
(setq sunshine-show-icons t)
#+END_SRC
[[file:img/emacs-sunshine.jpg]]
** osx-location
OS X users can take adavantage of automatic geogrphical discovery using the OS'
CoreLocation system service, implemented as a long running background process. A
helper script will need to be given proper access first time this layer is
activated.
[[file:img/emacs-location-helper.jpg]]

View File

@ -0,0 +1,14 @@
(defvar enable-osx-location-service-support nil
"")
(defvar enable-weather-forecast nil
"")
(defvar enable-automatic-theme-managment nil
"")
(defvar spacemacs/day-theme 'spacemacs-light
"")
(defvar spacemacs/night-theme 'spacemacs-dark
"")

View File

@ -0,0 +1,31 @@
;;; extensions.el --- location Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq location-pre-extensions
'(
;; pre extension names go here
))
(setq location-post-extensions
'(
;; post extension names go here
))
;; For each extension, define a function location/init-<extension-name>
;;
;; (defun location/init-my-extension ()
;; "Initialize my extension"
;; )
;;
;; Often the body of an initialize function uses `use-package'
;; For more info on `use-package', see readme:
;; https://github.com/jwiegley/use-package

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1,69 @@
;;; packages.el --- location Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq location-packages
'(
osx-location
sunshine
theme-changer
))
(require 'solar)
(defun location/init-osx-location ()
"Initialize osx-location"
(use-package osx-location
:if enable-osx-location-service-support
:defer t
:init
(progn
(add-hook 'osx-location-changed-hook
(lambda ()
(setq calendar-latitude osx-location-latitude
calendar-longitude osx-location-longitude)
(unless calendar-location-name
(setq calendar-location-name
(format "%s, %s" osx-location-latitude osx-location-longitude)))))
(osx-location-watch))))
(defun location/init-sunshine ()
"Initialize sunshine"
(use-package sunshine
:if enable-weather-forecast
:defer t
:init
(progn
(evil-leader/set-key
"aw" 'sunshine-forecast
"aW" 'sunshine-quick-forecast)
(evilify sunshine-mode sunshine-mode-map
(kbd "q") 'quit-window
(kbd "i") 'sunshine-toggle-icons))
:config
;; just in case location was not set by user, or on OS X, if wasn't set up
;; automatically, will not work with Emac's default for `calendar-location-name'
(when (not (boundp 'sunshine-location))
(setq sunshine-location (format "%s, %s" calendar-latitude calendar-longitude)))))
(defun location/init-theme-changer ()
"Initialize theme-changer"
(use-package theme-changer
:if enable-automatic-theme-managment
:defer t
:init
(when (car dotspacemacs-themes) ;; at least one theme defined in user's `dotspacemacs-themes'
(setq spacemacs/day-theme (nth 0 dotspacemacs-themes))
(setq spacemacs/night-theme (nth 1 dotspacemacs-themes)))
:config
(change-theme spacemacs/day-theme spacemacs/night-theme) ;; otherwise use defaults fron config.el
))