summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Pykhalov <go.wigust@gmail.com>2018-03-22 11:15:42 +0300
committerOleg Pykhalov <go.wigust@gmail.com>2018-03-22 11:47:29 +0300
commit303f58cf65fb6c7701b587cdd048ca785019ebd0 (patch)
treed163284d6cec860f437538e4d1c34162936a63d6
downloademacs-redshift-303f58cf65fb6c7701b587cdd048ca785019ebd0.tar.gz
Initial commit.
-rw-r--r--README69
-rw-r--r--guix.scm71
-rw-r--r--redshift.el77
3 files changed, 217 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..512d5fb
--- /dev/null
+++ b/README
@@ -0,0 +1,69 @@
+-*- mode: org -*-
+
+* About
+
+ =Emacs-Redshift= (aka =redshift.el=) provides an Emacs interface to
+ [[https://github.com/jonls/redshift][Redshift]] for changing display
+ color temperature.
+
+* Installation
+
+ Emacs-Redshift can be used from a Git checkout and can be installed
+ using Guix.
+
+** Git checkout
+
+ Clone a Git repository:
+
+ #+BEGIN_SRC sh
+ git clone https://github.com/wigust/emacs-redshift
+ #+END_SRC
+
+ Add it to Emacs =load-path= in your init file and load:
+
+ #+BEGIN_SRC emacs-lisp
+ (add-to-list 'load-path (expand-file-name "~/emacs-redshift"))
+ (require 'redshift)
+ #+END_SRC
+
+** Guix
+
+ Clone a Git repository:
+
+ #+BEGIN_SRC sh
+ git clone https://github.com/wigust/emacs-redshift
+ cd emacs-redshift
+ #+END_SRC
+
+ Install a Guix package with:
+
+ #+BEGIN_SRC sh
+ guix package -f guix.scm
+ #+END_SRC
+
+* Usage
+
+ Call =M-x redshift-set-temp= to set a display temperature.
+
+ Call =M-x redshift-increase-temp= to increase a display temperature.
+
+ Call =M-x redshift-decrease-temp= to decrease a display temperature.
+
+ To change increment for =redshift-increase-temp= and
+ =redshift-decrease-temp= set =redshift-temp-increment= to a number.
+
+ #+BEGIN_SRC emacs-lisp
+ (setq redshift-temp-increment 100)
+ #+END_SRC
+
+* Keys
+
+ You could use [[https://github.com/abo-abo/hydra][Hydra]] to get an
+ interactive interface:
+
+ #+BEGIN_SRC emacs-lisp
+ (defhydra hydra-redshift () "redshift"
+ ("g" redshift-set-temp "set")
+ ("n" redshift-decrease-temp "decrease")
+ ("p" redshift-increase-temp "increase"))
+ #+END_SRC
diff --git a/guix.scm b/guix.scm
new file mode 100644
index 0000000..11dd57e
--- /dev/null
+++ b/guix.scm
@@ -0,0 +1,71 @@
+;;; guix.scm --- Emacs interface to Redshift
+
+;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
+
+;; This file is part of Emacs-Redshift.
+
+;; Emacs-Redshift 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.
+;;
+;; Emacs-Redshift 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 Emacs-Redshift.
+;; If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file contains Guix package for development version of
+;; Emacs-redshift. To build or install, run:
+;;
+;; guix build --file=guix.scm
+;; guix package --install-from-file=guix.scm
+
+;;; Code:
+
+(use-modules ((guix licenses) #:prefix license:)
+ (guix build utils)
+ (guix build-system emacs)
+ (guix gexp)
+ (guix git-download)
+ (guix packages)
+ (ice-9 popen)
+ (ice-9 rdelim))
+
+(define %source-dir (dirname (current-filename)))
+
+(define (git-output . args)
+ "Execute 'git ARGS ...' command and return its output without trailing
+newspace."
+ (with-directory-excursion %source-dir
+ (let* ((port (apply open-pipe* OPEN_READ "git" args))
+ (output (read-string port)))
+ (close-port port)
+ (string-trim-right output #\newline))))
+
+(define (current-commit)
+ (git-output "log" "-n" "1" "--pretty=format:%H"))
+
+(define emacs-redshift
+ (let ((commit (current-commit)))
+ (package
+ (name "emacs-redshift")
+ (version (string-append "0.0.1" "-" (string-take commit 7)))
+ (source (local-file %source-dir
+ #:recursive? #t
+ #:select? (git-predicate %source-dir)))
+ (build-system emacs-build-system)
+ (home-page "https://github.com/wigust/emacs-redshift")
+ (synopsis "Emacs interface to Redshift")
+ (description
+ "This package provides an Emacs interface to Redshift")
+ (license license:gpl3+))))
+
+emacs-redshift
+
+;;; guix.scm ends here
diff --git a/redshift.el b/redshift.el
new file mode 100644
index 0000000..a9b2774
--- /dev/null
+++ b/redshift.el
@@ -0,0 +1,77 @@
+;;; redshift.el --- Emacs interface to Redshift
+
+;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
+
+;; Author: Oleg Pykhalov <go.wigust@gmail.com>
+;; Version: 0.0.1
+;; URL: https://wigust.github.io/emacs-redshift/
+;; Keywords: tools
+;; Package-Requires: ((emacs "24.3")
+
+;; This file is part of Emacs-Redshift.
+
+;; Emacs-Redshift 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.
+;;
+;; Emacs-Redshift 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 Emacs-Redshift.
+;; If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file provides functions to control Redshift. It allows you:
+;;
+;; - to decrease a display temperature with `redshift-decrease-temp';
+;;
+;; - to increase a display temperature with `redshift-increase-temp';
+;;
+;; - to set a display temperature with `redshift-set-temp'.
+
+;;; Code:
+
+(defvar redshift-temp 5500 "Display color temperature")
+
+(defcustom redshift-temp-increment 500
+ "Display color temperature increment."
+ :type 'number
+ :group 'redshift)
+
+(defcustom redshift-program "redshift"
+ "The name by which to invoke Redshift."
+ :type 'string
+ :group 'redshift)
+
+;;;###autoload
+(defun redshift-set-temp (temp)
+ "Set display color temperature of display to TEMP and return TEMP."
+ (interactive "nColor temperature: ")
+ (and (start-process "redshift" nil redshift-program
+ "-O" (number-to-string temp))
+ temp))
+
+;;;###autoload
+(defun redshift-increase-temp ()
+ "Increase display color temperature of display to TEMP."
+ (interactive)
+ (setq redshift-temp
+ (redshift-set-temp (+ redshift-temp
+ redshift-temp-increment))))
+
+;;;###autoload
+(defun redshift-decrease-temp ()
+ "Decrease display color temperature of display to TEMP."
+ (interactive)
+ (setq redshift-temp
+ (redshift-set-temp (- redshift-temp
+ redshift-temp-increment))))
+
+(provide 'redshift)
+
+;;; redshift.el ends here