file-local-variable

2016-03-18

File-local variable independent from ASDF

Upstream URL

github.com/guicho271828/file-local-variable

Author

Masataro Asai

License

LLGPL
README

1File-Local-Variable - File-local variable independent from ASDF

https://circleci.com/gh/guicho271828/file-local-variable.svg?style=svg

Implements a file-local variable using a carefully designed file-reloading scheme.


(defpackage file-local-variable.example
  (:use :cl))

(in-package :file-local-variable.example)

(defun myhook (macrofn form env)
  (print form)
  (funcall macrofn form env))

(flv:file-local-bind *macroexpand-hook* 'myhook
                     *read-default-float-format* 'double-float)

(eval-when (:compile-toplevel) (print :compile-toplevel))
(eval-when (:load-toplevel)    (print :load-toplevel))
(eval-when (:execute)          (print :execute))

(eval-when (:compile-toplevel :load-toplevel :execute)
  (print '#.*macroexpand-hook*)         ; 'myhook
  (print (type-of 3.0)))                ; 'double-float

1.1syntax

The syntax is the same as setf.

(file-local-bind var val &rest more)

1.2Related work

ASDF-FLV, but it depends on ASDF. by Didier Verna.

http://www.cliki.net/asdf-flv

CDR 9 proposal (File-local variables) by Didier Verna.

https://common-lisp.net/project/cdr/document/9/verna.11.cdr2.pdf

1.3How It Works

  1. flv:file-local-bind dynamically binds the variable using progv, andopens the current *compile-pathanme*. Within the dynamic environmentof progv, reread the file as follows:
    1. Skip the forms until the first appearance of flv:file-local-bind.
    2. Skip the flv:file-local-bind form.
    3. Read, then macroexpands the rest of the forms. Currently it dependson the implementation-specific macroexpand-all.
    4. flv:file-local-bind expands into a progn containing theirexpansion results.
  2. Skips the rest of the forms by assigning *dumb-readtable* to*readtable* , i.e., a readtable which treats all charactersas whitespace characters.
  3. Since *readtable* is file-local as specified by ANSI, it is unbound when the filecompilation finishes.

1.4Dependencies

This library is at least tested on implementation listed below:

  • SBCL 1.3.2 on X86-64 Linux 3.19.0-49-generic (author's environment)

Also, it depends on the following libraries:

iterate by
Jonathan Amsterdam's iterator/gatherer/accumulator facility
alexandria by
Alexandria is a collection of portable public domain utilities.
trivia

1.5Installation

1.6Author

  • Masataro Asai (guicho2.71828@gmail.com)

2Copyright

Copyright (c) 2016 Masataro Asai (guicho2.71828@gmail.com)

3License

Licensed under the LLGPL License.

Dependencies (4)

  • alexandria
  • fiveam
  • iterate
  • trivia

Dependents (0)

    • GitHub
    • Quicklisp