2019-10-09 13:13:56 +02:00
|
|
|
;;; fonts.el --- Font preferences -*- lexical-binding: t -*-
|
2020-09-01 11:17:43 +02:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; Package-Requires: ((emacs "24.3"))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Control my font preferences with ELisp.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'maybe)
|
2020-09-02 16:23:46 +02:00
|
|
|
(require 'cl-lib)
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Constants
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2022-11-21 03:46:15 +01:00
|
|
|
(defgroup fonts nil
|
|
|
|
"Customize group for fonts configuration.")
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2022-11-21 03:46:15 +01:00
|
|
|
(defcustom fonts-size "10"
|
|
|
|
"My preferred default font-size."
|
|
|
|
:group 'fonts)
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2022-11-21 03:46:15 +01:00
|
|
|
(defcustom fonts-size-step 10
|
|
|
|
"The amount (%) by which to increase or decrease a font."
|
|
|
|
:group 'fonts)
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Functions
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun fonts-set (font &optional size)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Change the font to `FONT' with option integer, SIZE, in pixels."
|
2020-08-31 15:59:48 +02:00
|
|
|
(if (maybe-some? size)
|
2020-09-01 00:28:47 +02:00
|
|
|
(set-frame-font (string-format "%s %s" font size) nil t)
|
2019-10-09 13:13:56 +02:00
|
|
|
(set-frame-font font nil t)))
|
|
|
|
|
2022-11-21 03:46:15 +01:00
|
|
|
(defun fonts-current ()
|
|
|
|
"Return the currently enabled font."
|
|
|
|
(symbol-name (font-get (face-attribute 'default :font) :family)))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun fonts-increase-size ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Increase font size."
|
|
|
|
(interactive)
|
|
|
|
(->> (face-attribute 'default :height)
|
2020-09-01 11:17:43 +02:00
|
|
|
(+ fonts-size-step)
|
2019-10-09 13:13:56 +02:00
|
|
|
(set-face-attribute 'default (selected-frame) :height)))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun fonts-decrease-size ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Decrease font size."
|
|
|
|
(interactive)
|
|
|
|
(->> (face-attribute 'default :height)
|
2020-09-01 11:17:43 +02:00
|
|
|
(+ (- fonts-size-step))
|
2019-10-09 13:13:56 +02:00
|
|
|
(set-face-attribute 'default (selected-frame) :height)))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun fonts-reset-size ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Restore font size to its default value."
|
|
|
|
(interactive)
|
2022-11-19 19:20:12 +01:00
|
|
|
(fonts-set (fonts-current) fonts-size))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2020-09-04 22:03:16 +02:00
|
|
|
(defun fonts-enable-ligatures ()
|
|
|
|
"Call this function to enable ligatures."
|
|
|
|
(interactive)
|
|
|
|
(let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)")
|
|
|
|
(35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)") ;;
|
|
|
|
(36 . ".\\(?:>\\)")
|
|
|
|
(37 . ".\\(?:\\(?:%%\\)\\|%\\)")
|
|
|
|
(38 . ".\\(?:\\(?:&&\\)\\|&\\)")
|
|
|
|
(42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)") ;;
|
|
|
|
(43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)")
|
|
|
|
(45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
|
|
|
|
(46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)") ;;
|
|
|
|
(47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
|
|
|
|
(48 . ".\\(?:x[a-zA-Z]\\)")
|
|
|
|
(58 . ".\\(?:::\\|[:=]\\)")
|
|
|
|
(59 . ".\\(?:;;\\|;\\)")
|
|
|
|
(60 . ".\\(?:\\(?:!--\\)\\|\\(?:~~\\|->\\|\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[*$+~/<=>|-]\\)")
|
|
|
|
(61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
|
|
|
|
(62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
|
|
|
|
(63 . ".\\(?:\\(\\?\\?\\)\\|[:=?]\\)")
|
|
|
|
(91 . ".\\(?:]\\)")
|
|
|
|
(92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
|
|
|
|
(94 . ".\\(?:=\\)")
|
|
|
|
(119 . ".\\(?:ww\\)")
|
|
|
|
(123 . ".\\(?:-\\)")
|
|
|
|
(124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
|
|
|
|
(126 . ".\\(?:~>\\|~~\\|[>=@~-]\\)"))))
|
|
|
|
(dolist (char-regexp alist)
|
|
|
|
(set-char-table-range composition-function-table (car char-regexp)
|
|
|
|
`([,(cdr char-regexp) 0 font-shape-gstring])))))
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
(provide 'fonts)
|
|
|
|
;;; fonts.el ends here
|