├── docs ├── website │ ├── .gitignore │ ├── layouts │ │ ├── partials │ │ │ ├── footer.html │ │ │ └── header.html │ │ ├── index.html │ │ └── _default │ │ │ ├── single.html │ │ │ └── list.html │ ├── static │ │ └── style.css │ ├── config.toml │ ├── generate.el │ ├── Makefile │ ├── Readme.org │ └── COPYING ├── CONTRIBUTING.md └── pull_request_template.md ├── paper1.gif ├── bibliothek.png ├── forecast.el.png ├── .github └── FUNDING.yml ├── ovp-test.org ├── dollar.el ├── gk-greek.el ├── Website.org ├── .hgtags ├── Readme.org ├── gk-unilat.el ├── pass-listing.el ├── bibliothek.el ├── org-variable-pitch.el ├── bsdpkg.el ├── paper-theme.el └── forecast.el /docs/website/.gitignore: -------------------------------------------------------------------------------- 1 | public/ 2 | content/ 3 | -------------------------------------------------------------------------------- /paper1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadadr/elisp/HEAD/paper1.gif -------------------------------------------------------------------------------- /bibliothek.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadadr/elisp/HEAD/bibliothek.png -------------------------------------------------------------------------------- /forecast.el.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadadr/elisp/HEAD/forecast.el.png -------------------------------------------------------------------------------- /docs/website/layouts/partials/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/website/layouts/index.html: -------------------------------------------------------------------------------- 1 | {{ partial "header.html" . }} 2 | 3 | {{ .Content }} 4 | 5 | {{ partial "footer.html" . }} 6 | -------------------------------------------------------------------------------- /docs/website/layouts/_default/single.html: -------------------------------------------------------------------------------- 1 | {{ partial "header.html" . }} 2 | 3 | {{ .Content }} 4 | 5 | {{ partial "footer.html" . }} 6 | -------------------------------------------------------------------------------- /docs/website/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | max-width: 760px; 3 | margin: auto; 4 | font-family: sans-serif; 5 | } 6 | header { 7 | text-align: center; 8 | } 9 | -------------------------------------------------------------------------------- /docs/website/config.toml: -------------------------------------------------------------------------------- 1 | languageCode = "en-gb" 2 | title = "Göktuğ's Elisp Website" 3 | #baseurl = "http://dev.gkayaalp.com/elisp/" 4 | author = "Göktuğ Kayaalp" 5 | uglyURLs = true 6 | disablePathToLower = true 7 | enableRobotsTXT = true 8 | disableKinds = ["taxonomy", "taxonomyTerm"] 9 | canonifyURLs = false 10 | relativeURLs = true 11 | -------------------------------------------------------------------------------- /docs/website/generate.el: -------------------------------------------------------------------------------- 1 | ;; generate.el --- generate input for hugo from Website.org 2 | 3 | (defun y-or-n-p (&rest ignore) nil) 4 | 5 | (require 'ox) 6 | (add-to-list 'load-path "~/co/External/emacs-kaushalmodi-ox-hugo") 7 | (require 'ox-hugo) 8 | 9 | (cd (getenv "ORGSRCDIR")) 10 | 11 | (find-file "Website.org") 12 | 13 | (org-hugo-export-wim-to-md t) 14 | 15 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thanks! Please submit a pull request or e-mail a patch. Explain 2 | clearly your changes and the rationale for them, and include a clear 3 | commit message, prefixed with the relevant filename. 4 | 5 | Please write your commit message as in the example below: 6 | 7 | file-name.el: imperative-mood summary of changes 8 | 9 | Optionally further explain the change. 10 | 11 | -------------------------------------------------------------------------------- /docs/website/layouts/_default/list.html: -------------------------------------------------------------------------------- 1 | {{ partial "header.html" . }} 2 | 3 | 14 | 15 | {{ partial "footer.html" . }} 16 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: cadadr 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: cadadr 7 | liberapay: cadadr 8 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 10 | custom: # Replace with a single custom sponsorship URL 11 | -------------------------------------------------------------------------------- /docs/website/layouts/partials/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{ .Hugo.Generator }} 6 | 7 | {{ .Title }} --- Göktuğ's Elisp Stuff 8 | 9 | 10 | 12 | 13 | 14 |
15 |

Göktuğ's Elisp Stuff

16 |

{{ .Title }}

