2019-07-20 23:59:29 -05:00
|
|
|
;;; lang/scheme/autoload.el -*- lexical-binding: t; -*-
|
|
|
|
|
2021-04-25 18:35:49 -04:00
|
|
|
;; HACK `geiser' has poor autoload etiquette. It calls
|
2021-04-20 22:11:19 -04:00
|
|
|
;; `geiser-activate-implementation' and `geiser-implementation-extension'
|
|
|
|
;; in their autoloads files. Sure, these functions are autoloaded, but this
|
|
|
|
;; needlessly (and unavoidably) pulls in the `geiser-impl' package (et co)
|
|
|
|
;; when geiser-X's autoloads are read (i.e. at startup).
|
|
|
|
;;
|
|
|
|
;; I rectify this by inlining calls to these two functions (and the
|
|
|
|
;; `geiser-impl--add-to-alist' sub-call in
|
|
|
|
;; `geiser-implementation-extension'), and autoloading the two variables
|
2021-04-25 18:35:49 -04:00
|
|
|
;; they operate on. I do this from our autoloads file (which is
|
|
|
|
;; byte-compiled and read at startup before package autoloads).
|
2021-04-20 22:11:19 -04:00
|
|
|
;; TODO At some point, PR this behavior upstream (but not verbatim!)
|
2021-04-15 00:38:39 -04:00
|
|
|
;;;###autoload (defvar geiser-active-implementations ())
|
|
|
|
;;;###autoload (defvar geiser-implementations-alist ())
|
2021-04-20 22:11:19 -04:00
|
|
|
;;;###autoload (eval-and-compile (dolist (sym '(geiser-impl--add-to-alist geiser-activate-implementation geiser-implementation-extension)) (put sym 'byte-optimizer 'byte-compile-inline-expand)))
|
2021-04-13 22:41:31 -04:00
|
|
|
|
|
|
|
|
2020-04-24 00:34:28 -04:00
|
|
|
(defvar calculate-lisp-indent-last-sexp)
|
|
|
|
;; Adapted from https://github.com/alezost/emacs-config/blob/master/utils/al-scheme.el#L76-L123
|
|
|
|
;;;###autoload
|
2021-04-20 22:11:19 -04:00
|
|
|
(defun +scheme-indent-function-a (indent-point state)
|
2020-04-24 00:34:28 -04:00
|
|
|
"Advice to replace `scheme-indent-function'.
|
|
|
|
|
2021-04-20 22:11:19 -04:00
|
|
|
This function is the same as `scheme-indent-function' except it properly indents
|
|
|
|
property lists and names starting with 'default'."
|
2020-04-24 00:34:28 -04:00
|
|
|
(let ((normal-indent (current-column)))
|
|
|
|
(goto-char (1+ (elt state 1)))
|
|
|
|
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
|
|
(if (and (elt state 2)
|
|
|
|
;; NOTE looking-at -> looking-at-p
|
|
|
|
(not (looking-at-p "\\sw\\|\\s_")))
|
2020-05-01 01:22:14 -04:00
|
|
|
(progn
|
|
|
|
;; NOTE (if (not ...) (progn ...)) -> (unless ... ...)
|
|
|
|
(unless (> (save-excursion (forward-line 1) (point))
|
|
|
|
calculate-lisp-indent-last-sexp)
|
|
|
|
(goto-char calculate-lisp-indent-last-sexp)
|
|
|
|
(beginning-of-line)
|
|
|
|
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t))
|
|
|
|
(backward-prefix-chars)
|
|
|
|
(current-column))
|
2021-04-16 12:30:49 -04:00
|
|
|
;; NOTE let -> let* & moved `method' def into let bindings
|
2020-04-24 00:34:28 -04:00
|
|
|
(let* ((function (buffer-substring
|
|
|
|
(point) (progn (forward-sexp 1) (point))))
|
|
|
|
(method (or (get (intern-soft function) 'scheme-indent-function)
|
|
|
|
(get (intern-soft function) 'scheme-indent-hook))))
|
|
|
|
(cond ((or (eq method 'defun)
|
|
|
|
(and (null method)
|
|
|
|
(> (length function) 3)
|
|
|
|
;; NOTE string-match -> string-match-p
|
|
|
|
;; NOTE The original regexp is "\\`def" but it will mess
|
2021-04-16 12:30:49 -04:00
|
|
|
;; up indentation with such names as 'default-...'.
|
2020-05-01 01:22:14 -04:00
|
|
|
(string-match-p "\\`def" function)))
|
2020-04-24 00:34:28 -04:00
|
|
|
(lisp-indent-defform state indent-point))
|
|
|
|
;; NOTE Added this clause to handle alignment of keyword symbols
|
|
|
|
((and (null method)
|
|
|
|
(> (length function) 1)
|
2020-05-01 01:22:14 -04:00
|
|
|
;; NOTE string-match -> string-match-p
|
2020-04-24 00:34:28 -04:00
|
|
|
(string-match-p "\\`:" function))
|
|
|
|
(let ((lisp-body-indent 1))
|
|
|
|
(lisp-indent-defform state indent-point)))
|
|
|
|
((integerp method)
|
|
|
|
(lisp-indent-specform method state indent-point normal-indent))
|
|
|
|
(method
|
|
|
|
(funcall method state indent-point normal-indent)))))))
|
|
|
|
|
2019-07-20 23:59:29 -05:00
|
|
|
;;;###autoload
|
2020-06-10 00:17:03 +10:00
|
|
|
(defun +scheme/open-repl ()
|
2019-07-20 23:59:29 -05:00
|
|
|
"Open the Scheme REPL."
|
2020-06-10 00:17:03 +10:00
|
|
|
(interactive)
|
|
|
|
(call-interactively #'switch-to-geiser)
|
2019-07-20 23:59:29 -05:00
|
|
|
(current-buffer))
|