17 | 26 |
27 |
28 | -------------------------------------------------------------------------------- /docs/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Hi, thanks a lot for considering to contribute to this project! 2 | 3 | Please check if you’ve done the following: 4 | 5 | 1. Write your patches against the `devel` branch, and send your pull 6 | request against it. `master` is for releases. 7 | 8 | 2. Prefix your commit messages’ subject lines with the file name: 9 | 10 | ``` 11 | file.el: the commit message goes here 12 | 13 | Optionally further document your changes. 14 | ``` 15 | 16 | Do **not** end the first line with punctuation, and do **not** 17 | capitalise right after the **colon**. 18 | 19 | 3. In your pull request, document: 20 | - What is the problem your changes solve? **or** 21 | - What is the new feature your changes add? 22 | - How does the changes address the problem / implement the feature? 23 | (Unless it is obvious from the patch.) 24 | 25 | Thanks a lot for your cooperation! 26 | -------------------------------------------------------------------------------- /docs/website/Makefile: -------------------------------------------------------------------------------- 1 | HUGOCMD=hugo 2 | HUGOPTS=--quiet 3 | HUGO_PUBLISHDIR=$(HOME)/co/com.gkayaalp/dev/elisp 4 | export HUGO_PUBLISHDIR 5 | ORGSRCDIR=../.. 6 | export ORGSRCDIR 7 | HEAD!=git rev-parse HEAD 8 | 9 | help: 10 | @echo "Targets:" 11 | @echo " build: build the website" 12 | @echo " generate: generate pages from org source" 13 | @echo " serve: start the build server" 14 | 15 | # FIXME: Do not remove index.xml here, make hugo not create it. 16 | build: generate 17 | rm -rf $(HUGO_PUBLISHDIR)/* &&\ 18 | $(HUGOCMD) $(HUGOPTS) &&\ 19 | rm $(HUGO_PUBLISHDIR)/index.xml 20 | 21 | # FIXME: Any way to not re-export when uptodate? 22 | generate: 23 | emacs --script generate.el 24 | 25 | serve: 26 | cd $(HUGO_PUBLISHDIR)/.. && python -m SimpleHTTPServer 27 | 28 | publish: build 29 | cd $(HUGO_PUBLISHDIR) && git add . \ 30 | && git commit -m "elisp@$(HEAD)" && git push 31 | 32 | .PHONY: build generate serve publish 33 | -------------------------------------------------------------------------------- /ovp-test.org: -------------------------------------------------------------------------------- 1 | #+title: Test file for OVP 2 | 3 | #+BEGIN_SRC elisp :results none 4 | ;; Setup: 5 | (setq org-list-allow-alphabetical t) 6 | (org-element-update-syntax) 7 | (org-mode) 8 | #+END_SRC 9 | 10 | Pellentesque dapibus suscipit ligula. Donec posuere augue in quam. 11 | Etiam vel tortor sodales tellus ultricies commodo. 12 | 13 | - Suspendisse potenti. Aenean in sem ac leo mollis blandit. Donec 14 | neque quam, 15 | - dignissim in, mollis nec, sagittis eu, wisi. Phasellus lacus. 16 | Etiam 17 | * Dignissim in, mollis nec, sagittis eu, wisi. 18 | * Et mollis nec, sagittis eu, wisi. 19 | 20 | - [X] Alpha 21 | - [ ] Beta 22 | - [ ] Gamma 23 | - [ ] Pseudorandom number generator 24 | 1. [ ] Hello! 25 | 1) [ ] Another test for checkboxes 26 | 27 | - laoreet quam sed arcu. Phasellus at dui in ligula mollis ultricies. 28 | a. Integer placerat tristique nisl. Praesent augue. Fusce commodo. 29 | 30 | - laoreet quam sed arcu. Phasellus at dui in ligula mollis ultricies. 31 | A. Integer placerat tristique nisl. Praesent augue. Fusce commodo. 32 | 33 | - laoreet quam sed arcu. Phasellus at dui in ligula mollis ultricies. 34 | 1. Integer placerat tristique nisl. Praesent augue. Fusce commodo. 35 | 36 | | Vestibulum | convallis | , lorem | | 37 | | a | tempus | semper, | dui | 38 | #+TBLFM: 2 + 2 = 4 39 | 40 | #+BEGIN_EXAMPLE 41 | (defun doctor () 42 | (interactive) 43 | (kill-emacs)) 44 | #+END_EXAMPLE 45 | 46 | 47 | 48 | * TODO dui euismod elit, 49 | [2019-01-24 Prş] 50 | 51 | vitae placerat urna tortor vitae lacus. Nullam libero mauris, 52 | consequat quis, 53 | 54 | #+BEGIN_VERBATIM 55 | varius et, dictum id, arcu. Mauris mollis tincidunt felis. Aliquam 56 | feugiat tellus ut neque. Nulla facilisis, risus a rhoncus fermentum, 57 | #+END_VERBATIM 58 | 59 | - tellus :: tellus lacinia purus, et dictum nunc justo sit amet elit. 60 | -------------------------------------------------------------------------------- /docs/website/Readme.org: -------------------------------------------------------------------------------- 1 | #+title: Hugo configuration for my elisp website. 2 | #+options: toc:nil 3 | #+category: elisp-www 4 | 5 | * Introduction 6 | 7 | This is the configuration for the "Göktuğ's Elisp Stuff" website. 8 | [[https://github.com/kaushalmodi/ox-hugo][ox-hugo]] is used to generate this from the [[https://github.com/cadadr/elisp][source code repository]]. 9 | [[https://gohugo.io][Hugo]] static website generator is used to build the website from the 10 | source files ox-hugo generates. 11 | 12 | * Usage 13 | 14 | This section will be expanded when I will set up deployment. 15 | 16 | ** Building the website 17 | 18 | There is a Makefile that handles all the tasks. 19 | 20 | Build requirements: 21 | 22 | - GNU Emacs 23 | - Org mode 24 | - ox-hugo 25 | - Hugo 26 | - make 27 | - Python 2 (optional, for build server) 28 | 29 | As of writing this document, I use Org 9.1, and GNU Emacs recently 30 | built from master (I usually build once each week), but any recent 31 | version of Emacs should work (not tested!). 32 | 33 | On Debian stable you might want to get Hugo from the unstable (sid) 34 | branch. For that, you should add sid to apt sources (in 35 | =/etc/apt/sources.list=, [[https://github.com/cadadr/configuration/blob/b087649150f507e24e83ded3455de0bf512996bd/system/debian/etc/apt/sources.list][example]]), and set package =hugo= to be 36 | installed from unstable (in =/etc/apt/preferences=, [[https://github.com/cadadr/configuration/blob/b087649150f507e24e83ded3455de0bf512996bd/system/debian/etc/apt/preferences][example]]). 37 | 38 | Before building, open [[./generate.el]] and edit it to load ox-hugo from 39 | the correct path. Also, control [[./Makefile]] and make sure the paths it 40 | sets and exports are all correct. Then, proceed to running make. 41 | 42 | The default make rule will print out a help message and do nothing. 43 | In order to build the website, run ~make build~. In order to run the 44 | build server, run ~make serve~. This uses the ~SimpleHTTPServer~ 45 | module from Python 2. 46 | 47 | * License 48 | 49 | This package is licensed under the terms of GNU GPLv3. See the 50 | [[./COPYING]] file. 51 | 52 | * Contributing 53 | 54 | Any fixes or suggestions are welcome, just open an issue on the [[https://github.com/cadadr/elisp-www][GitHub 55 | repo]]. Note that the source of the website content is not in this 56 | repo, see the [[https://github.com/cadadr/elisp][elisp]] repo instead. 57 | 58 | * Issues 59 | ** TODO Add a proper footer 60 | ** TODO Fix feeds 61 | - Link is a relative url, guess baseURL needs to be set. 62 | -------------------------------------------------------------------------------- /dollar.el: -------------------------------------------------------------------------------- 1 | ;;; dollar.el --- Shorthand lambda notation -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2018, 2019, 2023 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Keywords: lisp 7 | ;; Version: 0.2 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#dollar-el 9 | ;; Package-Requires: ((emacs "25")) 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | 25 | 26 | ;;; Commentary: 27 | 28 | ;; This package provides a macro named $ where in its body symbols in 29 | ;; the form $N where N is a positive integer are to stand for 30 | ;; positional arguments to the generated lambda. 31 | 32 | ;; If the car of the body is a vector though, that vector becomes the 33 | ;; argument list of the new lambda. 34 | 35 | 36 | 37 | ;;; Code: 38 | (require 'seq) 39 | (require 'dash) 40 | 41 | ;; Exclude quoted expressions from search. 42 | ;; cf. https://github.com/cadadr/elisp/issues/43 43 | (defun $--eliminate-quoted (expr) 44 | (cond 45 | ((and (consp expr) 46 | (eq (car expr) 'quote)) 47 | nil) 48 | ((consp expr) 49 | (cons ($--eliminate-quoted (car expr)) 50 | ($--eliminate-quoted (cdr expr)))) 51 | (t 52 | expr))) 53 | 54 | (defun $--find-args (seq) 55 | (seq-sort 56 | (lambda (sym1 sym2) 57 | (< (string-to-number (substring (symbol-name sym1) 1)) 58 | (string-to-number (substring (symbol-name sym2) 1)))) 59 | (seq-filter 60 | (lambda (x) 61 | (and (symbolp x) 62 | (equal 0 (string-match "\\$[0-9]+" (symbol-name x))))) 63 | (seq-uniq 64 | (-flatten 65 | ($--eliminate-quoted seq)))))) 66 | 67 | (defmacro $ (&rest body) 68 | "Shortcut for lambdas. 69 | 70 | Inside this form symbols in the form $N where N is a positive 71 | integer are to stand for positional arguments to the generated 72 | lambda. 73 | 74 | If the car of the BODY is a vector though, that vector becomes 75 | the argument list of the new lambda. 76 | 77 | Within the body, $_ stands for arguments not used within the 78 | body, i.e. the argument list is the N args used within the body 79 | plus \"&rest $_\"; $* contains the entire argument list, 80 | including what $_ matches, as a cons cell whose car is a vector 81 | of positional arguments and whose cdr is the value of $_." 82 | (let ((head (car body)) 83 | (tail (cdr body)) 84 | args the-body) 85 | (if (vectorp head) 86 | ;; Convert it to a list. 87 | (setf args (seq-into head 'list) 88 | the-body tail) 89 | (setf args ($--find-args body) 90 | the-body body)) 91 | `(lambda 92 | (,@args &rest $_) 93 | (let (($* (cons (vector ,@args) $_))) 94 | ,@the-body)))) 95 | 96 | 97 | 98 | ;;; Footer: 99 | 100 | (provide 'dollar) 101 | ;;; dollar.el ends here 102 | -------------------------------------------------------------------------------- /gk-greek.el: -------------------------------------------------------------------------------- 1 | ;;; gk-greek.el --- Input method for modern Greek. -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2016-2019 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Keywords: input, greek 7 | ;; Version: 1.5 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#gk-greek-el 9 | 10 | ;; Permission is hereby granted, free of charge, to any person 11 | ;; obtaining a copy of this software and associated documentation 12 | ;; files (the "Software"), to deal in the Software without 13 | ;; restriction, including without limitation the rights to use, copy, 14 | ;; modify, merge, publish, distribute, sublicense, and/or sell copies 15 | ;; of the Software, and to permit persons to whom the Software is 16 | ;; furnished to do so, subject to the following conditions: 17 | 18 | ;; The above copyright notice and this permission notice shall be 19 | ;; included in all copies or substantial portions of the Software. 20 | 21 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | ;; SOFTWARE. 29 | 30 | ;;; Commentary: 31 | 32 | ;; Input method that converts modern Greek latinisation into Greek 33 | ;; alphabet. 34 | 35 | ;; 'x' is for the 'χ', 'ks' is for the 'ξ', 'v' is for 'β'. ';' adds 36 | ;; the accent mark. Phonologically similar letters are used for 37 | ;; diphongs and common consonant clusters, ie 'b' writes 'μπ', 'j' 38 | ;; writes 'αι', 'B' writes 'Μπ', and 'B;' writes 'ΜΠ'. Space, 39 | ;; punctuation and '#' after small sigma writes word-final sigma, 40 | ;; i.e. 'ς'. 41 | 42 | ;;; Code: 43 | (require 'quail) 44 | (quail-define-package 45 | "greek-translit-gk" "Greek transliteration (gk)" "ιγκ" nil 46 | "A transliteration scheme for Greek characters.") 47 | 48 | (quail-define-rules 49 | ("a" ?α) ("A" ?Α) 50 | ("a;" ?ά) ("A;" ?Ά) 51 | ("a#" ?α) ("A;" ?Α) 52 | ("af" ["αυ"]) ("Af" ["Αυ"]) ("AF" ["ΑΥ"]) 53 | ("af;" ["αύ"]) ("Af;" ["Αύ"]) ("AF;" ["ΑΎ"]) 54 | ("af#" ["αυ"]) ("Af#" ["Αυ"]) ("AF#" ["ΑΥ"]) 55 | ("av" ["αυ"]) ("Av" ["Αυ"]) ("AV" ["ΑΥ"]) 56 | ("av;" ["αύ"]) ("Av;" ["Αύ"]) ("AV;" ["ΑΎ"]) 57 | ("av#" ["αυ"]) ("Av#" ["Αυ"]) ("AV#" ["ΑΥ"]) 58 | ("a#" ?α) ("A;" ?Α) 59 | ("v" ?β) ("V" ?Β) 60 | ("g" ?γ) ("G" ?Γ) 61 | ("d" ?δ) ("D" ?Δ) 62 | ("e" ?ε) ("E" ?Ε) 63 | ("e;" ?έ) ("E;" ?Έ) 64 | ("e#" ?ε) ("E#" ?Ε) 65 | ("ef" ["ευ"]) ("Ef" ["Ευ"]) ("EF" ["ΕΥ"]) 66 | ("ef;" ["εύ"]) ("Ef;" ["Εύ"]) ("EF;" ["ΕΎ"]) 67 | ("ef#" ["ευ"]) ("Ef#" ["Ευ"]) ("EF#" ["ΕΥ"]) 68 | ("ev" ["ευ"]) ("Ev" ["Ευ"]) ("EV" ["ΕΥ"]) 69 | ("ev;" ["εύ"]) ("Ev;" ["Εύ"]) ("EV;" ["ΕΎ"]) 70 | ("ev#" ["ευ"]) ("Ev#" ["Ευ"]) ("EV#" ["ΕΥ"]) 71 | ("z" ?ζ) ("Z" ?Ζ) 72 | ("h" ?η) ("H" ?Η) 73 | ("h;" ?ή) ("H;" ?Ή) 74 | ("h#" ?η) ("H#" ?Η) 75 | ("th" ?θ) ("Th" ?Θ) ("TH" ?Θ) 76 | ("i" ?ι) ("I" ?Ι) 77 | ("i;" ?ί) ("I;" ?Ί) 78 | ("i#" ?ι) ("I#" ?Ι) 79 | ("k" ?κ) ("K" ?Κ) 80 | ("k#" ?κ) ("K#" ?Κ) 81 | ("l" ?λ) ("L" ?Λ) 82 | ("m" ?μ) ("M" ?Μ) 83 | ("n" ?ν) ("N" ?Ν) 84 | ("ks" ?ξ) ("Ks" ?Ξ) ("KS" ?Ξ) 85 | ("o" ?ο) ("O" ?Ο) 86 | ("o;" ?ό) ("O;" ?Ό) 87 | ("o#" ?ο) ("O#" ?Ο) 88 | ("p" ?π) ("P" ?Π) 89 | ("r" ?ρ) ("r" ?ρ) 90 | ("s" ?σ) ("S" ?Σ) 91 | ("s " ["ς "]) 92 | ("s." ["ς."]) 93 | ("s," ["ς,"]) 94 | ("s;" ["ς;"]) 95 | ("s:" ["ς:"]) 96 | ("s!" ["ς!"]) 97 | ("s#" ["ς"]) 98 | ("t" ?τ) ("T" ?Τ) 99 | ("y" ?υ) ("Y" ?Υ) 100 | ("y;" ?ύ) ("Y;" ?Ύ) 101 | ("y#" ?υ) ("Y#" ?Υ) 102 | ("u" ["ου"]) ("U" ["ΟΥ"]) 103 | ("u;" ["ού"]) ("U;" ["ΟΎ"]) 104 | ("u#" ["ου"]) ("U#" ["ΟΥ"]) 105 | ("f" ?φ) ("F" ?Φ) 106 | ("x" ?χ) ("X" ?Χ) 107 | ("ps" ?ψ) ("Ps" ?Ψ) ("PS" ?Ψ) 108 | ("w" ?ω) ("W" ?Ω) 109 | ("w;" ?ώ) ("W;" ?Ώ) 110 | ("w#" ?ω) ("W#" ?Ω) 111 | ;; Use unused keys for some diphthongs. 112 | ("b" ["μπ"]) ("B" ["Μπ"]) ("B;" ["ΜΠ"]) 113 | ("j" ["αι"]) ("J" ["Αι"]) ("J;" ["ΑΙ"]) 114 | ("q" ["γγ"]) ("Q" ["Γγ"]) ("Q;" ["ΓΓ"]) 115 | ("c" ["γκ"]) ("C" ["Γκ"]) ("C;" ["ΓΚ"])) 116 | 117 | ;;; Footer: 118 | (provide 'gk-greek) 119 | ;;; gk-greek.el ends here 120 | -------------------------------------------------------------------------------- /Website.org: -------------------------------------------------------------------------------- 1 | #+title: Göktuğ's Elisp Stuff website source 2 | #+latex_class: gk-article 3 | 4 | This file is the source for the website for this repo, using Kaushal 5 | Modi's [[https://github.com/kaushalmodi/ox-hugo][ox-hugo]] package. Here is the setup for that. 6 | 7 | #+HUGO_BASE_DIR: ~/co/elisp/docs/website 8 | 9 | * Website 10 | :PROPERTIES: 11 | :CUSTOM_ID: website 12 | :END: 13 | 14 | ** About 15 | :PROPERTIES: 16 | :EXPORT_FILE_NAME: about 17 | :EXPORT_HUGO_SECTION: / 18 | :CUSTOM_ID: about 19 | :EXPORT_OPTIONS: toc:nil 20 | :END: 21 | 22 | This is the website for [[https://www.gkayaalp.com][Göktuğ]]'s Emacs Lisp stuff (what do we really 23 | call them? features, programs, modules, packages; well...). This 24 | website is generated from the repository's [[https://github.com/cadadr/elisp/blob/master/Readme.org][readme]] file, using the 25 | [[https://github.com/kaushalmodi/ox-hugo][ox-hugo]] package, and the [[https://gohugo.io][Hugo]] static website generator. 26 | 27 | ** Homepage 28 | :PROPERTIES: 29 | :EXPORT_FILE_NAME: _index 30 | :EXPORT_HUGO_SECTION: / 31 | :CUSTOM_ID: homepage 32 | :EXPORT_OPTIONS: toc:t 33 | :END: 34 | 35 | *** Introduction 36 | 37 | This is the website for [[https://www.gkayaalp.com][Göktuğ]]'s Emacs Lisp stuff. Some of the 38 | programs here are published on [[https://melpa.org][Melpa]]. All of the source code is 39 | available at the [[https://github.com/cadadr/elisp][source code repository]]. 40 | 41 | *** What's here 42 | 43 | #+INCLUDE: "./Readme.org::#whatshere" :only-contents t 44 | 45 | *** Contributing 46 | 47 | See the [[https://github.com/cadadr/elisp][source code repository]] in order to find out about how to 48 | contribute. 49 | 50 | ** News 51 | :PROPERTIES: 52 | :EXPORT_HUGO_SECTION: news 53 | :CUSTOM_ID: news 54 | :END: 55 | 56 | *** Org variable pitch now supports =org-list-allow-alphabetical= 57 | :PROPERTIES: 58 | :EXPORT_FILE_NAME: ovp-alpha-lists 59 | :EXPORT_DATE: "2019-01-28" 60 | :END: 61 | 62 | With [[https://github.com/cadadr/elisp/issues/38][issue#38]] fixed, OVP now supports Org mode plain lists with 63 | prefixes like =A.=, =a.=, =a)=, =A)=, and with the prefix =*= for 64 | levels except the first level. 65 | 66 | *** Move website sources into the elisp repository 67 | :PROPERTIES: 68 | :EXPORT_FILE_NAME: move-website-to-elisp-repo 69 | :EXPORT_DATE: "2019-01-28" 70 | :END: 71 | 72 | Now, with commit [[https://github.com/cadadr/elisp/commit/ac2da41ca4854e7e5ea10697ec9f989f0f74d17e][ac2da41]], website sources live under the [[https://github.com/cadadr/elisp/tree/devel/docs/website][docs/website]] 73 | tree. This was done in order to ease up adding new posts, which 74 | involved three repositories before this move. 75 | 76 | *** New domain: =dev.gkayaalp.com= 77 | :PROPERTIES: 78 | :EXPORT_FILE_NAME: new-domain 79 | :EXPORT_DATE: "2019-01-24" 80 | :END: 81 | 82 | Started using a custom domain name for this website in order to remove 83 | the direct links to Github. Who knows where Github will end up now; 84 | it’s all smooth these days but now that the acquisition happened, 85 | there always is a chance that things go rogue. 86 | 87 | *** =pass-listing= gets a rename command 88 | :PROPERTIES: 89 | :EXPORT_FILE_NAME: pass-rename 90 | :EXPORT_DATE: "2018-11-27" 91 | :END: 92 | 93 | Commit @@html:30119002db@@ 95 | adds a rename command to pass-listing, bound to =R= by default. 96 | 97 | *** New website for my Elisp programs 98 | :PROPERTIES: 99 | :EXPORT_FILE_NAME: new-website 100 | :EXPORT_DATE: "2018-04-22" 101 | :END: 102 | 103 | This is the new website for my Elisp stuff. Here you can find 104 | up-to-date package summaries and , follow [[/news.html][updates]] on programs 105 | published here. Descriptions here will always be up-to-date thanks to 106 | [[https://github.com/kaushalmodi/ox-hugo][ox-hugo]] package, with which I can reuse data from the readme file of 107 | the elisp repo. Huge thanks to Kaushal Modi for authoring that 108 | package and for suggesting it to me. [[https://gohugo.io][Hugo]] is not the most pleasant 109 | static site generator I worked with (way too complex, hard to 110 | customise, bad docs, weird limitations), but it's worth it given how 111 | useful ox-hugo is. 112 | 113 | Source code of this website is split among the content source [[https://github.com/cadadr/elisp/blob/master/Website.org][here]], 114 | and the Hugo setup [[https://github.com/cadadr/elisp-www][here]]. 115 | -------------------------------------------------------------------------------- /.hgtags: -------------------------------------------------------------------------------- 1 | 0c9bc05ab52d70109f55cab0a2d6e5d7fb02b975 paper-v0.1.0 2 | 17661b06d3ed2fe11e6ce1e27ad91e5349df6666 forecast-v0.6.3 3 | 2e8750ad221e0a9ff1d61814fcad628727418821 forecast-v0.1.5 4 | 3424373a51b64009637f92b8a24d43b12ef1080a forecast-v0.5.0 5 | 363f7310cbaccfdd6b84b845ef28f22ee60430a2 forecast-v0.2.0 6 | 38ece608181b3f741b952a35c3a8d5a543c9c7d8 forecast-v0.1.7 7 | 4b0d59998449b8d0d2a706b54088196577dc5d24 forecast-v0.3.0 8 | 4e32ba5cc27a836d072aba9d01c9a624670a00a8 paper-v1.0.0 9 | 74cf8c5b2ebb5c254843e03547a37237db7a329f forecast-v0.1.9 10 | 75ba7c115432fe03a4d3f4b235b7dab1c9307a7b forecast-v0.1.3 11 | 7982db6060d9ea83316be82bd173339f42a13857 forecast-v0.4.1 12 | 7b22d62031612dbab802995ff7c694af834dfe24 forecast-v0.4.0 13 | 7b962c7cf6f4abc72bf1d48c2cb3612c9ade9132 forecast-v0.1.1 14 | 88bc111cb59f03a6843d20aaef52c388be5a7166 forecast-v0.6.4 15 | 94ce1f83529b76cc0bc5ff72ac37a8dbf7f0ab2b forecast-v0.6.0 16 | 9885ef1c1c974eb95fae680184abb7a2e7892a6e forecast-v0.6.2 17 | a1c700f8151c759434ec3249a414cad68d81adf3 forecast-v0.1.6 18 | a53bc8b265e5060e272cdba941af173ccfe3bccf forecast-v0.5.1 19 | aa4bb2b4bd5f9ec9861c8eb408093ee18068bd0f paper-v0.2.0 20 | acac398e23ff4e368a4ec15c86450c2ff53568a3 forecast-v0.1.2 21 | c05b2ee285c99b0b29399ac3820471d651c81879 pass-listing-v0.1.0 22 | c817026fd6675975d277f8b10136f688c50e93b3 forecast-v0.1.8 23 | cea040b93ffb4e957132e7849f0f19419212f231 forecast-v0.6.1 24 | d12ea245e20a38f4636c421226df06d658c4f42d forecast-v0.3.1 25 | e57bd13035536e64dbc2fa3d5b7920ba45eacae4 forecast-v0.1.4 26 | ef30c4dea275b942f7be0536671f2e6d02a06593 forecast-v0.1.0 27 | f2611847aba2629567f83b19bc0b93ebc56ff9ad forecast-v0.5.2 28 | c05b2ee285c99b0b29399ac3820471d651c81879 pass-listing-v0.1.0 29 | 0000000000000000000000000000000000000000 pass-listing-v0.1.0 30 | 4e32ba5cc27a836d072aba9d01c9a624670a00a8 paper-v1.0.0 31 | 0000000000000000000000000000000000000000 paper-v1.0.0 32 | aa4bb2b4bd5f9ec9861c8eb408093ee18068bd0f paper-v0.2.0 33 | 0000000000000000000000000000000000000000 paper-v0.2.0 34 | 0c9bc05ab52d70109f55cab0a2d6e5d7fb02b975 paper-v0.1.0 35 | 0000000000000000000000000000000000000000 paper-v0.1.0 36 | 88bc111cb59f03a6843d20aaef52c388be5a7166 forecast-v0.6.4 37 | 0000000000000000000000000000000000000000 forecast-v0.6.4 38 | 17661b06d3ed2fe11e6ce1e27ad91e5349df6666 forecast-v0.6.3 39 | 0000000000000000000000000000000000000000 forecast-v0.6.3 40 | 9885ef1c1c974eb95fae680184abb7a2e7892a6e forecast-v0.6.2 41 | 0000000000000000000000000000000000000000 forecast-v0.6.2 42 | cea040b93ffb4e957132e7849f0f19419212f231 forecast-v0.6.1 43 | 0000000000000000000000000000000000000000 forecast-v0.6.1 44 | 94ce1f83529b76cc0bc5ff72ac37a8dbf7f0ab2b forecast-v0.6.0 45 | 0000000000000000000000000000000000000000 forecast-v0.6.0 46 | f2611847aba2629567f83b19bc0b93ebc56ff9ad forecast-v0.5.2 47 | 0000000000000000000000000000000000000000 forecast-v0.5.2 48 | a53bc8b265e5060e272cdba941af173ccfe3bccf forecast-v0.5.1 49 | 0000000000000000000000000000000000000000 forecast-v0.5.1 50 | 3424373a51b64009637f92b8a24d43b12ef1080a forecast-v0.5.0 51 | 0000000000000000000000000000000000000000 forecast-v0.5.0 52 | 7982db6060d9ea83316be82bd173339f42a13857 forecast-v0.4.1 53 | 0000000000000000000000000000000000000000 forecast-v0.4.1 54 | 7b22d62031612dbab802995ff7c694af834dfe24 forecast-v0.4.0 55 | 0000000000000000000000000000000000000000 forecast-v0.4.0 56 | d12ea245e20a38f4636c421226df06d658c4f42d forecast-v0.3.1 57 | 0000000000000000000000000000000000000000 forecast-v0.3.1 58 | 4b0d59998449b8d0d2a706b54088196577dc5d24 forecast-v0.3.0 59 | 0000000000000000000000000000000000000000 forecast-v0.3.0 60 | 363f7310cbaccfdd6b84b845ef28f22ee60430a2 forecast-v0.2.0 61 | 0000000000000000000000000000000000000000 forecast-v0.2.0 62 | 74cf8c5b2ebb5c254843e03547a37237db7a329f forecast-v0.1.9 63 | 0000000000000000000000000000000000000000 forecast-v0.1.9 64 | c817026fd6675975d277f8b10136f688c50e93b3 forecast-v0.1.8 65 | 0000000000000000000000000000000000000000 forecast-v0.1.8 66 | 38ece608181b3f741b952a35c3a8d5a543c9c7d8 forecast-v0.1.7 67 | 0000000000000000000000000000000000000000 forecast-v0.1.7 68 | a1c700f8151c759434ec3249a414cad68d81adf3 forecast-v0.1.6 69 | 0000000000000000000000000000000000000000 forecast-v0.1.6 70 | 2e8750ad221e0a9ff1d61814fcad628727418821 forecast-v0.1.5 71 | 0000000000000000000000000000000000000000 forecast-v0.1.5 72 | e57bd13035536e64dbc2fa3d5b7920ba45eacae4 forecast-v0.1.4 73 | 0000000000000000000000000000000000000000 forecast-v0.1.4 74 | 75ba7c115432fe03a4d3f4b235b7dab1c9307a7b forecast-v0.1.3 75 | 0000000000000000000000000000000000000000 forecast-v0.1.3 76 | acac398e23ff4e368a4ec15c86450c2ff53568a3 forecast-v0.1.2 77 | 0000000000000000000000000000000000000000 forecast-v0.1.2 78 | 7b962c7cf6f4abc72bf1d48c2cb3612c9ade9132 forecast-v0.1.1 79 | 0000000000000000000000000000000000000000 forecast-v0.1.1 80 | ef30c4dea275b942f7be0536671f2e6d02a06593 forecast-v0.1.0 81 | 0000000000000000000000000000000000000000 forecast-v0.1.0 82 | -------------------------------------------------------------------------------- /Readme.org: -------------------------------------------------------------------------------- 1 | #+title: Göktuğ's Emacs Lisp Bits 2 | #+options: toc:t num:nil tasks:todo 3 | #+category: elisp 4 | 5 | * Introduction 6 | :PROPERTIES: 7 | :CUSTOM_ID: introduction 8 | :END: 9 | 10 | This repository is a swarm for all the Elisp stuff I published. Most 11 | files will have licence information in it, which don't are licenced 12 | under the MIT licence, whose text is available in the LICENSE file. 13 | 14 | * What's here? 15 | :PROPERTIES: 16 | :CUSTOM_ID: whatshere 17 | :END: 18 | 19 | Below is a listing of all the programs here: 20 | 21 | ** =paper-theme.el= 22 | :PROPERTIES: 23 | :CUSTOM_ID: paper 24 | :END: 25 | «Paper» is a little, minimal emacs theme that is meant to be simple 26 | and consistent. 27 | 28 | It was first intended to resemble the look of paper, but has diverged 29 | from that objective. Still, though, I keep calling it Paper, as I 30 | like that name. 31 | 32 | Paper uses a small colour palette over all the elements. Org headings 33 | are specially treated with a palette of equidistant colours. The 34 | colours and heading font sizes are calculated using base and factor 35 | values which can be edited. See source. 36 | 37 | It's most adapted for ELisp-Org users, as I'm one such user, though it 38 | works fine with Markdown, Textile, Python, JavaScript, Html, Diff, 39 | Magit, etc. 40 | 41 | [[./paper1.gif]] 42 | 43 | ** =pass-listing.el= 44 | :PROPERTIES: 45 | :CUSTOM_ID: pass-listing-el 46 | :END: 47 | «pass-listing» is a simple frontend to the [[https://www.passwordstore.org/][pass]] utility. It uses the 48 | functions from =password-store.el=. 49 | 50 | ** =gk-unilat.el= 51 | :PROPERTIES: 52 | :CUSTOM_ID: gk-unilat-el 53 | :END: 54 | «gk-unilat» is a unified input method for European variants of the 55 | Latin alphabet. 56 | 57 | It aims to provide comprehensive support for typing characters found 58 | in different European versions of the Latin alphabet, in a unified, 59 | predictable way. 60 | 61 | ** =gk-greek.el= 62 | :PROPERTIES: 63 | :CUSTOM_ID: gk-greek-el 64 | :END: 65 | «gk-greek» is a transliterating input method for modern Greek. 66 | 67 | Translates input in Greek latinization into Greek alphabet. Mappings 68 | are based on vocal correspondence and common modern transliteration. 69 | 70 | ** =dollar.el= 71 | :PROPERTIES: 72 | :CUSTOM_ID: dollar-el 73 | :END: 74 | This package provides a macro named $ where in its body symbols in the 75 | form $N where N is a positive integer are to stand for positional 76 | arguments to the generated lambda. 77 | 78 | If the car of the body is a vector though, that vector becomes the 79 | argument list of the new lambda. 80 | 81 | Some examples: 82 | 83 | #+BEGIN_SRC elisp 84 | ($ (message "Hello, %s" $1)) 85 | (funcall ($ (* $1 $1)) 2) 86 | (reduce ($ [a b] (concat a b)) (list "hel" "lo")) 87 | #+END_SRC 88 | 89 | * Obsolete packages 90 | ** =forecast.el= 91 | :PROPERTIES: 92 | :CUSTOM_ID: forecast-el 93 | :END: 94 | 95 | *** Obsoletion notice 96 | 97 | /DarkSky.net has been acquired and eventually closed by Apple. Because 98 | I no longer actively use this package, I have not found the time and 99 | energy to port it to something else. See the contents of [[https://github.com/cadadr/elisp/issues/48][issue #48 on 100 | Github]] for reimplementation ideas. If you wish to take over the 101 | package and port it; please open an issue once you have a working 102 | port, I will help with handing the package over on MELPA./ 103 | 104 | *** Package description 105 | 106 | «forecast.el» is a weather forecast report generator, currently using 107 | data from [[https://darksky.net][Dark Sky]] (but I plan to add other backends in the future). 108 | 109 | * Unmaintained packages 110 | 111 | ** Non-maintenance notice 112 | 113 | /The following packages are no longer maintained by me. If you wish to 114 | take over their development, please create a new repository to do so, 115 | and if you want to take over the MELPA package, create an issue on 116 | Github and I will help with that./ 117 | 118 | ** =org-variable-pitch.el= 119 | :PROPERTIES: 120 | :CUSTOM_ID: ovp 121 | :END: 122 | «org-variable-pitch.el» is a minor mode that enables 123 | ‘variable-pitch-mode’ in the current Org-mode buffer, and sets some 124 | particular faces up so that they are are rendered in fixed-width font. 125 | Also, indentation, list bullets and checkboxes are displayed in 126 | monospace, in order to keep the shape of the outline. 127 | 128 | ** =bsdpkg.el= 129 | :PROPERTIES: 130 | :CUSTOM_ID: bsdpkg-el 131 | :END: 132 | «bsdpkg» is an Emacs interface to FreeBSD =pkg(1)=. It's planned to 133 | genericise the package to support all *BSD packaging systems, and the 134 | module is written with that sort of extensibility in mind. 135 | 136 | #+BEGIN_QUOTE 137 | This is experimental, and kind-of obsoleted as I don't use BSD at 138 | the moment. I'd be happy to accept changes or to hand it over if 139 | anybody will be interested. 140 | #+END_QUOTE 141 | 142 | ** =bibliothek.el= 143 | :PROPERTIES: 144 | :CUSTOM_ID: bibliothek-el 145 | :END: 146 | «bibliothek.el» is a personal PDF library manager. Presently it only 147 | displays a concatenated tabular list of PDF files from many locations, 148 | and allows to open the files or view metadata from that list. Find 149 | below a screenshot of the default view. I intend to add some 150 | functionality for moving PDF files around and editing the metadata. 151 | 152 | # [[./bibliothek.png]] 153 | 154 | * Contributing 155 | :PROPERTIES: 156 | :CUSTOM_ID: contributing 157 | :EXPORT_FILE_NAME: docs/CONTRIBUTING 158 | :EXPORT_OPTIONS: toc:nil title:nil author:nil 159 | :END: 160 | 161 | # Export: C-c C-e C-s m m 162 | 163 | Thanks for your contribution! Please submit a pull request or e-mail a 164 | patch. Explain clearly your changes and the rationale for them, and 165 | include a clear commit message, prefixed with the relevant filename. 166 | 167 | Please base your changes on the =devel= branch. 168 | 169 | Please write your commit message as in the example below: 170 | 171 | #+BEGIN_EXAMPLE 172 | file-name.el: imperative-mood summary of changes 173 | 174 | Optionally further explain the change. 175 | #+END_EXAMPLE 176 | 177 | * Issues 178 | Please mention the relevant filename in your issue title. 179 | -------------------------------------------------------------------------------- /gk-unilat.el: -------------------------------------------------------------------------------- 1 | ;;; gk-unilat.el -- Unified input method for variants of the Latin alphabet. -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2016, 2018, 2019, 2020, 2021, 2022 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Keywords: input 7 | ;; Version: 3.0 8 | ;; URL: https://github.com/cadadr/elisp/#gk-unilatel 9 | 10 | ;; Permission is hereby granted, free of charge, to any person 11 | ;; obtaining a copy of this software and associated documentation 12 | ;; files (the "Software"), to deal in the Software without 13 | ;; restriction, including without limitation the rights to use, copy, 14 | ;; modify, merge, publish, distribute, sublicense, and/or sell copies 15 | ;; of the Software, and to permit persons to whom the Software is 16 | ;; furnished to do so, subject to the following conditions: 17 | 18 | ;; The above copyright notice and this permission notice shall be 19 | ;; included in all copies or substantial portions of the Software. 20 | 21 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | ;; SOFTWARE. 29 | 30 | 31 | ;;; Commentary: 32 | 33 | ;; This is the Universal Latin Emacs Input Method. 34 | 35 | ;; It aims to provide comprehensive support for typing characters 36 | ;; found in different European versions of the Latin alphabet, in a 37 | ;; unified, predictable way. 38 | 39 | ;; See [ C-h I unilat-gk ] for a comprehensive listing of keymaps, but 40 | ;; also the definitions below as they are logically grouped. 41 | 42 | ;; See `gk-unilat-languages' for a list of intentionally supported 43 | ;; languages. 44 | 45 | ;; Contributions are welcome, please follow the instructions at 46 | ;; https://github.com/cadadr/elisp/#contributing 47 | 48 | 49 | 50 | ;;; Code: 51 | (require 'seq) 52 | (require 'quail) 53 | 54 | ;; Keep this sorted alphabetically 55 | (defconst gk-unilat-languages 56 | (list "Dutch" "English" "French" "German" "Italian" "Kurdish" 57 | "Latin" "Norwegian" "Portuguese" "Spanish" "Swedish" 58 | "Turkish" "UTF-8" "Welsh") 59 | "List of languages that `unilat-gk' input-method supports.") 60 | 61 | 62 | (defvar gk-unilat-escape-char ?# 63 | "Character to escape an active composition. 64 | 65 | When this character is entered, the current visible letter is 66 | inserted and the sequence is no longer available for Quail 67 | modifications.") 68 | 69 | 70 | (defvar gk-unilat-undo-char ? 71 | "Character to undo a composition. 72 | 73 | When a composition is active and this character is entered, the 74 | most recent modification is undone.") 75 | 76 | 77 | 78 | 79 | ;;; Unified latin input method: 80 | (quail-define-package 81 | "unilat-gk" "Universal Latin (GK)" "☉" nil 82 | "A universal Latin input method. 83 | 84 | The Unilat-GK input method is meant to help with entering text in 85 | most, and ideally all, Latin-based scripts. 86 | 87 | The 26 Latin letters insert themselves. For those that can 88 | receive diacritics, Unilat-GK presents mnemonic key combinations 89 | to insert them. 90 | 91 | Some example conversions: 92 | C;ekoslovakyali;lasti;ramadi;klari;mi;zdan mi;si;ni;z? 93 | => Çekoslovakyalılaştıramadıklarımızdan mısınız? 94 | Na ve/spera de na~o partir nunca 95 | => Na véspera de não partir nunca 96 | Tu bi Kurdi^ diaxivi^? 97 | => Tu bi kurdî diaxivî? 98 | L'histoire se re/pe\te. 99 | => L'histoire se répète. 100 | I no$d skal du la£re dine venner a0 kenne. 101 | => I nød skal du lære dine venner å kenne. 102 | 103 | There are cases where this can get complicated, for example when 104 | typing a slash between two words or a colon after a vowel, in 105 | which case just typing ahead when Unilat-GK is active will 106 | produce a letter with a diacritic instead of the intended 107 | sequence. 108 | 109 | To remedy this, there are two mechanisms: escaping, and undoing. 110 | 111 | The escape key, determined by ‘gk-unilat-escape-char’, terminates 112 | the active letter’s composition, inserting what you see on the 113 | screen into the text without any further changes or undoing. For 114 | example, assuming default settings are active, observe: 115 | 116 | here/there => heréthere vs. here#/there => here/there 117 | see: => seë vs. see#: => see: 118 | 119 | The undo key, determined by ‘gk-unilat-undo-char’, instead, 120 | undoes the last modification to the current letter and inserts 121 | the letter without that modification into the buffer. Observe: 122 | 123 | here/there => heréthere vs. here//there => here/there 124 | aks;am => akşam vs. aks;am => aksam 125 | 126 | The languages Unilat-GK supports are hard to pin down, as many 127 | world languages use some variation of the Latin alphabet and I 128 | only have familiarity with the orthography of a subset of them. 129 | 130 | Thus rather than listing languages it supports, I resort to 131 | enumerating those languages which I intentionally target. See 132 | ‘gk-unilat-languages’ for a list of these. 133 | 134 | ‘gk-unilat-languages’, with possible modifications, can be used 135 | to assign Unilat-GK as the default input method for supported 136 | languages with an Elisp snippet as follows: 137 | 138 | ;; Use ‘unilat-gk’ whenever possible. 139 | \(dolist (lang gk-unilat-languages) 140 | (let* ((env (assoc lang language-info-alist)) 141 | (im (assoc 'input-method env))) 142 | ;; Some language environments may not have an input-method 143 | ;; field, namely English. 144 | (when im 145 | (setcdr im \"unilat-gk\")))) ") 146 | 147 | (defvar gk-unilat--mappings 148 | '( 149 | ;; Turkish I and umlauts, cedillas circumflecis 150 | ("i;" ?ı) ("i;;" ?i) ("o;" ?ö) ("u;" ?ü) ("c;" ?ç) ("g;" ?ğ) ("s;" ?ş) 151 | 152 | ("I;" ?İ) ("I;;" ?I) ("O;" ?Ö) ("U;" ?Ü) ("C;" ?Ç) ("G;" ?Ğ) ("S;" ?Ş) 153 | 154 | ("A^" ?Â) ("E^" ?Ê) ("U^" ?Û) ("I^" ?Î) ("O^" ?Ô) 155 | 156 | ("a^" ?â) ("e^" ?ê) ("i^" ?î) ("u^" ?û) ("o^" ?ô) 157 | 158 | ;; Acute and breve 159 | ("a\\" ?à) ("e\\" ?è) ("i\\" ?ì) ("o\\" ?ò) ("u\\" ?ù) 160 | 161 | ("A\\" ?À) ("E\\" ?È) ("I\\" ?Ì) ("O\\" ?Ò) ("U\\" ?Ù) 162 | 163 | ("a/" ?á) ("e/" ?é) ("i/" ?í) ("o/" ?ó) ("u/" ?ú) 164 | 165 | ("A/" ?Á) ("E/" ?É) ("I/" ?Í) ("O/" ?Ó) ("U/" ?Ú) 166 | 167 | ;; Macron 168 | ("a_" ?ā) ("e_" ?ē) ("i_" ?ī) ("o_" ?ō) ("u_" ?ū) 169 | 170 | ("A_" ?Ā) ("E_" ?Ē) ("I_" ?Ī) ("O_" ?Ō) ("U_" ?Ū) 171 | 172 | ;; Tilde 173 | ("a~" ?ã) ("e~" ?ẽ) ("i~" ?ĩ) ("o~" ?õ) ("u~" ?ũ) ("n~" ?ñ) 174 | 175 | ("A~" ?Ã) ("E~" ?Ẽ) ("I~" ?Ĩ) ("O~" ?Õ) ("U~" ?Ũ) ("N~" ?Ñ) 176 | 177 | ;; Ordinal 178 | ("a&" ?ª) ("o&" ?º) 179 | 180 | ;; Various 181 | ("I:" ?Ï) ("i:" ?ï) ("a:" ?ä) ("A:" ?Ä) ("e:" ?ë) ("E:" ?Ë) ("a0" ?å) 182 | ("A0" ?Å) ("o$" ?ø) ("O$" ?Ø) ("sZ" ?ß) ("o£" ?œ) ("O£" ?Œ) ("a£" ?æ) 183 | ("A£" ?Æ) 184 | 185 | ;; Inclusive language - Italian 186 | ("x;" ?ə) ("X;" ?Ə) ("q;" ?з) ("Q;" ?З))) 187 | 188 | 189 | (defvar gk-unilat--undo-mappings 190 | (mapcar 191 | (lambda (m) 192 | (list (concat (car m) (make-string 1 gk-unilat-undo-char)) 193 | (car (string-to-list (car m))))) 194 | gk-unilat--mappings)) 195 | 196 | 197 | (defvar gk-unilat--escape-mappings 198 | (append 199 | (list (list (format "i;%c" gk-unilat-escape-char) ?ı) 200 | (list (format "I;%c" gk-unilat-escape-char) ?İ)) 201 | (mapcar 202 | (lambda (letter) 203 | (list (format "%c%c" letter gk-unilat-escape-char) letter)) 204 | (seq-uniq 205 | (mapcar 206 | (lambda (m) (aref (car m) 0)) 207 | gk-unilat--mappings))))) 208 | 209 | 210 | (eval 211 | `(quail-define-rules 212 | ,@gk-unilat--mappings 213 | 214 | ,@gk-unilat--undo-mappings 215 | 216 | ,@gk-unilat--escape-mappings)) 217 | 218 | 219 | 220 | ;;; Footer: 221 | (provide 'gk-unilat) 222 | ;;; gk-unilat.el ends here 223 | -------------------------------------------------------------------------------- /pass-listing.el: -------------------------------------------------------------------------------- 1 | ;;; pass-listing.el --- Listing UI for password-store.el -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Maintainer: Göktuğ Kayaalp 7 | ;; Version: 0.1.0 8 | ;; Keywords: unix 9 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#pass-listing-el 10 | ;; Package-Requires: ((password-store "0.1") (emacs "25")) 11 | 12 | ;; This program is free software; you can redistribute it and/or modify 13 | ;; it under the terms of the GNU General Public License as published by 14 | ;; the Free Software Foundation, either version 3 of the License, or 15 | ;; (at your option) any later version. 16 | 17 | ;; This program is distributed in the hope that it will be useful, 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | ;; GNU General Public License for more details. 21 | 22 | ;; You should have received a copy of the GNU General Public License 23 | ;; along with this program. If not, see . 24 | 25 | ;;; Commentary: 26 | 27 | ;; Lists passwords in pass(1), through ‘password-store.el’, where 28 | ;; hitting RET or clicking on an item expands it to show the contents 29 | ;; of the related file in pass database. 30 | 31 | ;; Run M-x passwords to bring it up. 32 | 33 | ;; See docstring for ‘pass-listing-mode’ for more info. 34 | 35 | ;;; Code: 36 | (require 'password-store) 37 | 38 | ;;; The Major Mode: 39 | (defgroup pass-listing '() 40 | "Emacs mode for pass-listing-mode." 41 | :prefix "pass-listing-" 42 | :group 'pass-listing) 43 | 44 | ;;;; Keymap: 45 | (progn ; Make sure C-M-x always gets both... 46 | (defvar pass-listing-mode-map 47 | (let ((map (make-sparse-keymap))) 48 | (define-key map [?g] 'pass-listing-mode) 49 | (define-key map [?q] (lambda () (interactive) (kill-buffer (current-buffer)))) 50 | (define-key map [?d] 'pass-listing--remove) 51 | (define-key map [?e] 'pass-listing--edit) 52 | (define-key map [?i] 'pass-listing--insert) 53 | (define-key map [?+] 'pass-listing--generate) 54 | (define-key map [?r] 'pass-listing--regenerate) 55 | (define-key map [?R] 'pass-listing--rename) 56 | (define-key map [?y] 'pass-listing--copy) 57 | (define-key map [?n] 'widget-forward) 58 | (define-key map [?p] 'widget-backward) 59 | (define-key map [?s] 'isearch-forward) 60 | (define-key map [?/] 'isearch-forward) 61 | map) 62 | "Keymap for `pass-listing-mode'") 63 | 64 | (defvar pass-listing-mode--composed-map 65 | (make-composed-keymap pass-listing-mode-map widget-keymap))) 66 | 67 | (defvar pass-listing--buffer-name 68 | "*Passwords*" 69 | "Base buffer name for `pass-listing-mode'.") 70 | 71 | ;;;; Mode definition: 72 | (defvar-local pass-listing--passwords nil) 73 | (defvar-local pass-listing--marked nil) 74 | (defvar-local pass-listing--open nil) 75 | 76 | (define-derived-mode pass-listing-mode 77 | special-mode "Passwords" 78 | "Expandable list UI for password-store. 79 | \\ 80 | 81 | List all passwords, one per line, where hitting 82 | \\[widget-button-press] on a line inserts below that line the 83 | contents of the related file.\n 84 | 85 | Keybindings for `pass-listing-mode':\n 86 | \\{pass-listing-mode--composed-map}" 87 | :group 'pass-listing 88 | ;;; Setup. 89 | ;; Prepare buffer. 90 | (buffer-disable-undo) 91 | (setq-local default-directory (password-store-dir)) 92 | (setq-local word-wrap t) 93 | (setq-local show-paren-mode nil) 94 | (hl-line-mode) 95 | (use-local-map pass-listing-mode--composed-map) 96 | ;; Insert passwords. 97 | (setq pass-listing--passwords 98 | (sort (password-store-list) 99 | (lambda (s1 s2) (string-collate-lessp s1 s2 nil t)))) 100 | (save-excursion 101 | (let ((inhibit-read-only t)) 102 | (erase-buffer) 103 | (insert 104 | (format 105 | (substitute-command-keys 106 | (concat 107 | "This is the password listing for the database at ‘%s’.\n" 108 | "Hit \\[widget-button-press] or \\[widget-button-click]" 109 | " on any button in order to toggle" 110 | " entries, the contents of the related passwords entry will" 111 | " be listed below the button.\n\n")) 112 | (password-store-dir))) 113 | (dolist (each pass-listing--passwords) 114 | (pass-listing--insert-item each))) 115 | (widget-setup))) 116 | 117 | ;;; Interface: 118 | ;;;###autoload 119 | (defun pass-listing () 120 | "List passwords in pass(1). 121 | See ‘pass-listing-mode’ for more information." 122 | (interactive) 123 | (let ((buffer (get-buffer-create 124 | pass-listing--buffer-name))) 125 | (with-current-buffer buffer 126 | (pass-listing-mode)) 127 | (switch-to-buffer buffer))) 128 | 129 | (defalias 'passwords 'pass-listing) 130 | (defalias 'pass 'pass-listing) 131 | 132 | ;;; Functions: 133 | (defmacro pass-listing--defcmd1 (name docstring &rest body) 134 | "Define a command that acts on an entry. 135 | You will have the lexical variable ‘w’ available to you as the 136 | widget's plist's cdr; see ‘widget-at’. Also, ‘it’ and ‘p’ are 137 | available, the former is the ‘:value’ field from the plist, and 138 | the latter is the value of ‘point’." 139 | (declare (indent defun)) 140 | `(pass-listing--defcmd2 ,name ,docstring 141 | (if-let* ((w (cdr (widget-at (point))))) 142 | (let ((it (plist-get w :value)) 143 | (p (point))) 144 | ,@body) 145 | (user-error "Point is not on a password entry!")))) 146 | 147 | (defmacro pass-listing--defcmd2 (name docstring &rest body) 148 | "Define a generic command." 149 | (declare (indent defun)) 150 | `(defun ,(intern (concat "pass-listing--" (symbol-name name))) () 151 | ,docstring 152 | (interactive) 153 | ,@body)) 154 | 155 | (pass-listing--defcmd1 remove 156 | "Remove the entry under point; see ‘password-store-remove’." 157 | (when (yes-or-no-p (format "Really remove %s? " it)) 158 | (password-store-remove it))) 159 | 160 | (pass-listing--defcmd1 edit 161 | "Edit the entry under point; see ‘password-store-edit’." 162 | (password-store-edit it)) 163 | 164 | (pass-listing--defcmd2 insert 165 | "Insert an entry; see ‘password-store-insert’." 166 | (password-store-insert (read-string "Name for the new entry (inserting): ") 167 | (read-string "Contents: "))) 168 | 169 | (pass-listing--defcmd2 generate 170 | "Generate an entry; see ‘password-store-generate’." 171 | (let ((name (read-string "Name for the new entry (generating): "))) 172 | (password-store-generate name (read-number "Password length: ")) 173 | (when (y-or-n-p "Copy new password to clipboard?") 174 | (password-store-copy name)))) 175 | 176 | (pass-listing--defcmd1 regenerate 177 | "Regenerate an entry. 178 | Useful for resetting passwords. " 179 | (password-store-generate 180 | it 181 | (read-number 182 | (eval-when-compile 183 | (concat 184 | "Warning: This will reset all the contents of the " 185 | "password file, though git history can be used to " 186 | "retrieve any past information.\nPassword length: ")))) 187 | (when (y-or-n-p "Copy new password to clipboard?") 188 | (password-store-copy it))) 189 | 190 | (pass-listing--defcmd1 rename 191 | "Rename an entry." 192 | (password-store-rename it (read-string "Rename entry to: "))) 193 | 194 | (pass-listing--defcmd1 copy 195 | "Copy an entry." 196 | (password-store-copy it)) 197 | 198 | (defun pass-listing--insert-item (item) 199 | (widget-create 'push-button 200 | :notify #'pass-listing--toggle item) 201 | (insert "\n")) 202 | 203 | (defun pass-listing--toggle (widget &rest ignore) 204 | (let* ((w (cdr widget)) 205 | (name (plist-get w :value)) 206 | (there (plist-get w :to)) 207 | str) 208 | (if (member name pass-listing--open) 209 | (progn 210 | (let ((inhibit-read-only t)) 211 | (delete-region there (1- (save-excursion 212 | (widget-forward 1) 213 | (point))))) 214 | (setq pass-listing--open 215 | (remove name pass-listing--open))) 216 | (progn 217 | (push name pass-listing--open) 218 | (setq str (password-store--run-show name)) 219 | (save-excursion 220 | (goto-char there) 221 | (widget-insert "\n" str)))))) 222 | 223 | (provide 'pass-listing) 224 | ;;; pass-listing.el ends here 225 | -------------------------------------------------------------------------------- /bibliothek.el: -------------------------------------------------------------------------------- 1 | ;;; bibliothek.el --- Managing a digital library of PDFs -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2018, 2019 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Version: 0.2.0 7 | ;; Keywords: tools 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#bibliothek-el 9 | ;; Package-Requires: ((emacs "24.4") (pdf-tools "0.70") (a "0.1.0alpha4")) 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; Bibliothek.el is a management tool for a library of PDFs. Or it 27 | ;; aspires to be so. It's quite fresh ATM, it'll grow as it gets 28 | ;; used more. 29 | 30 | ;; Presently, bibliothek.el displays PDF files from directories in 31 | ;; ‘bibliothek-path’ in a tabulated list, 32 | ;; (see (info "(elisp) Tabulated List Mode")). 33 | 34 | ;; The functionality provided by this program is as such: 35 | 36 | ;; - List PDF files from directories specified in ‘bibliothek-path’, 37 | ;; recursively if ‘bibliothek-recursive’ is non-nil. 38 | 39 | ;; This list includes three columns: title, author, path. Sorting 40 | ;; based on these via clicking the table headers is possible. 41 | 42 | ;; - Filter this list with ‘bibliothek-filter’ 43 | 44 | ;; Using this function, the list can be filtered. Currently this is 45 | ;; rather unsophisticated, and only allows matching a single regexp 46 | ;; against all the metadata PDF-tools can fetch from a file, with a 47 | ;; match being counted positive if any of the fields match. More 48 | ;; complex mechanisms for better filtering are planned. 49 | 50 | ;; - View metadata of file under cursor. 51 | 52 | ;; - Visit the file associated to the item under cursor. 53 | 54 | ;; See also the docstring for the ‘bibliothek’ command, which lists 55 | ;; the keybindings, besides additional info. 56 | 57 | 58 | 59 | ;;;; Installation: 60 | 61 | ;; Bibliothek.el depends on ‘pdf-tools’. 62 | 63 | ;; After putting a copy of bibliothek.el in a directory in the 64 | ;; ‘load-path’, bibliothek.el can be configured as such: 65 | 66 | ;; (require 'bibliothek) 67 | ;; (setq bibliothek-path (list "~/Documents")) 68 | 69 | ;; Then, the Bibliothek interface can be brought up via 70 | ;; M-x bibliothek RET. 71 | 72 | ;;; Code: 73 | 74 | (require 'a) 75 | (require 'pdf-info) 76 | (require 'goto-addr) 77 | (require 'cl-lib) 78 | (require 'tabulated-list) 79 | (require 'button) 80 | 81 | 82 | 83 | ;;;; Customisables: 84 | 85 | (defgroup bibliothek 86 | nil 87 | "Customisations for bibliothek.el, digital PDF library manager." 88 | :group 'applications 89 | :prefix "bibliothek-") 90 | 91 | (defcustom bibliothek-path nil 92 | "A list of directories to look for PDF files." 93 | :type '(repeat directory) 94 | ;; Should be a global variable. 95 | :risky t 96 | :group 'bibliothek) 97 | 98 | (defcustom bibliothek-recursive nil 99 | "Recursively look for files in subdirectories." 100 | :type 'boolean 101 | :group 'bibliothek) 102 | 103 | 104 | 105 | ;;;; Helper functions: 106 | 107 | (defun bibliothek--items () 108 | "Extract all the PDF files from each directory in ‘bibliothek-path’." 109 | (let (items 110 | (file-pattern "\\.pdf\\'")) 111 | (dolist (directory bibliothek-path items) 112 | (when (file-exists-p directory) 113 | (let ((files (if bibliothek-recursive 114 | (directory-files-recursively directory file-pattern) 115 | (directory-files directory t file-pattern t)))) 116 | (dolist (file files) 117 | (cl-pushnew (cons (cons 'bibliothek--filename file) 118 | (pdf-info-metadata file)) 119 | items))))))) 120 | 121 | (defun bibliothek--find (&optional marker) 122 | "Open the PDF file for the row under point. 123 | Optional argument MARKER is passed in when this function is 124 | called from a button." 125 | ;; This function caters to two cases: 1) when it's called from the 126 | ;; ‘tabulated-list-mode’ mechanism, where ‘marker’ will be set; and 127 | ;; 2) when it's called from a keyboard command, where it won't be, 128 | ;; and the point may or may not be on a button. But then we can use 129 | ;; the row id. 130 | (interactive) 131 | (find-file 132 | (if marker 133 | (button-get (button-at marker) 'file) 134 | (tabulated-list-get-id)))) 135 | 136 | ;; Adapted from ‘pdf-misc-display-metadata’. 137 | (defun bibliothek--display-metadata (path) 138 | "Display PDF metadata for file at PATH." 139 | (interactive) 140 | (let* ((md (pdf-info-metadata path))) 141 | (switch-to-buffer 142 | (with-current-buffer (get-buffer-create "*Bibliothek Item Metadata*") 143 | (let* ((inhibit-read-only t) 144 | (pad (apply' 145 | max (mapcar (lambda (d) (length (symbol-name (car d)))) md))) 146 | (fmt (format "%%%ds : %%s\n" pad))) 147 | (erase-buffer) 148 | (special-mode) 149 | (setq header-line-format path) 150 | (font-lock-mode 1) 151 | (font-lock-add-keywords 152 | nil '(("^ *\\(\\(?:\\w\\|-\\)+\\) :" 153 | (1 font-lock-keyword-face)))) 154 | (dolist (d md) 155 | (let ((key (car d)) 156 | (val (cdr d))) 157 | (cl-case key 158 | (keywords 159 | (setq val (mapconcat 'identity val ", ")))) 160 | (let ((beg (+ (length (symbol-name key)) (point) 3)) 161 | (fill-prefix (make-string (+ pad 3) ?\s))) 162 | (insert (format fmt key val)) 163 | (fill-region beg (point)))))) 164 | (goto-char 1) 165 | (current-buffer))) 166 | nil)) 167 | 168 | (defun bibliothek--info () 169 | "Show the metadata buffer for current row." 170 | (interactive) 171 | (bibliothek--display-metadata (tabulated-list-get-id))) 172 | 173 | 174 | 175 | ;;;; The major mode: 176 | 177 | (defvar bibliothek-mode-map 178 | (let ((map (make-sparse-keymap))) 179 | (prog1 map 180 | (define-key map "f" #'bibliothek--find) 181 | (define-key map "s" #'bibliothek-filter) 182 | (define-key map "g" #'bibliothek) 183 | (define-key map "i" #'bibliothek--info)))) 184 | 185 | (define-derived-mode bibliothek-mode tabulated-list-mode 186 | "Bibliothek" 187 | "Bibliothek listing." 188 | (use-local-map bibliothek-mode-map) 189 | (tabulated-list-init-header) 190 | (tabulated-list-print t) 191 | (hl-line-mode)) 192 | 193 | (defvar bibliothek--filter-history nil 194 | "History of filters used by ‘bibliothek’.") 195 | 196 | (defun bibliothek--prep-item (item) 197 | "Prepare ITEM to be used in the table." 198 | (list (a-get item 'bibliothek--filename) 199 | (let ((title (a-get item 'title)) 200 | (path (a-get item 'bibliothek--filename))) 201 | (when (string-empty-p (string-trim title)) 202 | (setq title (concat "(" (file-name-nondirectory path) ")"))) 203 | (vector 204 | (cons title 205 | `(action bibliothek--find file ,path)) 206 | (a-get item 'author) 207 | path)))) 208 | 209 | (defun biblothek--prepare-table-entries (items match) 210 | "Prepare ITEMS for the table, filter with MATCH if applicable." 211 | (let (table-entries) 212 | (dolist (item items table-entries) 213 | (when (cl-remove-if-not 214 | (lambda (field) 215 | (let ((value (cdr field))) 216 | (when value 217 | (cond ((stringp value) 218 | (string-match match value)) 219 | ((listp value) 220 | (cl-remove-if-not 221 | (lambda (v) (string-match match v)) 222 | value)))))) 223 | item) 224 | (cl-pushnew (bibliothek--prep-item item) table-entries))))) 225 | 226 | ;;;###autoload 227 | (defun bibliothek-filter (match) 228 | "Limit results using MATCH, see ‘bibliothek’. 229 | 230 | This can be used as an alternative entry point to the Bibliothek 231 | library listing." 232 | (interactive (list (read-string 233 | "Filter: " 234 | nil 'bibliothek--filter-history "" t))) 235 | (bibliothek match)) 236 | 237 | ;;;###autoload 238 | (cl-defun bibliothek (&optional (match "")) 239 | "Show the library contents. 240 | 241 | This is the main entry point to the Bibliothek package. It shows a 242 | tabulated list of metadata for all the PDF files found in the 243 | directories under ‘bibliothek-path’. 244 | 245 | MATCH is an optional argument, a string, used to filter the 246 | library listing. An entry is included if one or more of the 247 | fields match. 248 | 249 | The keybindings are as follows: 250 | 251 | \\{bibliothek-mode-map}" 252 | (interactive) 253 | (switch-to-buffer 254 | (with-current-buffer (get-buffer-create "*Bibliothek*") 255 | (setq 256 | tabulated-list-entries 257 | (biblothek--prepare-table-entries (bibliothek--items) match) 258 | tabulated-list-format 259 | [("Title" 40 t) 260 | ("Author" 20 t) 261 | ("Path" 20 t)]) 262 | (bibliothek-mode) 263 | (setq-local truncate-lines t) 264 | (current-buffer)))) 265 | 266 | 267 | 268 | ;;; Footer: 269 | (provide 'bibliothek) 270 | ;;; bibliothek.el ends here 271 | -------------------------------------------------------------------------------- /org-variable-pitch.el: -------------------------------------------------------------------------------- 1 | ;;; org-variable-pitch.el --- Minor mode for variable pitch text in org mode. -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2018, 2019, 2020, 2021 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Keywords: faces 7 | ;; Version: 2.1 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#ovp 9 | ;; Package-Requires: ((emacs "25")) 10 | 11 | 12 | ;; This program is free software; you can redistribute it and/or modify 13 | ;; it under the terms of the GNU General Public License as published by 14 | ;; the Free Software Foundation, either version 3 of the License, or 15 | ;; (at your option) any later version. 16 | 17 | ;; This program is distributed in the hope that it will be useful, 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | ;; GNU General Public License for more details. 21 | 22 | ;; You should have received a copy of the GNU General Public License 23 | ;; along with this program. If not, see . 24 | 25 | 26 | 27 | ;;; Commentary: 28 | 29 | ;; Variable-pitch support for org-mode. This minor mode enables 30 | ;; ‘variable-pitch-mode’ in the current Org-mode buffer, and sets some 31 | ;; particular faces up so that they are are rendered in fixed-width 32 | ;; font. Also, indentation, list bullets and checkboxes are displayed 33 | ;; in monospace, in order to keep the shape of the outline. 34 | 35 | ;;; Installation: 36 | 37 | ;; Have this file somewhere in the load path, then: 38 | 39 | ;; (require 'org-variable-pitch) 40 | ;; (add-hook 'org-mode-hook 'org-variable-pitch-minor-mode) 41 | 42 | ;;; Setup: 43 | 44 | ;; org-variable-pitch.el (hereafter, OVP) can be set up in two 45 | ;; methods, the new method introduced in v2.0, and the old way which 46 | ;; was the initial method. 47 | 48 | ;;;; New set up method: 49 | 50 | ;; With v2.0 a new function, ‘org-variable-pitch-setup’ has been 51 | ;; added, which is means to be added to the ‘after-init-hook’ in order 52 | ;; to set up a sensible default configuration for OVP. In order to 53 | ;; use this method, you can simply add the following to your 54 | ;; ‘user-init-file’: 55 | 56 | ;; (require 'org-variable-pitch) 57 | ;; (add-hook 'after-init-hook #'org-variable-pitch-setup) 58 | 59 | ;; If you desire finer control, however, you might instead configure 60 | ;; OVP as follows: 61 | 62 | ;; (require 'org-variable-pitch) 63 | ;; (set-face-attribute 'org-variable-pitch-fixed-face nil 64 | ;; :family "My Custom Font Mono") 65 | ;; (add-hook 'org-mode-hook 'org-variable-pitch--enable) 66 | 67 | ;; At the time I’m writing this, the above snippet is essentially 68 | ;; equivalent to what ‘org-variable-pitch-setup’ does, but that 69 | ;; function might get improved over time. I’ll try to keep the 70 | ;; documentation in sync with it, but it’s recommended that you use 71 | ;; the setup function instead. 72 | 73 | ;;;; Old setup method: 74 | 75 | ;; The old way involved setting a variable-pitch font by hand and 76 | ;; adding ‘org-variable-pitch-minor-mode’ to ‘org-mode-hook’. 77 | 78 | ;; Because this method of setup is obsolete, it’s not documented here, 79 | ;; but OVP should still work fine with old-style configurations. You 80 | ;; can still modify ‘org-variable-pitch-fixed-face’ (the new name of 81 | ;; ‘org-variable-pitch-face’, which is obsoleted) and have your 82 | ;; configurations stick though, which was not possible before v2.0. 83 | 84 | ;;; Configuration: 85 | 86 | ;; There are a couple variables and faces you can use to configure how 87 | ;; OVP behaves. These can be modified through the Emacs’ 88 | ;; customisation facility via 89 | 90 | ;; M-x customize-group RET org-variable-pitch RET 91 | 92 | ;; or manually, in your ‘user-init-file’. It’s advisable that you 93 | ;; consult the documentation of each variable with ‘describe-variable’ 94 | ;; and each face with ‘describe-face’. 95 | 96 | ;;;; ‘org-variable-pitch-fixed-face’ (face): 97 | 98 | ;; This face is applied to parts of the buffer that OVP renders in 99 | ;; fixed pitch, i.e. monospace fonts. These include the space 100 | ;; characters on the left edge of the buffer (indentation), list 101 | ;; bullets, checkboxes, and optionally, leading asterixes of the 102 | ;; headline (see below). 103 | 104 | ;; By default, ‘org-variable-pitch-setup’ sets the ‘:family’ 105 | ;; attribute of this face to that of the ‘default’ face. Pre-v2.0 106 | ;; this was achieved via setting the ‘org-variable-pitch-fixed-font’ 107 | ;; to a desired font, which can still be used (see below), but we’ve 108 | ;; obsoleted that method in favour of this new style of 109 | ;; configuration in order to allow customising this face. 110 | 111 | ;; This face replaces ‘org-variable-pitch-face’, which is made into 112 | ;; an obsolete alias (i.e. still usable, but obsoleted). 113 | 114 | ;;;; ‘org-variable-pitch-fixed-font’ (variable): 115 | 116 | ;; Obsolete since v2.0. Please configure 117 | ;; ‘org-variable-pitch-fixed-face’ instead. 118 | 119 | ;;;; ‘org-variable-pitch-fixed-faces’ (variable): 120 | 121 | ;; Apart from applying a face to the indentation and other aligned 122 | ;; parts of an Org mode buffer to fix alignment issues, OVP also 123 | ;; modifies the appearance of some other elements of the buffer so 124 | ;; that everything appears tidy and aligned when 125 | ;; ‘variable-pitch-mode’ is enabled. 126 | 127 | ;; This variable contains a list of the faces that are to be 128 | ;; modified in order to achive that. You can extend this list with 129 | ;; the names of faces you want to keep in fixed pitch, tho the 130 | ;; default is aimed to be fairly comprehensive. 131 | 132 | ;;;; ‘org-variable-pitch-fontify-headline-prefix’ (variable): 133 | 134 | ;; When this variable is non-nil, the leading asterixes of Org mode 135 | ;; headlines are configured to appear in fixed pitch too. 136 | 137 | ;;; Notes: 138 | 139 | ;; - Setting ‘redisplay-skip-fontification-on-input’ to t may lead to 140 | ;; inconsistent application of ‘org-variable-pitch-fixed-face’ to 141 | ;; indentation. This usually self-remedies as new input is added to 142 | ;; the buffer and e.g. sometimes when ‘org-fill-paragraph’ is run, 143 | ;; but will still lead to confusing issues, like for example the 144 | ;; second and further lines of list items’ indentation not being 145 | ;; made fixed, leading to them appearing on the wrong indentation 146 | ;; level. 147 | 148 | 149 | 150 | ;;; Code: 151 | 152 | (require 'org) 153 | (require 'rx) 154 | 155 | (defgroup org-variable-pitch nil 156 | "Customisations for ‘org-variable-pitch-minor-mode’." 157 | :group 'org 158 | :prefix "org-variable-pitch-") 159 | 160 | (defun org-variable-pitch--get-fixed-font () 161 | (if (string= org-variable-pitch-fixed-font--default 162 | org-variable-pitch-fixed-font) 163 | (face-attribute 'default :family) 164 | org-variable-pitch-fixed-font)) 165 | 166 | (defcustom org-variable-pitch-fixed-font "Monospace" 167 | "Monospace font to use with ‘org-variable-pitch-minor-mode’." 168 | :group 'org-variable-pitch 169 | :type 'string 170 | :risky t) 171 | 172 | (defconst org-variable-pitch-fixed-font--default 173 | org-variable-pitch-fixed-font) 174 | 175 | (make-obsolete-variable 176 | 'org-variable-pitch-fixed-font 177 | "customize ‘org-variable-pitch-fixed-face’ instead." 178 | "org-variable-pitch.el 2.0") 179 | 180 | (defcustom org-variable-pitch-fixed-faces 181 | '(org-block 182 | org-block-begin-line 183 | org-block-end-line 184 | org-code 185 | org-document-info-keyword 186 | org-done 187 | org-formula 188 | org-indent 189 | org-meta-line 190 | org-special-keyword 191 | org-table 192 | org-todo 193 | org-verbatim 194 | org-date 195 | org-drawer) 196 | "Faces to keep fixed-width when using ‘org-variable-pitch-minor-mode’." 197 | :group 'org-variable-pitch 198 | :type '(repeat symbol)) 199 | 200 | (defcustom org-variable-pitch-fontify-headline-prefix nil 201 | "Fontify the headline prefix. 202 | When non-nil, headline prefix will use the monospace face. 203 | Otherwise the headline will use the default `org-level-*' face. 204 | 205 | Note that this will drop all `org-level-*' face styles and only 206 | apply the monospace face to the headline prefix." 207 | :group 'org-variable-pitch 208 | :type 'boolean) 209 | 210 | (define-obsolete-face-alias 211 | 'org-variable-pitch-face 212 | 'org-variable-pitch-fixed-face 213 | "org-variable-pitch.el 2.0") 214 | 215 | (defface org-variable-pitch-fixed-face 216 | `((t . (:family ,(org-variable-pitch--get-fixed-font)))) 217 | "Face for initial space and list item bullets. 218 | This face is used to keep them in monospace when using 219 | ‘org-variable-pitch-minor-mode’." 220 | :group 'org-variable-pitch) 221 | 222 | (defvar org-variable-pitch-font-lock-keywords) 223 | (defvar org-variable-pitch-headline-font-lock-keywords) 224 | (let ((code '(0 (put-text-property 225 | (match-beginning 0) 226 | (match-end 0) 227 | 'face 'org-variable-pitch-fixed-face)))) 228 | (setq 229 | org-variable-pitch-font-lock-keywords 230 | `((,(rx bol (1+ blank)) 231 | ,code) 232 | (,(rx bol (0+ blank) 233 | (or (: (or (+ digit) letter) (in ".)")) 234 | (: (or (in "-+") (1+ blank "*")))) 235 | (opt blank "[" (in "-X ") "]") 236 | blank) 237 | ,code)) 238 | org-variable-pitch-headline-font-lock-keywords 239 | `((,(rx bol (1+ "\*") blank) 240 | ,code)))) 241 | 242 | 243 | (defvar org-variable-pitch--cookies nil 244 | "Face remappings to restore when the minor mode is deactivated") 245 | 246 | ;;;###autoload 247 | (define-minor-mode org-variable-pitch-minor-mode 248 | "Set up the buffer to be partially in variable pitch. 249 | Keeps some elements in fixed pitch in order to keep layout." 250 | nil " OVP" nil 251 | (if org-variable-pitch-minor-mode 252 | (progn 253 | (variable-pitch-mode 1) 254 | (dolist (face org-variable-pitch-fixed-faces) 255 | (if (facep face) 256 | (push (face-remap-add-relative face 'org-variable-pitch-fixed-face) 257 | org-variable-pitch--cookies) 258 | (message "‘%s’ is not a valid face, thus OVP skipped it" 259 | (symbol-name face)))) 260 | (font-lock-add-keywords nil org-variable-pitch-font-lock-keywords) 261 | (when org-variable-pitch-fontify-headline-prefix 262 | (font-lock-add-keywords nil org-variable-pitch-headline-font-lock-keywords))) 263 | (variable-pitch-mode -1) 264 | (mapc #'face-remap-remove-relative org-variable-pitch--cookies) 265 | (setq org-variable-pitch--cookies nil) 266 | (font-lock-remove-keywords nil org-variable-pitch-font-lock-keywords) 267 | (font-lock-remove-keywords nil org-variable-pitch-headline-font-lock-keywords)) 268 | (font-lock-ensure)) 269 | 270 | (defun org-variable-pitch--enable () 271 | "Enable ‘org-variable-pitch-minor-mode’" 272 | (org-variable-pitch-minor-mode +1)) 273 | 274 | ;;;###autoload 275 | (defun org-variable-pitch-setup () 276 | "Set up ‘org-variable-pitch-minor-mode’. 277 | 278 | This function is a helper to set up OVP. It syncs 279 | ‘org-variable-pitch-fixed-face’ with ‘default’ face, and adds a 280 | hook to ‘org-mode-hook’. Ideally, you’d want to run this 281 | function somewhere after you set up ‘default’ face. 282 | 283 | A nice place to call this function is from within 284 | ‘after-init-hook’: 285 | 286 | \(add-hook 'after-init-hook #'org-variable-pitch-setup) 287 | 288 | Alternatively, you might want to manually set up the attributes 289 | of ‘org-variable-pitch-fixed-face’, in which case you should 290 | calling avoid this function, add ‘org-variable-pitch-minor-mode’ 291 | to ‘org-mode-hook’ manually, and set up the face however you 292 | please." 293 | (interactive) 294 | (set-face-attribute 'org-variable-pitch-fixed-face nil 295 | :family (org-variable-pitch--get-fixed-font)) 296 | (add-hook 'org-mode-hook 'org-variable-pitch--enable)) 297 | 298 | 299 | 300 | 301 | ;;; Footer: 302 | 303 | (provide 'org-variable-pitch) 304 | ;;; org-variable-pitch.el ends here 305 | -------------------------------------------------------------------------------- /bsdpkg.el: -------------------------------------------------------------------------------- 1 | ;;; bsdpkg.el --- Emacs interface for FreeBSD pkg(1) -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2017, 2018, 2019 Göktuğ Kayaalp 4 | 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Keywords: unix, tools 7 | ;; Version: 0 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#bsdpkg-el 9 | ;; Package-Requires: ((emacs "25")) 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; This is alpha software. 27 | 28 | ;; ‘bsdpkg’ is an Emacs interface to FreeBSD pkg(1). It's planned to 29 | ;; genericise the package to support all *BSD packaging systems, and 30 | ;; the module is written with that sort of extensibility in mind. 31 | 32 | ;;;; Notes: 33 | 34 | 35 | 36 | ;;; Code: 37 | 38 | (require 'cl-lib) 39 | (require 'tabulated-list) 40 | (require 'button) 41 | (require 'tramp) 42 | 43 | 44 | 45 | ;;;; Configuration: 46 | 47 | ;; TODO: Extend as this is (possibly) ported around. 48 | (defvar bsdpkg-system 49 | (let ((freebsd (string-match "freebsd" system-configuration))) 50 | (cond (freebsd 51 | (cons 'freebsd 52 | (substring system-configuration (+ freebsd 7)))))) 53 | "Operating system and type. 54 | A cons pair of a symbol and a string, the system type and the 55 | system version, respectively. The default value of this variable 56 | is calculated via a heuristic, but the user should make sure that 57 | it corresponds to their system, and possibly help improve it for 58 | their system. The meaning of the car of this pair is 59 | self-evident, but here is a list of expected values and their 60 | meanings: 61 | 62 | - freebsd: FreeBSD, GhostBSD, other compatible FreeBSD derivatives 63 | - openbsd: OpenBSD 64 | - dragonfly: DragonflyBSD 65 | - netbsd: NetBSD 66 | 67 | At the time being, the module works only on FreeBSD.") 68 | 69 | (defvar bsdpkg-command 70 | (cl-case (car bsdpkg-system) 71 | ('freebsd (let ((ver (mapcar #'string-to-number 72 | (split-string (cdr bsdpkg-system) 73 | "\\.")))) 74 | ;; pkg was introduced in FreeBSD 9.1. The system 75 | ;; before that was comprised of multiple executables. 76 | (when (or (and (= (car ver) 9) (>= (cadr ver) 1)) 77 | (and (> (car ver) 9))) 78 | (or (executable-find "pkg") 79 | (error "‘pkg’ is not installed on Freebsd %d.%d" 80 | (car ver) (cadr ver))))))) 81 | "The path to the binary packaging system's main executable. 82 | The default value of this variable is computed based on that of 83 | ‘bsdpkg-system’. If the packaging system does not have a main 84 | executable like FreeBSD's ‘pkg’, then this variable's value will 85 | be set to nil.") 86 | 87 | 88 | 89 | ;;;; Utilites: 90 | 91 | ;;;;; Buffers: 92 | (defvar bsdpkg--scratch-buf "*bsdpkg process interaction*") 93 | 94 | (defun bsdpkg--scratch () 95 | "Return the buffer for storing and processing command outputs. 96 | Erases the buffer before returning." 97 | (let ((bufnam bsdpkg--scratch-buf)) 98 | (when-let (buf (get-buffer bufnam)) (kill-buffer buf)) 99 | (generate-new-buffer bufnam))) 100 | 101 | (defun bsdpkg--listing () 102 | "Return the package listing buffer. 103 | Erases the buffer before returning." 104 | (with-current-buffer (get-buffer-create "*bsdpkg search*") 105 | (fundamental-mode) 106 | (read-only-mode -1) 107 | (erase-buffer) 108 | (current-buffer))) 109 | 110 | (defun bsdpkg--descrbuf (pkg) 111 | "Return the package description buffer for PKG. 112 | Erases the buffer before returning." 113 | (with-current-buffer (get-buffer-create (format "*bsdpkg descr (%s)*" pkg)) 114 | (fundamental-mode) 115 | (read-only-mode -1) 116 | (erase-buffer) 117 | (current-buffer))) 118 | 119 | 120 | 121 | ;;;;; Strings: 122 | 123 | (defvar bsdpkg--err-unexpected-ret "Process terminated with unexpected error (%d)") 124 | 125 | 126 | 127 | ;;;; Portability abstractions: 128 | 129 | ;; The functions in this section provide an abstraction for running 130 | ;; common features w/o needing to know the underlying system. The 131 | ;; user interface functions may only call these. 132 | 133 | (defun bsdpkg--system () 134 | "Return a symbol denoting the system type. 135 | This is equivalent to (car ‘bsdpkg-system’)" 136 | (car bsdpkg-system)) 137 | 138 | (defun bsdpkg--system-name () 139 | "Return a stylized name for the current system." 140 | (cl-case (bsdpkg--system) 141 | ('freebsd "FreeBSD") 142 | ('openbsd "OpenBSD") 143 | ('dragonfly "DragonflyBSD") 144 | ('netbsd "NetBSD") 145 | (otherwise "UNKNOWN SYSTEM"))) 146 | 147 | (defun bsdpkg--call (feature &rest args) 148 | "Execute the function implementing FEATURE for current system. 149 | The FEATURE function is run on ARGS with ‘apply’. Will raise a 150 | ‘not-implemented’ error, whose cdr is a cons pair, the FEATURE 151 | symbol itself and a default error message." 152 | (let ((sym (intern (format "bsdpkg--%s--%s" (bsdpkg--system) feature)))) 153 | (unless (functionp sym) 154 | (error "‘%s’ not implemented on %s" feature (bsdpkg--system-name))) 155 | (apply sym args))) 156 | 157 | 158 | 159 | ;;;;; FreeBSD: 160 | ;;;;;; Call pkg-ng: 161 | 162 | (defun bsdpkg--freebsd-call-pkg-ng (&rest args) 163 | "Call FreeBSD pkg(1) command with ARGS. 164 | ARGS are a list of strings, each an argument passed to the 165 | command, a la ‘call-process’. If the process returns 0, return 166 | the output (may be empty string), signal otherwise, with 167 | appropriate info attached." 168 | (let* ((buf (bsdpkg--scratch)) 169 | (ret (apply 'call-process 170 | bsdpkg-command nil `(,buf nil) nil args))) 171 | (if (zerop ret) 172 | (with-current-buffer buf (buffer-string)) 173 | ret))) 174 | 175 | (defun bsdpkg--freebsd-call-pkg-ng-su (&rest args) 176 | "Like ‘bsdpkg--freebsd-call-pkg-ng’ but as sudo." 177 | (with-current-buffer (bsdpkg--scratch) 178 | (cd (concat "/sudo::" (expand-file-name default-directory))) 179 | (prog1 180 | (shell-command 181 | (concat bsdpkg-command " " 182 | (mapconcat (lambda (c) (concat "'" c "'")) args " ")) (current-buffer)) 183 | (cd default-directory)))) 184 | 185 | 186 | 187 | ;;;;;; Search: 188 | 189 | (defun bsdpkg--freebsd-pkg-ng-search (pkg) 190 | "Search pakcages PKG using pkg(1)." 191 | (let ((ret (bsdpkg--freebsd-call-pkg-ng "search" pkg))) 192 | (cond 193 | ((stringp ret) 194 | (with-temp-buffer 195 | (insert ret) (goto-char (point-min)) 196 | (let ((line (buffer-substring (line-beginning-position) (line-end-position))) 197 | (go t) data) 198 | (while go 199 | (unless 200 | (equal 0 (string-match "^\\([^ ]+\\) +\\(.*\\)$" line)) 201 | (error "Regexp did not match line while searching")) 202 | (setf data (nconc data 203 | (list (cons (match-string 1 line) 204 | (match-string 2 line))))) 205 | ;; Break on EOF. 206 | (if (= (1+ (line-end-position)) (point-max)) 207 | (setf go nil) 208 | (progn 209 | (forward-line) 210 | (setf line (buffer-substring (line-beginning-position) 211 | (line-end-position)))))) 212 | data))) 213 | ((eq 70 ret) nil) 214 | (:otherwise (error bsdpkg--err-unexpected-ret ret))))) 215 | 216 | (defun bsdpkg--freebsd--search (pkg) 217 | "Return a list of matching packages. 218 | PKG is a regular expression. Returns a list of lists of three 219 | strings: the package name, version and package comment, 220 | respectively." 221 | (unless bsdpkg-command 222 | (throw :not-implemented 'search)) 223 | (bsdpkg--freebsd-pkg-ng-search pkg)) 224 | 225 | 226 | 227 | ;;;;;; Package completion: 228 | 229 | ;; see ‘(elisp)Programmed Completion’. 230 | (defun bsdpkg--freebsd-completions (prefix pred flag) 231 | "Complete package names for PREFIX." 232 | (when (> (length prefix) 2) 233 | (mapcar 'car (bsdpkg--call 'search (concat "^" prefix))))) 234 | 235 | (defun bsdpkg--freebsd--complete-pkg () 236 | "Completing-read the name of a single, existing package." 237 | (completing-read "Package name (at least three letters to auto-complete): " 238 | 'bsdpkg--freebsd-completions nil t)) 239 | 240 | 241 | 242 | ;;;;;; Describe: 243 | 244 | (defun bsdpkg--freebsd--describe (pkg) 245 | "Return a string describing PKG." 246 | (let ((ret (bsdpkg--freebsd-call-pkg-ng 247 | "search" "-Q" "name" "-Q" "version" "-Q" "repository" 248 | "-Q" "categories" "-Q" "license" "-Q" "maintainer" "-Q" "size" 249 | "-Q" "comment" "-Q" "options" "-Q" "annotations" 250 | "-Q" "pkg-size" "-Q" "depends-on" "-Q" "description" 251 | (format "^%s$" pkg)))) 252 | (if (stringp ret) 253 | ret 254 | (if (eq 70 ret) 255 | (user-error "Query ‘%s’ did not match anything" pkg) 256 | (error "Process returned error (%S) when querying ‘%s’" ret pkg))))) 257 | 258 | ;;;;;; Install/Remove: 259 | 260 | (defun bsdpkg--freebsd--installed-p (pkg) 261 | "Check whether or not PKG is installed. 262 | Returns t if installed, nil otherwise." 263 | (let ((ret (bsdpkg--freebsd-call-pkg-ng "info" "-e" pkg))) 264 | (cond ((stringp ret) t) 265 | ((and (numberp ret) (not (= 1 ret))) 266 | (error bsdpkg--err-unexpected-ret ret))))) 267 | 268 | (defun bsdpkg--freebsd--install (pkg) 269 | "Install PKG. 270 | Ensure via ‘yes-or-no-p’ before installing." 271 | (if (bsdpkg--freebsd--installed-p pkg) 272 | (user-error "‘%s’ is already installed" pkg) 273 | (when (yes-or-no-p (format "Install %s? " pkg)) 274 | (let ((ret (bsdpkg--freebsd-call-pkg-ng-su "install" "-y" pkg))) 275 | (cond ((equal 0 ret) (with-current-buffer bsdpkg--scratch-buf 276 | (buffer-string))) 277 | ((equal 70 ret) (user-error "Package not found (%s)" pkg)) 278 | ((equal 77 ret) (user-error "User %s cannot install packages" 279 | (user-login-name) pkg)) 280 | (t (error bsdpkg--err-unexpected-ret ret))))))) 281 | 282 | (defun bsdpkg--freebsd--remove (pkg) 283 | "Remove PKG. 284 | Ensure via ‘yes-or-no-p’ before removing." 285 | (when (yes-or-no-p (format "Remove %s? " pkg)) 286 | (let ((ret (bsdpkg--freebsd-call-pkg-ng-su "remove" "-y" pkg))) 287 | (cond ((equal 0 ret) (with-current-buffer bsdpkg--scratch-buf 288 | (buffer-string))) 289 | ((equal 65 ret) (user-error "Package not found (%s)" pkg)) 290 | ((equal 77 ret) (user-error "User %s cannot remove packages" 291 | (user-login-name) pkg)) 292 | (t (error bsdpkg--err-unexpected-ret ret)))))) 293 | 294 | 295 | 296 | ;;;; User interface: 297 | ;;;;; Helper functions: 298 | ;;;;;; Search: 299 | 300 | (defun bsdpkg--search-table (pkgs) 301 | "Build a package search table out of PKGS." 302 | (switch-to-buffer 303 | (with-current-buffer (bsdpkg--listing) 304 | (setf tabulated-list-entries 305 | (mapcar 'bsdpkg--search-table-btnify pkgs)) 306 | (setf tabulated-list-format [("Package" 30 nil) 307 | ("Comment" 90 nil)]) 308 | (bsdpkg-search-mode) 309 | (current-buffer)))) 310 | 311 | (defun bsdpkg--search-table-btnify (entry) 312 | (interactive) 313 | (let ((pkg (car entry))) 314 | (list pkg 315 | (vector (cons pkg 316 | `(action bsdpkg--search-table-btn-action pkg ,pkg)) 317 | (cdr entry))))) 318 | 319 | (defun bsdpkg--search-table-btn-action (marker) 320 | (interactive) 321 | (bsdpkg-describe (button-get (button-at marker) 'pkg))) 322 | 323 | 324 | 325 | ;;;;;; Describe: 326 | 327 | (defun bsdpkg--describe (pkg descr) 328 | "Create a description buffer for PKG and switch to it." 329 | (switch-to-buffer 330 | (with-current-buffer (bsdpkg--descrbuf pkg) 331 | (setq-local bsdpkg--pkg pkg) 332 | (let ((installed (bsdpkg--call 'installed-p pkg))) 333 | (if installed 334 | (progn (insert "Installed, ") 335 | (insert-text-button "Remove" 336 | 'action (lambda (mark) 337 | (interactive) 338 | (bsdpkg--call 'remove pkg) 339 | (bsdpkg-describe pkg)))) 340 | (insert-text-button "Install" 341 | 'action (lambda (mark) 342 | (interactive) 343 | (bsdpkg--call 'install pkg) 344 | (bsdpkg-describe pkg))))) 345 | (insert "\n\n") 346 | (insert descr) 347 | (goto-char (point-min)) 348 | (bsdpkg-describe-mode) 349 | (current-buffer)))) 350 | 351 | 352 | 353 | ;;;;; Modes: 354 | 355 | (define-derived-mode bsdpkg-search-mode tabulated-list-mode 356 | "BSD Package Search" 357 | "Mode for interacting with package search results." 358 | (tabulated-list-init-header) 359 | (tabulated-list-print t) 360 | (hl-line-mode)) 361 | 362 | (let ((map bsdpkg-search-mode-map)) 363 | (define-key map "s" 'bsdpkg-search)) 364 | 365 | (define-derived-mode bsdpkg-describe-mode special-mode 366 | "BSD Describe Package" 367 | "Mode for interacting with package status and details" 368 | (goto-address-mode +1)) 369 | 370 | 371 | 372 | ;;;;; Public commands: 373 | 374 | (defun bsdpkg-search (pkg) 375 | "Search the package repository for PKG. 376 | PKG may be a regex that the OS packaging tool accepts. " 377 | (interactive (list (read-string "Package name (regexp): "))) 378 | (let ((pkgs (bsdpkg--call 'search pkg))) 379 | (if pkgs 380 | (bsdpkg--search-table pkgs) 381 | (user-error "No match for ‘%s’" pkg)))) 382 | 383 | (defun bsdpkg-describe (pkg) 384 | "Search the package repository for PKG." 385 | (interactive (list (bsdpkg--call 'complete-pkg))) 386 | (let ((descr (bsdpkg--call 'describe pkg))) 387 | (bsdpkg--describe pkg descr))) 388 | 389 | (defun bsdpkg-install (pkg) 390 | "Install PKG." 391 | (interactive (list (bsdpkg--call 'complete-pkg))) 392 | (bsdpkg--call 'install pkg)) 393 | 394 | (defun bsdpkg-remove (pkg) 395 | "Remove PKG." 396 | (interactive (list (bsdpkg--call 'complete-pkg))) 397 | (bsdpkg--call 'remove pkg)) 398 | 399 | (defun bsdpkg-clean () 400 | "Remove packages installed as a dependency for a now removed package." 401 | (interactive) 402 | (bsdpkg--call 'clean)) 403 | 404 | ;; TODO: In search buffer, RET on a line shows package description 405 | ;; TODO: describe, install, remove, update, upgrade 406 | ;; TODO: Show package status (installed or not) in search buffer 407 | 408 | 409 | 410 | ;;;; Export: 411 | 412 | (provide 'bsdpkg) 413 | ;;; bsdpkg.el ends here 414 | -------------------------------------------------------------------------------- /paper-theme.el: -------------------------------------------------------------------------------- 1 | ;;; paper-theme.el --- A minimal Emacs colour theme. -*- lexical-binding: t; -*- 2 | ;; Copyright (C) 2015, 2018, 2019, 2022, 2023 Göktuğ Kayaalp 3 | ;; 4 | ;; Author: Göktuğ Kayaalp 5 | ;; Keywords: theme paper 6 | ;; Package-Version: 2.1 7 | ;; Package-Requires: ((emacs "24")) 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#paper 9 | ;; 10 | ;; Permission is hereby granted, free of charge, to any person 11 | ;; obtaining a copy of this software and associated documentation 12 | ;; files (the "Software"), to deal in the Software without 13 | ;; restriction, including without limitation the rights to use, copy, 14 | ;; modify, merge, publish, distribute, sublicense, and/or sell copies 15 | ;; of the Software, and to permit persons to whom the Software is 16 | ;; furnished to do so, subject to the following conditions: 17 | ;; 18 | ;; The above copyright notice and this permission notice shall be 19 | ;; included in all copies or substantial portions of the Software. 20 | ;; 21 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | ;; SOFTWARE. 29 | ;; 30 | ;;; Commentary: 31 | ;; 32 | ;; Paper is a little, minimal emacs theme that is meant to be simple 33 | ;; and consistent. 34 | ;; 35 | ;; It was first intended to resemble the look of paper, but has 36 | ;; diverged from that objective. Still, though, I keep calling it 37 | ;; Paper, as I like that name. 38 | ;; 39 | ;; Paper uses a small colour palette over all the elements. Org 40 | ;; headings are specially treated with a palette of equidistant 41 | ;; colours. The colours and heading font sizes are calculated using 42 | ;; base and factor values which can be edited. See source. 43 | ;; 44 | ;; It's most adapted for ELisp-Org users, as I'm one such user, though 45 | ;; it works fine with Markdown, Textile, Python, JavaScript, Html, 46 | ;; Diff, Magit, etc. 47 | ;; 48 | ;;; Installation: 49 | ;; 50 | ;; Install it into a directory that's in the `custom-theme-load-path'. 51 | ;; I recommend that you put that directory also in `load-path', so 52 | ;; that you can `require' the `paper-theme'. Then adapt this snippet 53 | ;; to your configuration. 54 | ;; 55 | ;; ;; Not necessary, but silences flycheck errors for referencing free 56 | ;; ;; variables. 57 | ;; (require 'paper-theme) 58 | ;; ;; It's not necessary to modify these variables, they all have sane 59 | ;; ;; defaults. 60 | ;; (setf paper-paper-colour 'paper-parchment ; Custom background. 61 | ;; paper-tint-factor 45) ; Tint factor for org-level-* faces 62 | ;; ;; Activate the theme. 63 | ;; (load-theme 'paper t) 64 | ;; 65 | ;;; Customisation: 66 | ;; 67 | ;; It is possible to modify the base font size and the scaling factor 68 | ;; for `org-level-faces' via the variables `paper-base-font-size' and 69 | ;; `paper-font-factor' respectively. 70 | ;; 71 | ;; The factor for org-level-* colours are also configurable, adjust 72 | ;; the variable `paper-tint-factor'. 73 | ;; 74 | ;; Various background colours are provided, see the docstring of the 75 | ;; variable `paper-paper-colour' in order to find out how to switch 76 | ;; them. You can add your custom colour for background without 77 | ;; modifying this module: 78 | ;; 79 | ;; (push (list 'my-bgcolour "#000000") paper-colours-alist) 80 | ;; (setf paper-paper-colour 'my-bgcolour) 81 | ;; 82 | ;; The following snippet will modify org-level-* faces so that initial 83 | ;; stars in org headings are hidden and a Sans-serif font is used. 84 | ;; Because the combination of heading font sizes and colours make 85 | ;; levels obvious, it may be considered superfluous to have stars 86 | ;; indicating depth: 87 | ;; 88 | ;; (setq org-hide-leading-stars nil) 89 | ;; (set-face-attribute 90 | ;; 'org-hide nil 91 | ;; :height 0.1 :weight 'light :width 'extracondensed) 92 | ;; (dolist (face org-level-faces) 93 | ;; (set-face-attribute 94 | ;; face nil 95 | ;; :family "Sans Serif")) 96 | ;; 97 | ;;; Code: 98 | ;; 99 | (require 'cl-lib) 100 | 101 | ;;; Code from hexrgb.el: 102 | ;; On 25 Dec 2018 I was informed that Melpa was about to drop support 103 | ;; for Emacswiki packages, which includes hexrgb.el too. This means 104 | ;; that I needed to remove the dependency on the package, so I include 105 | ;; here the functions needed by paper-theme from that package. Below, 106 | ;; I reproduce information on copyright and some other things from the 107 | ;; version I have of it: 108 | 109 | ;; Copyright (C) 2004-2015, Drew Adams, all rights reserved. 110 | ;; Last-Updated: Wed Jul 8 18:32:29 2015 (-0700) 111 | ;; By: dradams 112 | ;; Update #: 985 113 | ;; URL: http://www.emacswiki.org/hexrgb.el 114 | 115 | ;; This program is free software; you can redistribute it and/or modify 116 | ;; it under the terms of the GNU General Public License as published by 117 | ;; the Free Software Foundation; either version 2, or (at your option) 118 | ;; any later version. 119 | 120 | ;; This program is distributed in the hope that it will be useful, 121 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 122 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 123 | ;; GNU General Public License for more details. 124 | 125 | ;; You should have received a copy of the GNU General Public License 126 | ;; along with this program; see the file COPYING. If not, write to 127 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth 128 | ;; Floor, Boston, MA 02110-1301, USA. 129 | 130 | (if (featurep 'hexrgb) 131 | (require 'hexrgb) 132 | (progn 133 | ;; Originally, I used the code from `int-to-hex-string' in `float.el'. 134 | ;; This version is thanks to Juri Linkov . 135 | ;; 136 | (defun hexrgb-int-to-hex (int &optional nb-digits) 137 | "Convert integer arg INT to a string of NB-DIGITS hexadecimal digits. 138 | If INT is too large to be represented with NB-DIGITS, then the result 139 | is truncated from the left. So, for example, INT=256 and NB-DIGITS=2 140 | returns \"00\", since the hex equivalent of 256 decimal is 100, which 141 | is more than 2 digits." 142 | (setq nb-digits (or nb-digits 4)) 143 | (substring (format (concat "%0" (int-to-string nb-digits) "X") int) (- nb-digits))) 144 | 145 | ;; From `hexl.el'. This is the same as `hexl-hex-char-to-integer' defined there. 146 | (defun hexrgb-hex-char-to-integer (character) 147 | "Take a CHARACTER and return its value as if it were a hex digit." 148 | (if (and (>= character ?0) (<= character ?9)) 149 | (- character ?0) 150 | (let ((ch (logior character 32))) 151 | (if (and (>= ch ?a) (<= ch ?f)) 152 | (- ch (- ?a 10)) 153 | (error "Invalid hex digit `%c'" ch))))) 154 | 155 | (defun hexrgb-hex-to-int (hex) 156 | "Convert HEX string argument to an integer. 157 | The characters of HEX must be hex characters." 158 | (let* ((factor 1) 159 | (len (length hex)) 160 | (indx (1- len)) 161 | (int 0)) 162 | (while (>= indx 0) 163 | (setq int (+ int (* factor (hexrgb-hex-char-to-integer (aref hex indx)))) 164 | indx (1- indx) 165 | factor (* 16 factor))) 166 | int)) 167 | 168 | (defun hexrgb-increment-hex (hex nb-digits increment &optional wrap-p) 169 | "Increment hexadecimal-digits string HEX by INCREMENT. 170 | Only the first NB-DIGITS of HEX are used. 171 | If optional arg WRAP-P is non-nil then the result wraps around zero. 172 | For example, with NB-DIGITS 3, incrementing \"fff\" by 1 causes it 173 | to wrap around to \"000\"." 174 | (let* ((int (hexrgb-hex-to-int hex)) 175 | (new-int (+ increment int))) 176 | (if (or wrap-p 177 | (and (>= int 0) ; Not too large for the machine. 178 | (>= new-int 0) ; For the case where increment < 0. 179 | (<= (length (format (concat "%X") new-int)) nb-digits))) ; Not too long. 180 | (hexrgb-int-to-hex new-int nb-digits) ; Use incremented number. 181 | hex))) ; Don't increment. 182 | 183 | (defun hexrgb-increment-equal-rgb (hex nb-digits increment &optional wrap-p) 184 | "Increment each color component (r,g,b) of rgb string HEX by INCREMENT. 185 | String HEX starts with \"#\". Each color is NB-DIGITS hex digits long. 186 | If optional arg WRAP-P is non-nil then the result wraps around zero. 187 | For example, with NB-DIGITS 3, incrementing \"#fffffffff\" by 1 188 | causes it to wrap around to \"#000000000\"." 189 | (concat 190 | "#" 191 | (hexrgb-increment-hex (substring hex 1 (1+ nb-digits)) nb-digits increment wrap-p) 192 | (hexrgb-increment-hex (substring hex (1+ nb-digits) (1+ (* nb-digits 2))) 193 | nb-digits 194 | increment 195 | wrap-p) 196 | (hexrgb-increment-hex (substring hex (1+ (* nb-digits 2))) nb-digits increment wrap-p))))) 197 | 198 | ;;; Paper theme: 199 | (deftheme paper 200 | "An Emacs colour theme that resembles the look of paper.") 201 | 202 | (defvar paper-colours-alist 203 | '((text "#070A01") 204 | (paper-grey "#FAFAFA") 205 | (paper-old-dark "#F8ECC2") 206 | (paper-parchment "#F1F1D4") 207 | (paper-old-light "#F2EECB") 208 | (white "#EEEEEE") 209 | (magenta "#8C0D40") 210 | (pen "#000F55") 211 | (light-shadow "#D9DDD9")) 212 | "The colours used in Paper theme. 213 | The alist of colours where for each pair p (car p) is a 214 | symbol identifying the colour and (cdr p) is the string, the 215 | hexedecimal notation of the colour (i.e. #RRGGBB where R, G and B 216 | are hexedecimal digits).") 217 | 218 | (defvar paper-paper-colour 'paper-grey 219 | "Which paper colour to use. 220 | The variable `paper-colours-alist' contains a suit of colours 221 | with prefix `paper-'. This variable's value is supposed to be 222 | set to one of those symbols to specify the colour used for 223 | background.") 224 | 225 | (defvar paper-use-varying-heights-for-org-title-headlines nil 226 | "Whether to use varying heights for Org headlines.") 227 | 228 | (defvar paper-base-font-size 100 229 | "The base size for fonts.") 230 | 231 | (defvar paper-font-factor 0.1 232 | "The font factor for calculating level fonts from base.") 233 | 234 | (defvar paper-tint-factor 20 235 | "The factor for computing tints for org levels.") 236 | 237 | (defun paper-colour (colour-identifier) 238 | "Get colour for COLOUR-IDENTIFIER." 239 | (cadr (assoc colour-identifier paper-colours-alist))) 240 | 241 | (defun paper-colour-paper () 242 | "Get the colour for paper. 243 | See `paper-paper-colour' and `paper-colours-alist'." 244 | (paper-colour paper-paper-colour)) 245 | 246 | (defconst paper-normal-face 247 | `((t (:foreground ,(paper-colour 'text) :background ,(paper-colour-paper)))) 248 | "The base colours of Paper theme.") 249 | 250 | (defconst paper-inverse-face 251 | `((t (:foreground ,(paper-colour-paper) :background ,(paper-colour 'text)))) 252 | "The inverse of base colours of Paper theme.") 253 | 254 | (defconst paper-pen-face 255 | `((t (:foreground ,(paper-colour 'pen) :background ,(paper-colour-paper)))) 256 | "Colour couple that resembles pen colour on paper.") 257 | 258 | (defconst paper-light-shadow-face 259 | `((t (:foreground ,(paper-colour 'text) :background ,(paper-colour 'light-shadow)))) 260 | "Colour couple that resembles a light shadow.") 261 | 262 | (defconst paper-italicised-pen-face 263 | `((t (:foreground ,(paper-colour 'pen) :background ,(paper-colour-paper) 264 | :slant italic))) 265 | "Colour couple that resembles pen colour on paper, italicised.") 266 | 267 | (defconst paper-magenta-on-paper-face 268 | `((t (:foreground ,(paper-colour 'magenta) :background ,(paper-colour-paper))))) 269 | 270 | (defun paper-tints (hex n &optional darken) 271 | "Compute equidistant tints of a given colour. 272 | HEX is the hexedecimal RRGGBB string representation of the colour. 273 | N is an integer denoting how many tints to compute. 274 | If DARKEN is non-nil, compute darker tints, otherwise, lighter." 275 | (cl-loop 276 | for i from 0 to n 277 | collect (hexrgb-increment-equal-rgb 278 | hex 2 279 | (* i 280 | (funcall 281 | (if darken #'- #'identity) 282 | paper-tint-factor))))) 283 | 284 | (defun paper--set-faces () 285 | "Set up faces. 286 | 287 | May be used to refresh after tweaking some variables." 288 | (eval 289 | (let* ((b paper-base-font-size) ; base 290 | (f paper-font-factor) ; factor 291 | (o "org-level-") 292 | (org-faces) 293 | (n 8) 294 | (tints (paper-tints (paper-colour 'magenta) n))) 295 | (dolist (n (number-sequence 1 n)) 296 | (push 297 | `(quote 298 | (,(intern 299 | (concat o (number-to-string n))) 300 | ((t (:slant normal 301 | :weight light 302 | :foreground ,(pop tints) 303 | ,@(when paper-use-varying-heights-for-org-title-headlines 304 | (list 305 | :height 306 | (truncate (+ b (- (* b (+ 1 f)) (* b (* f n)))))))))))) 307 | org-faces)) 308 | 309 | `(custom-theme-set-faces 310 | (quote paper) 311 | ;; === Frame === 312 | (quote (default ,paper-normal-face)) 313 | (quote (cursor ,paper-inverse-face)) 314 | (quote (mode-line ((t (:foreground ,(paper-colour 'white) 315 | :background ,(paper-colour 'magenta) 316 | :box nil))))) 317 | (quote (mode-line-inactive ,paper-light-shadow-face)) 318 | (quote (mode-line-highlight ((t (:foreground ,(paper-colour 'text) 319 | :box nil))))) 320 | (quote (fringe ,paper-normal-face)) 321 | (quote (region ((t (:background ,(paper-colour 'magenta) 322 | :foreground ,(paper-colour 'white)))))) 323 | 324 | ;; === Syntax === 325 | (quote (font-lock-builtin-face ,paper-normal-face)) 326 | (quote (font-lock-comment-face ,paper-italicised-pen-face)) 327 | (quote (font-lock-string-face ,paper-pen-face)) 328 | (quote (font-lock-function-name-face ,paper-pen-face)) 329 | (quote (font-lock-variable-name-face ,paper-pen-face)) 330 | (quote (font-lock-keyword-face ,paper-magenta-on-paper-face)) 331 | (quote (font-lock-type-face ,paper-magenta-on-paper-face)) 332 | (quote (font-lock-constant-face ,paper-magenta-on-paper-face)) 333 | (quote (font-lock-preprocessor-face ,paper-magenta-on-paper-face)) 334 | 335 | ;; === Org titles === 336 | ,(when paper-use-varying-heights-for-org-title-headlines 337 | (quote (quote (org-tag ((t (:height 90 :weight light))))))) 338 | ,@org-faces 339 | 340 | ;; === Line numbers === 341 | (quote (line-number ,paper-light-shadow-face)) 342 | (quote (line-number-current-line ((t (:inherit highlight))))) 343 | 344 | ;; === Various faces === 345 | ;; 346 | ;; Faces which do not sensibly inherit from font-lock. 347 | (quote (sh-heredoc ((t (:inherit font-lock-string-face))))))))) 348 | 349 | (paper--set-faces) 350 | 351 | ;;;###autoload 352 | (and load-file-name 353 | (boundp 'custom-theme-load-path) 354 | (add-to-list 'custom-theme-load-path 355 | (file-name-as-directory 356 | (file-name-directory load-file-name)))) 357 | 358 | (provide 'paper-theme) 359 | (provide-theme 'paper) 360 | ;;; paper-theme.el ends here 361 | -------------------------------------------------------------------------------- /docs/website/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 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 | 635 | Copyright (C) 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 . 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 | Copyright (C) 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 | . 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 | . 675 | -------------------------------------------------------------------------------- /forecast.el: -------------------------------------------------------------------------------- 1 | ;;; forecast.el --- Weather forecasts -*- lexical-binding: t; -*- 2 | ;; 3 | ;; Copyright (C) 2015-2019 Göktuğ Kayaalp 4 | ;; 5 | ;; Author: Göktuğ Kayaalp 6 | ;; Keywords: weather, forecast 7 | ;; Version: 0.8 8 | ;; URL: https://dev.gkayaalp.com/elisp/index.html#forecast-el 9 | ;; Package-Requires: ((emacs "24.4")) 10 | ;; 11 | ;; Permission is hereby granted, free of charge, to any person 12 | ;; obtaining a copy of this software and associated documentation 13 | ;; files (the "Software"), to deal in the Software without 14 | ;; restriction, including without limitation the rights to use, copy, 15 | ;; modify, merge, publish, distribute, sublicense, and/or sell copies 16 | ;; of the Software, and to permit persons to whom the Software is 17 | ;; furnished to do so, subject to the following conditions: 18 | ;; 19 | ;; The above copyright notice and this permission notice shall be 20 | ;; included in all copies or substantial portions of the Software. 21 | ;; 22 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 26 | ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 27 | ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 28 | ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | ;; SOFTWARE. 30 | ;; 31 | 32 | ;;; Commentary: 33 | ;; 34 | ;; forecast.el generates a _weather forecast report_ and displays it 35 | ;; in a buffer. It uses data from Dark Sky (http://darksky.net), and 36 | ;; thus one needs to acquire an api key from them in order to use this 37 | ;; package. They allow 1000 requests a day in their free plan, which 38 | ;; should be enough for any user. 39 | ;; 40 | ;; See Installation section for installation and setup instructions. 41 | ;; 42 | ;; Report bugs to the Issues page in the Github repo: 43 | ;; 44 | ;; https://github.com/cadadr/elisp/issues 45 | ;; 46 | 47 | ;;; Installation: 48 | ;; 49 | ;; See also «Example configuration». 50 | ;; 51 | ;; forecast.el is available on Melpa with the package name `forecast'. 52 | ;; 53 | ;; Otherwise, put the forecast.el file somewhere in your path, then 54 | ;; `require' it. Then set these variables either in your 55 | ;; configuration, or via the customisation group `forecast': 56 | ;; 57 | ;; `calendar-latitude' Latitude of your location float 58 | ;; `calendar-longitude' Longitude of your location float 59 | ;; `forecast-api-key' The API key from Dark Sky string 60 | ;; `calendar-location-name' Name of your location/city string 61 | ;; `forecast-language' Language to use symbol 62 | ;; `forecast-units' Units standard to use symbol 63 | ;; 64 | ;; Only the first three variables above are mandatory. The first four have 65 | ;; *non-sane* defaults, and if `forecast-api-key' is absent, this program 66 | ;; will not run. 67 | ;; 68 | ;; See the documentation for these variables for more detail. 69 | ;; 70 | ;; The API key can be obtained via registering oneself through their 71 | ;; developer website: 72 | ;; 73 | ;; https://darksky.net/dev/ 74 | ;; 75 | ;; See also the docstring for the face `forecast-moon-phase', which 76 | ;; governs the face for the moon phase visualisation. Most fonts will 77 | ;; not have defined the necessary characters, thus one may need to 78 | ;; install a special font, e.g. Quivira (http://quivira-font.com/). 79 | ;; 80 | ;; Then on, you may run the command `forecast' to get the forecast 81 | ;; buffer. The forecast buffer uses `org-level-*' faces, so it will 82 | ;; look like your org files. It is called «*Weather Forecast*». 83 | 84 | ;;; Example configuration: 85 | ;; 86 | ;; (require 'forecast) 87 | ;; (setq calendar-latitude 41.168602 88 | ;; calendar-longitude 29.047024 89 | ;; calendar-location-name "İstanbul, Türkiye" 90 | ;; forecast-api-key "") 91 | ;; 92 | ;; Or, for the privacy of the API key: 93 | ;; 94 | ;; (require 'forecast) 95 | ;; (setq calendar-latitude 41.168602 96 | ;; calendar-longitude 29.047024 97 | ;; calendar-location-name "İstanbul, Türkiye" 98 | ;; forecast-city "İstanbul") 99 | ;; 100 | ;; (load (locate-user-emacs-file "forecast-api-key.el")) 101 | ;; 102 | ;; And in the file ~/.emacs.d/forecast-api-key.el: 103 | ;; 104 | ;; (setq forecast-api-key "") 105 | ;; 106 | 107 | ;;; Usage: 108 | ;; 109 | ;; There are 3 keybindings: 110 | ;; 111 | ;; g Refresh the forecast. Will re-download data. 112 | ;; q Bury the buffer. 113 | ;; C-u q Kill the buffer. 114 | ;; 115 | ;; Two contemporaneous instances of the program *will not* run 116 | ;; correctly, as global state is used to store data. 117 | ;; 118 | ;; The buffer is made up of these elements: 119 | ;; 120 | ;; - At the top, the title, details of location, last update time 121 | ;; 122 | ;; - Temperature and summary 123 | ;; 124 | ;; - Apparent temperature (Feels like ...) and detailed summary 125 | ;; 126 | ;; - Pressure in ATMs, humidity percentage, wind speed and direction 127 | ;; from which wind comes. If available, visibility distance. 128 | ;; 129 | ;; - Graphic showing hourly temperature changes for the upcoming 24 130 | ;; hours. 131 | ;; 132 | ;; - Summary information for upcoming seven days, by default in a 133 | ;; compact graphical format. This format was added in v0.5.0, set 134 | ;; the variable `forecast-old-ui' to a non-nil value to return to 135 | ;; the old UI. 136 | ;; 137 | ;; - Link to the service provider. 138 | ;; 139 | 140 | ;;; Contributing: 141 | ;; 142 | ;; Feel free to send me a pull request. 143 | ;; 144 | ;; Git repo: 145 | ;; 146 | ;; https://github.com/cadadr/elisp 147 | ;; 148 | 149 | ;;; Changes: 150 | ;; 0.8, 04 Sep 2019 151 | ;; - (forecast--sun-position-graphic) Fix bad array reference. 152 | ;; 0.7, 29 Aug 2019 153 | ;; - Switch to maj.min versioning 154 | ;; - (forecast-sun-symbol) New defcustom replacing hardcoded char. 155 | ;; 0.6.4, 23 Sep 2017 156 | ;; - (forecast--get-forecast) Fix truncation of coordinates in request 157 | ;; url (Thanks to @dnbarbato on GitHub, issue#26). 158 | ;; 0.6.3, 16 Sep 2017 159 | ;; - Don't kill all local variables when setting up the mode. 160 | ;; - Fix day names misaligned in the Upcoming week graph. 161 | ;; - Fix arithmetic error on 32bit OSes. 162 | ;; 0.6.2, 22 Feb 2017 163 | ;; - Allow customisations of rain and snow symbols in the Upcoming 164 | ;; table. 165 | ;; - Replace calls to ‘oddp’ w/ ‘cl-oddp’. 166 | ;; - (forecast--get-forecast) Fix call to ‘signal’. 167 | ;; - Fix "Invalid Time Specification" error on Emacs 24.5 (thanks 168 | ;; to GitHub user ‘bdollard’. 169 | ;; v0.6.1, 09 Jan 2017 170 | ;; - Fixed alignment issued in the Upcoming graph. 171 | ;; - Distinctly identify max/min temp in upcoming temp graph. 172 | ;; v0.6.0, 07 Jan 2017 173 | ;; - Switch from forecast.io to darksky.net, their new service. 174 | ;; v0.5.2, 07 Jan 2017 175 | ;; Thanks to Kaushal Modi for these patches: 176 | ;; - Fix data displayed in mirrored fashion in Upcoming graph. 177 | ;; - Upcase wind directions in the Upcoming graph. 178 | ;; - Whitespace fixes. 179 | ;; - Replace the wrong requirement of ‘calendar’ package with 180 | ;; ‘solar’. (Github Issue #17) 181 | ;; v0.5.1, 05 Jan 2017 182 | ;; - Fix bug in hourly graphic that causes incorrect graph. 183 | ;; v0.5.0, 19 Dec 2016 184 | ;; - Add the new compact graphic UI for the Upcoming forecast. 185 | ;; - Add variable ‘forecast-old-ui’ to control which Upcoming UI is used. 186 | ;; - Fix visibility interpreted as a percentage. It is distance. 187 | ;; v0.4.1, 13 May 2016 188 | ;; - Fix use of `loop' instead of `cl-loop'. Thanks to 189 | ;; github.com/Topslick 190 | ;; v0.4.0, 19 April 2016 191 | ;; - Implement an hourly temperature graphic. 192 | ;; - Use the maximum instead of averate for upcoming forecasts. 193 | ;; - Add procedure `forecast--temperature-unit-string', exported from 194 | ;; `forecast--temperature-string'. 195 | ;; - Add variable `forecast-graph-marker' for allowing users to customise 196 | ;; the graph. 197 | ;; v0.3.0, 09 February 2016 198 | ;; - Adapt for customisations via `customize'. 199 | ;; - Allow to customise time representation, via `forecast-time-format'. 200 | ;; (Thanks to Sharon Kimble for the recommendation) 201 | ;; v0.2.0, 05 February 2016 202 | ;; - Fix bugs in `forecast--sun-position-graphic' (Thanks to Zoli Kertesz) 203 | ;; v0.1.9, 06 November 2015 204 | ;; - Fix multibyte string problem. 205 | ;; - Some doc fixes. 206 | ;; v0.1.8, 21 October 2015 207 | ;; - Use special mode as parent mode. 208 | ;; v0.1.7, 20 October 2015 209 | ;; - Doc fixes. 210 | ;; v0.1.6, 20 October 2015 211 | ;; - Prepare for Melpa. 212 | ;; v0.1.5, 28 August 2015 213 | ;; - New release because I can't really do releases properly. 214 | ;; v0.1.4, 28 August 2015 215 | ;; - Fix callback called immaturely in `forecast--load-data' 216 | ;; - Add faces `forecast-upcoming-summary' and `forecast-upcoming-temperature' 217 | ;; v0.1.3, 28 August 2015 218 | ;; - Fix non-prefixed functions. 219 | ;; - Fix some errors regarding rendering. 220 | ;; v0.1.2, 28 August 2015 221 | ;; - Add missing docs. 222 | ;; v0.1.1, 28 August 2015 223 | ;; - Incredibly important changes. 224 | ;; v0.1.0, 28 August 2015 225 | ;; - First release. 226 | ;; 227 | 228 | ;;; Contributors: 229 | ;; 230 | ;; Kaushal Modi 231 | ;; Steve Purcell 232 | ;; Syohei YOSHIDA 233 | ;; TopSlick 234 | ;; bdollard 235 | ;; 236 | 237 | ;;; TODO: 238 | ;; 239 | ;; - Automatically find city and country names. 240 | ;; - Get location from computer? 241 | ;; - I18N? 242 | ;; 243 | 244 | ;;; Code: 245 | (require 'button) 246 | (require 'solar) 247 | (require 'cl-lib) 248 | (require 'json) 249 | (require 'org) ;; Org faces are used. 250 | (require 'subr-x) 251 | (require 'url) 252 | 253 | (defgroup forecast 254 | nil 255 | "Customisations for the forecast.el, the Emacs weather forecasts program." 256 | :group 'emacs 257 | :prefix "forecast-") 258 | 259 | ;;; Variables: 260 | (defcustom forecast-api-key "" 261 | "The API Key." 262 | :type 'string 263 | :group 'forecast) 264 | 265 | (defcustom forecast-api-url "https://api.darksky.net" 266 | "Base url of the remote service API. 267 | Without the trailing slash." 268 | :type 'string 269 | :group 'forecast) 270 | 271 | (defcustom forecast-time-format "%H:%M:%S, %F" 272 | "Format string for displaying timestamps. 273 | See `format-time-string'." 274 | :type 'string 275 | :group 'forecast) 276 | 277 | (defcustom forecast-units 'si 278 | "Sets the unit standard. 279 | `si' Standard units. 280 | `us' US Imperial units. 281 | `ca' Identical to si, but wind speed in km/h 282 | `uk' Identical to si, but wind speed is in miles/h, visibility in miles 283 | 284 | Any other symbol means that the unit standard is automatically 285 | selected based on the location." 286 | :type 'symbol 287 | :group 'forecast) 288 | 289 | (defcustom forecast-language 'en 290 | "Language of the forecast (click the more link if in customisation buffer). 291 | One of: ar (Arabic), bs (Bosnian), de (German), en (English, 292 | which is the default), es (Spanish), fr (French), it (Italian), 293 | nl (Dutch), pl (Polish), pt (Portuguese), ru (Russian), 294 | sk (Slovak), sv (Swedish), tet (Tetum), tr (Turkish), 295 | uk (Ukrainian), x-pig-latin (Igpay Atinlay), or zh (Chinese). 296 | 297 | If not one of these, then `en' is selected." 298 | :type 'symbol 299 | :group 'forecast) 300 | 301 | (defcustom forecast-graph-marker "█" 302 | "A single-character string for the graph marks." 303 | :type 'string 304 | :group 'forecast) 305 | 306 | (defcustom forecast-graph-marker-upcoming-max "▀" 307 | "A single-character string for the upcoming graph marking the max temperature." 308 | :type 'string 309 | :group 'forecast) 310 | 311 | (defcustom forecast-graph-marker-upcoming-min "▄" 312 | "A single-character string for the upcoming graph marking the min temperature." 313 | :type 'string 314 | :group 'forecast) 315 | 316 | (defcustom forecast-snow-symbol "❄" 317 | "A single-character string for a symbol to represent snowy wheather." 318 | :type 'string 319 | :group 'forecast) 320 | 321 | (defcustom forecast-rain-symbol "⛆" 322 | "A single-character string for a symbol to represent snowy wheather." 323 | :type 'string 324 | :group 'forecast) 325 | 326 | (defcustom forecast-sun-symbol "☉" 327 | "A single-character string for a symbol to represent snowy wheather." 328 | :type 'string 329 | :group 'forecast) 330 | 331 | (defcustom forecast-old-ui nil 332 | "If t, use the old text listing for upcoming forecast." 333 | :type 'boolean 334 | :group 'forecast) 335 | 336 | (defvar forecast--debug nil 337 | "Whether to surpress error messages.") 338 | 339 | (defconst forecast--supported-languages 340 | '(ar bs de en es fr it nl pl pt ru sk sv tet tr uk x-pig-latin or zh) 341 | "List of supported languages.") 342 | 343 | (defvar forecast--data nil 344 | "Forecast data container.") 345 | 346 | (defvar forecast--update-time 0 347 | "The time of last update to the buffer. 348 | As per returned from `current-time'.") 349 | 350 | (defvar forecast--buffer nil 351 | "The Forecast buffer object or name.") 352 | 353 | ;;; Faces: 354 | (defface forecast-moon-phase 355 | nil 356 | "Face for visualisation of moon-phase. 357 | 358 | Ideally, set the font family attribute to some font that supports 359 | the characters 01F311-01F318, e.g. Quivira, which can be found at 360 | : 361 | 362 | \(set-face-attribute 'forecast-moon-phase nil 363 | :font \"Quivira\") 364 | 365 | On Linux, one can download the Quivira font and put that under 366 | the $HOME/.fonts directory for using the font. There are not 367 | many fonts that support this character. There are also the 368 | BabelStone fonts.") 369 | 370 | (defface forecast-rain-symbol-face 371 | nil 372 | "Face for the rain symbol.") 373 | 374 | (defface forecast-snow-symbol-face 375 | nil 376 | "Face for the snow symbol.") 377 | 378 | ;;; Functions: 379 | (defun forecast--assoca (keyseq list) 380 | "Arbitrary depth multi-level alist query. 381 | 382 | KEYSEQ is the list of keys to look up in the LIST. The first key 383 | from KEYSEQ is looked up in the LIST, then the next key from 384 | KEYSEQ is looked up in the CDR of the return value of that 385 | operation, and so on until all the KEYSEQ is exhausted. The 386 | resultant value is returned, or nil, in case one or more keys are 387 | not found in the LIST." 388 | (let ((ks keyseq) 389 | (ret list)) 390 | (dolist (k ks ret) 391 | (setq ret (cdr (assoc k ret)))))) 392 | 393 | (defun forecast--insert (str) 394 | "Insert STR to the buffer, at point. 395 | 396 | Assume STR to be a unibyte string, convert it to multibyte, then 397 | insert it." 398 | ;; XXX I do not really understand why this works. In my *scratch*, 399 | ;; I was able to apply `string-as-multibyte' directly. However, it 400 | ;; works. 401 | (insert (string-as-multibyte (string-as-unibyte str)))) 402 | 403 | (defun forecast--insert-with-props (text &rest props) 404 | "Insert the given string TEXT and set PROPS lock on it." 405 | (let ((p1) (p2)) 406 | (setf p1 (point)) 407 | (forecast--insert text) 408 | (setf p2 (point)) 409 | (add-text-properties p1 p2 props))) 410 | 411 | (defun forecast--insert-format (str &rest fa) 412 | "Apply format, then insert into the buffer. 413 | 414 | STR is the format string. FA are the arguments to format. See 415 | `format' for details." 416 | (forecast--insert (apply 'format str fa))) 417 | 418 | (defun forecast--get-forecast (callback) 419 | "Get the forecasts from the remote API. 420 | 421 | CALLBACK is a function of a single argument, WEATHER, the Elisp 422 | representation of the returned JSON from the API." 423 | (let ((la calendar-latitude) 424 | (lo calendar-longitude) 425 | (request-url)) 426 | ;; Make sure LO and LA end up being numbers. 427 | (when (not (cl-every #'numberp (list la lo))) 428 | (user-error "Forecast: Latitude and longitude have to be numbers")) 429 | ;; Check whether we're set for making an API call. 430 | (when (or (not forecast-api-key) 431 | (string-empty-p forecast-api-key)) 432 | (user-error "Forecast: `forecast-api-key' not set")) 433 | (setf request-url 434 | (format "%s/forecast/%s/%f,%f?%s" 435 | forecast-api-url 436 | forecast-api-key 437 | la lo 438 | (forecast--api-opts))) 439 | (let ((cb (lambda (status &optional args) 440 | (ignore args) 441 | (let ((err (plist-get status :error))) 442 | (when err 443 | (funcall 'signal (car err) (cdr err)))) 444 | (save-excursion 445 | (goto-char (point-min)) 446 | (re-search-forward "^{") 447 | (beginning-of-line) 448 | (funcall callback 449 | (json-read-from-string 450 | (buffer-substring (point) 451 | (point-max)))))))) 452 | (url-retrieve request-url cb nil 453 | forecast--debug 454 | t ; Inhibit cookies, they are not necessary. 455 | )))) 456 | 457 | (defun forecast--api-opts () 458 | "Generate API options string." 459 | (let ((f "%s=%s") 460 | (opts)) 461 | (push (format f "units" 462 | (cl-case forecast-units 463 | (si "si") 464 | (us "us") 465 | (ca "ca") 466 | (uk "uk2") 467 | (otherwise "auto"))) 468 | opts) 469 | (push (format f "lang" 470 | (symbol-name 471 | (if (memq forecast-language forecast--supported-languages) 472 | forecast-language 473 | 'en))) 474 | opts) 475 | (mapconcat 'identity opts "&"))) 476 | 477 | (defun forecast--load-data (callback) 478 | "Load the forecast data into `forecast--data'. 479 | 480 | After the data is loaded, the CALLBACK function is called, 481 | passing into it as the argument CBARG. 482 | 483 | Arguments LAT, LONG and TIME are identical to those of 484 | `forecast--get-forecast'. 485 | 486 | Returns NIL, as it is asynchronous." 487 | (forecast--get-forecast (lambda (w) 488 | (setq forecast--data w) 489 | (message "Forecast: updated data.") 490 | (setf forecast--update-time 491 | (seconds-to-time 492 | (forecast--assoca '(currently time) 493 | forecast--data))) 494 | (funcall callback)))) 495 | 496 | (defun forecast--summary () 497 | "Return an human-readable summary of the current forecast." 498 | (forecast--assoca '(currently summary) forecast--data)) 499 | 500 | (defun forecast--temperature () 501 | "Return the temperature from the current forecast. 502 | 503 | If not available, i.e. not using 'currently, then return the 504 | maximum." 505 | (or (forecast--assoca '(currently temperature) forecast--data) 506 | (forecast--assoca '(currently temperatureMax) forecast--data))) 507 | 508 | (defun forecast--temperature-unit () 509 | "Return the temperature unit. 510 | 511 | Returns 'F for Fahrenheit, 'C for Centigrade." 512 | (cl-case forecast-units 513 | (us 'F) 514 | (otherwise 'C))) 515 | 516 | (defun forecast--timezone () 517 | "The time zone of the forecast." 518 | (forecast--assoca '(timezone) forecast--data)) 519 | 520 | (defun forecast--offset () 521 | "The offset of the timezone of the forecast from GMT." 522 | (forecast--assoca '(offset) forecast--data)) 523 | 524 | (defun forecast--temperature-unit-string () 525 | "Return the proper string for temperature unit." 526 | (cl-case (forecast--temperature-unit) 527 | (C "°C") 528 | (F "°F"))) 529 | 530 | (defun forecast--temperature-string () 531 | "Return a string representing the current temperature. 532 | 533 | The temperature, plus the degree sign, plus the unit in capital 534 | letter." 535 | (format "%.0f%s" 536 | (forecast--temperature) 537 | (forecast--temperature-unit-string))) 538 | 539 | (defun forecast--pressure (unit) 540 | "Return pressure in UNIT." 541 | (let ((p (forecast--assoca '(currently pressure) forecast--data))) 542 | (cl-case unit 543 | (bar p) 544 | (atm (forecast--bars-to-atm p)) 545 | (otherwise (error "Forecast: unknown pressure unit: %s" unit))))) 546 | 547 | (defun forecast--bars-to-atm (bars) 548 | "Convert pressure from BARS to ATM." 549 | (/ bars 1013.25)) 550 | 551 | (defun forecast--wind-speed () 552 | "Return the value for the wind speed." 553 | (forecast--assoca '(currently windSpeed) forecast--data)) 554 | 555 | (defun forecast--wind-unit () 556 | "Find the correct unit for the wind value." 557 | (cl-case forecast-units 558 | ((us uk) "mph") 559 | ( ca "km/h") 560 | ( si "m/s"))) 561 | 562 | (defun forecast--apparent-temperature () 563 | "Feels-like temperature, truncated." 564 | (truncate (or (forecast--assoca '(currently apparentTemperature) forecast--data) 565 | (/ (+ (forecast--assoca '(currently apparentTemperatureMin) forecast--data) 566 | (forecast--assoca '(currently apparentTemperatureMax) forecast--data)) 567 | 2)))) 568 | 569 | (defun forecast--format-current-time (formats) 570 | "Format forecast's time with a format string. 571 | FORMATS is the format string to use. See `format-time-string'." 572 | (format-time-string 573 | formats 574 | (seconds-to-time (forecast--assoca '(currently time) forecast--data)))) 575 | 576 | (defun forecast--wind-direction () 577 | "Calculate and return the direction of current wind." 578 | (if (zerop (forecast--wind-speed)) "" 579 | (let ((dir (forecast--assoca '(currently windBearing) forecast--data))) 580 | (upcase (symbol-name (forecast--cardinal-from-degrees dir)))))) 581 | 582 | (defun forecast--cardinal-from-degrees (d) 583 | "Turn degrees to one of 4 equivalent cardinal directions or a composed one. 584 | 585 | D is a number value, degrees." 586 | (cl-case (truncate (/ d 22.5)) 587 | (0 'n) 588 | (1 'n-ne) 589 | (2 'ne) 590 | (3 'e-ne) 591 | (4 'e) 592 | (5 'e-se) 593 | (6 'se) 594 | (7 's-se) 595 | (8 's) 596 | (9 's-sw) 597 | (10 'sw) 598 | (11 'w-sw) 599 | (12 'w) 600 | (13 'w-nw) 601 | (14 'nw) 602 | (15 'n-nw) 603 | (16 'n) 604 | ;; Wrap around.. 605 | (otherwise (forecast--cardinal-from-degrees (- d 360))))) 606 | 607 | 608 | (defun forecast--sun-position-graphic () 609 | "Visualise the time since the rise of the sun and the time to the set thereof. 610 | 611 | E.g.: 612 | 613 | Quasi-midday: 614 | ┝━━━━━━━━☉━━━━━━━━━━━┥ 615 | Sunrise: 616 | ☉━━━━━━━━━━━━━━━━━━━━┥ 617 | Sunset: 618 | ┝━━━━━━━━━━━━━━━━━━━━☉ 619 | 620 | Uses box-drawing characters." 621 | (let* ((today (aref (forecast--assoca '(daily data) forecast--data) 0)) 622 | (sunrise (forecast--assoca '(sunriseTime) today)) 623 | (sunset (forecast--assoca '(sunsetTime) today)) 624 | (now (float-time)) 625 | (daylen (- sunset sunrise)) 626 | (sunsec (- now sunrise)) 627 | (wwidth 58) 628 | (graph (concat "┝" (make-string (- wwidth 5) ?━) "┥")) 629 | (sun (aref forecast-sun-symbol 0)) 630 | (pos (cond 631 | ((< sunrise sunset now) (- wwidth 4)) 632 | ((> sunrise now) 0) 633 | (t (truncate 634 | (let ((x (/ sunsec (/ daylen wwidth)))) 635 | (- x 3))))))) 636 | (aset graph pos sun) 637 | graph)) 638 | 639 | (defun forecast--detailed-summary () 640 | "The more detailed summary of the forecast." 641 | (forecast--assoca '(summary) (aref (forecast--assoca '(daily data) forecast--data) 0))) 642 | 643 | (defun forecast--visualised-moon-phase () 644 | "Visualise the moon phase w/ unicode characters. 645 | 646 | See the face `forecast-moon-phase'" 647 | (let ((mp (forecast--assoca '(moonPhase) 648 | (aref (forecast--assoca '(daily data) forecast--data) 0)))) 649 | (cond ((zerop mp) "🌑") ; New moon 650 | ((< mp .25) "🌒") ; Waxing crescent moon 651 | ((= mp .25) "🌓") ; First quarter moon 652 | ((< mp .5) "🌔") ; Waxing gibbous moon 653 | ((- mp .5) "🌕") ; Full moon 654 | ((< mp .75) "🌖") ; Waning gibbous moon 655 | ((= mp .75) "🌗") ; Last quarter moon 656 | ((<= mp 1) "🌘") ; Waning crescent moon 657 | ))) 658 | 659 | (defun forecast--humidity () 660 | "Humidity percentage." 661 | (* 100 (forecast--assoca '(currently humidity) forecast--data))) 662 | 663 | (defun forecast--visibility () 664 | "Visibility range." 665 | (forecast--assoca '(currently visibility) forecast--data)) 666 | 667 | (defun forecast--insert-atmosphere-details () 668 | "Insert details like pressure, humidity, visibility and wind." 669 | (forecast--insert-format 670 | "Pressure %1.3f atm; Humidity %.1f%%" 671 | (forecast--pressure 'atm) 672 | (forecast--humidity)) 673 | (newline) 674 | (let ((v (forecast--visibility))) 675 | (when v 676 | (forecast--insert-format "Visibility %d %s; " 677 | v (if (eq forecast-units 'uk) "miles" "km")))) 678 | (forecast--insert-format 679 | "Wind %s %s, from %s" 680 | (forecast--wind-speed) 681 | (forecast--wind-unit) 682 | (forecast--wind-direction))) 683 | 684 | (defun forecast--insert-upcoming-graph () 685 | "Insert a line graph of daily high and daily low temperatures, and other data. 686 | Other data being precipitation, humidity, pressure, wind speed, 687 | wind directions." 688 | (let* 689 | ((data (reverse 690 | ;; Listify the data, which is an array. 691 | (append (forecast--assoca '(daily data) forecast--data) nil))) 692 | hi lo precip hum pres wind max-hi min-lo time) 693 | ;; Collect data 694 | (dolist (b data) 695 | (push (forecast--assoca '(time) b) time) 696 | (push (truncate (forecast--assoca '(temperatureMax) b)) hi) 697 | (push (truncate (forecast--assoca '(temperatureMin) b)) lo) 698 | (push (forecast--assoca '(humidity) b) hum) 699 | (push (forecast--bars-to-atm 700 | (forecast--assoca '(pressure) b)) pres) 701 | (push `(,(forecast--assoca '(windSpeed) b) 702 | . 703 | ,(let ((dir (forecast--assoca '(windBearing) b))) 704 | (forecast--cardinal-from-degrees dir))) 705 | wind) 706 | (push `(,(forecast--assoca '(precipProbability) b) 707 | . 708 | ,(forecast--assoca '(precipType) b)) 709 | precip)) 710 | ;; Find the limits of the graph. 711 | (setq max-hi (apply #'max hi) 712 | min-lo (apply #'min lo)) 713 | ;; Insert the graph 714 | (forecast--insert-with-props 715 | "Upcoming week, graph of high and low estimates, and other information\n" 716 | 'font-lock-face 'org-level-2) 717 | (forecast--insert-format "%4s \n" (forecast--temperature-unit-string)) 718 | (dolist (i (number-sequence max-hi min-lo -1)) 719 | (forecast--insert-format "%4d " i) 720 | (cl-loop for j upfrom 0 to 7 do 721 | (insert 722 | (cond ((= i (nth j hi)) 723 | (if (cl-oddp i) 724 | (concat "-|-" forecast-graph-marker-upcoming-max "-|-") 725 | (concat " | " forecast-graph-marker-upcoming-max " | "))) 726 | ((= i (nth j lo)) 727 | (if (cl-oddp i) 728 | (concat "-|-" forecast-graph-marker-upcoming-min "-|-") 729 | (concat " | " forecast-graph-marker-upcoming-min " | "))) 730 | ((and (< i (nth j hi)) 731 | (> i (nth j lo))) 732 | (if (cl-oddp i) 733 | (concat "-|-" forecast-graph-marker "-|-") 734 | (concat " | " forecast-graph-marker " | "))) 735 | ((cl-oddp i) "-|---|-") 736 | (t " | | ")))) 737 | (newline)) 738 | (forecast--insert-format 739 | "Day: %s\n" (mapconcat 740 | (lambda (tm) 741 | (format-time-string 742 | "%3a " (seconds-to-time tm))) time "")) 743 | ;; precipitation 744 | (insert " ") 745 | (mapc (lambda (p) 746 | (let ((pp (car p)) (pt (cdr p))) 747 | (insert (if (zerop pp) 748 | " " 749 | (format " %%%-3d%s " (* 100 pp) 750 | (cond ((string= pt "rain") 751 | (propertize 752 | forecast-rain-symbol 753 | 'face 'forecast-rain-symbol-face)) 754 | ((string= pt "snow") 755 | (propertize 756 | forecast-snow-symbol 757 | 'face 'forecast-snow-symbol-face)))))))) 758 | precip) 759 | (insert " Precipitation\n") 760 | ;; wind 761 | (insert " ") 762 | (mapc (lambda (w) 763 | (let ((ws (car w))) 764 | (forecast--insert-format " %-4d " ws))) 765 | wind) 766 | (insert (format 767 | " Wind speed (%s)\n" 768 | (forecast--wind-unit))) 769 | (insert " ") 770 | (mapc (lambda (w) 771 | (let ((wb (upcase (symbol-name (cdr w))))) 772 | (forecast--insert-format " %-4s " wb))) 773 | wind) 774 | (insert " Wind bearing\n") 775 | ;; humidity 776 | (insert " ") 777 | (mapc (lambda (h) (forecast--insert-format " %#1.1f " h)) hum) 778 | (insert " Humidity\n") 779 | ;; pressure 780 | (insert " ") 781 | (mapc (lambda (p) (forecast--insert-format " %#1.3f" p)) pres) 782 | (insert " Pressure (atm)\n"))) 783 | 784 | (defun forecast--insert-upcoming-text () 785 | "Forecasts about upcoming 7 days. 786 | The old style." 787 | (forecast--insert-with-props 788 | "Upcoming" 789 | 'font-lock-face 'org-level-2) 790 | (newline) 791 | (let ((b forecast--data)) 792 | (cl-loop for i from 1 to 7 793 | do 794 | (setcdr (assoc 'currently b) 795 | (aref (forecast--assoca '(daily data) b) i)) 796 | (let ((forecast--data b)) 797 | (forecast--insert-with-props 798 | (forecast--format-current-time "%A") 799 | 'font-lock-face 'org-level-3) 800 | (newline) 801 | (forecast--insert-with-props 802 | (forecast--temperature-string) 803 | 'font-lock-face 'forecast-upcoming-temperature) 804 | (insert ", ") 805 | (forecast--insert-with-props 806 | (forecast--summary) 807 | 'font-lock-face 'forecast-upcoming-summary) 808 | (newline) 809 | (forecast--insert-atmosphere-details) 810 | (newline 2))))) 811 | 812 | (defun forecast--insert-io-link () 813 | "Insert link to the serice provider." 814 | (newline) 815 | (insert "Powered by") 816 | (insert " ") 817 | (insert-text-button 818 | "Dark Sky" 819 | 'follow-link t 'action 820 | (lambda (b) 821 | (ignore b) 822 | (browse-url (format "https://darksky.net/forecast/%s,%s/us12/en" 823 | (number-to-string calendar-latitude) 824 | (number-to-string calendar-longitude)))))) 825 | 826 | (defun forecast--insert-location () 827 | "Insert location details." 828 | (forecast--insert-with-props 829 | (format "Forecasts for %s, %s" 830 | calendar-location-name 831 | (forecast--format-current-time "%F")) 832 | 'font-lock-face 'org-level-5) 833 | (newline) 834 | (forecast--insert-format "Lat: %f, Long: %f" 835 | calendar-latitude 836 | calendar-longitude)) 837 | 838 | (defun forecast--insert-update-time () 839 | "Insert the last update time." 840 | (insert (format-time-string 841 | (concat "Last updated " 842 | forecast-time-format) 843 | forecast--update-time)) 844 | (forecast--insert-format "; %s, GMT+%d" 845 | (forecast--timezone) 846 | (forecast--offset))) 847 | 848 | (defun forecast--insert-summary () 849 | "Insert the summary of today's forecast." 850 | (forecast--insert-with-props 851 | (format "%s - %s" 852 | (forecast--temperature-string) 853 | (forecast--summary)) 854 | 'font-lock-face 'org-level-1) 855 | (newline) 856 | (forecast--insert-with-props 857 | (format "Feels like %d, %s" 858 | (forecast--apparent-temperature) 859 | (forecast--detailed-summary)) 860 | 'font-lock-face 'org-level-4)) 861 | 862 | (defun forecast--insert-sun-moon-graphic () 863 | "Insert the combined sun phase and moon phase visualisations." 864 | (forecast--insert-with-props 865 | (forecast--sun-position-graphic) 866 | 'intangible t) 867 | (forecast--insert-with-props 868 | (forecast--visualised-moon-phase) 869 | 'font-lock-face 'forecast-moon-phase)) 870 | 871 | (defun forecast--insert-hourly-forecast () 872 | "Insert a listing of hourly forecasts for today." 873 | ;; Display a graphic of hourly temperature. 874 | (let* ((data (forecast--assoca '(hourly data) forecast--data)) 875 | (temps (mapcar (lambda (x) 876 | (truncate 877 | (forecast--assoca '(temperature) x))) 878 | data)) 879 | (min-today (apply 'min temps)) 880 | (max-today (apply 'max temps)) 881 | (x (1- (length temps)))) 882 | (forecast--insert-with-props 883 | "Temperature graphic for the next 24 hours\n" 884 | 'font-lock-face 'org-level-2) 885 | (forecast--insert-format "%4s \n" (forecast--temperature-unit-string)) 886 | (dolist (i (number-sequence max-today min-today -1)) 887 | (forecast--insert-format "%4d " i) 888 | (cl-loop for j from 0 to x do 889 | (insert 890 | (cond ((= i (nth j temps)) forecast-graph-marker) 891 | ((cl-oddp i) "-") 892 | (t " ")))) 893 | (newline)) 894 | (insert "Hour: ") 895 | (cl-loop for j from 0 to (1- (length data)) by 3 do 896 | (let* ((time (seconds-to-time 897 | (forecast--assoca '(time) (aref data j)))) 898 | (ts (format-time-string "%H" time))) 899 | (forecast--insert-format "%-3s" ts))) 900 | (newline))) 901 | 902 | (defun forecast--make-buffer (buffername) 903 | "(Re)prepare the forecast buffer. 904 | 905 | BUFFERNAME is the name of the forecast buffer to use. Created if 906 | absent." 907 | (with-current-buffer (get-buffer-create buffername) 908 | (setq forecast--buffer (current-buffer)) 909 | (when (not buffer-read-only) 910 | (read-only-mode)) 911 | (let ((inhibit-read-only t)) 912 | (erase-buffer) 913 | ;; Begin inserting data to the buffer. 914 | (forecast--insert-location) 915 | (newline) 916 | (forecast--insert-update-time) 917 | (newline) 918 | (newline) 919 | (forecast--insert-summary) 920 | (newline) 921 | (forecast--insert-sun-moon-graphic) 922 | (newline) 923 | (forecast--insert-atmosphere-details) 924 | (newline 2) 925 | (forecast--insert-hourly-forecast) 926 | (newline) 927 | (if forecast-old-ui 928 | (forecast--insert-upcoming-text) 929 | (forecast--insert-upcoming-graph)) 930 | (newline) 931 | (forecast--insert-io-link) 932 | 933 | ;; Finished preparing buffer. 934 | (goto-char (point-min)) 935 | (forecast-mode)) 936 | ;; Return the prepared buffer. 937 | (current-buffer))) 938 | 939 | ;;;###autoload 940 | (defun forecast () 941 | "Bring up the forecast buffer. 942 | Keybindings for `forecast-mode': 943 | \\{forecast-mode-map}" 944 | (interactive) 945 | (forecast--load-data 946 | (lambda () 947 | (let ((buf (forecast--make-buffer "*Weather Forecast*"))) 948 | (switch-to-buffer buf))))) 949 | 950 | (defalias 'forecast-today 'forecast) 951 | 952 | (defvar forecast-mode-map 953 | (let ((map (make-sparse-keymap))) 954 | (suppress-keymap map) 955 | (prog1 map 956 | (define-key map "g" 'forecast-refresh) 957 | (define-key map "q" 'forecast-quit)))) 958 | 959 | ;;; Major mode and keybindings: 960 | (define-derived-mode forecast-mode special-mode 961 | "Weather Forecast Mode" 962 | "Major mode for weather forecast buffers. 963 | Keybindings for `forecast-mode': 964 | \\{forecast-mode-map}" 965 | (use-local-map forecast-mode-map) 966 | (buffer-disable-undo)) 967 | 968 | (defun forecast-refresh () 969 | "Refresh the current forecast buffer." 970 | (interactive) 971 | (when (not forecast--buffer) 972 | (user-error "Run `forecast' instead")) 973 | (forecast--load-data 974 | (lambda () 975 | (forecast--make-buffer (buffer-name forecast--buffer))))) 976 | 977 | (defun forecast-quit (&optional quit) 978 | "Put away the Forecast buffer. 979 | 980 | If QUIT is non-nil or the universal argument is non-nil, kill the 981 | buffer." 982 | (interactive "^P") 983 | (quit-window quit)) 984 | 985 | (provide 'forecast) 986 | ;;; forecast.el ends here 987 | --------------------------------------------------------------------------------