5
54
Fork
You've already forked blue
4

Define documentation style #51

Open
opened 2025年06月11日 21:29:17 +02:00 by pastor · 4 comments

Before tackling the documentation issue, I think we should agree on how to do it.

One think I definitely want is that all files should have a header in the style of elisp packages. I propose the following structure for the header:

;;; <file-name>.scm --- <synopsis>
;; <copyright assignments>
;; <license>
;;; Commentary:
;; <purpose of the file>.
;;; Code:
Before tackling the [documentation issue](https://codeberg.org/lapislazuli/blue/issues/31), I think we should agree on how to do it. One think I definitely want is that **all** files should have a header in the style of elisp packages. I propose the following structure for the header: ``` ;;; <file-name>.scm --- <synopsis> ;; <copyright assignments> ;; <license> ;;; Commentary: ;; <purpose of the file>. ;;; Code: ```
Owner
Copy link

I would ike to keep the license at the top of the file followed by copyrights then synopsis and commentary and code.

Licenses need to be the closest possible to top of the file (when possible) because tools that detect them are expecting to find them in the first lines.

So:

;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: 2025 Olivier Dion <olivier-dion@proton.me>
;;;
;;; blue/cache.scm --- File-system caching of objects.
;;;
;;; Commentary:
;;;
;;; Whenever an object needs to used from different invocations (processes) of
;;; `blue', then the cache can be used to store that object on the file-system
;;; and load it back later.
;;;
;;; Code:
(define-module (blue cache)
 #:use-module (blue file-system directory)
 #:use-module (blue serialize)
 #:use-module (blue states)
 #:use-module (ice-9 exceptions)
 #:export (cache-ref
 cache-link!
 cache-set!
 make-cache))
(define (make-cache directory)
 (mkdir-p directory)
 (call-with-output-file (format #f "~a/.lock" directory)
 (lambda (lock)
 #f))
 directory)
(define (cache-file-path cache hash)
 (format #f "~a/~a"
 cache (number->string
 (logand hash (1- (ash 1 256)))
 16)))
;;; Is this lock really necessary?
(define (cache-lock cache)
 (format #f "~a/.lock" cache))
(define (with-cache-lock shared-or-exclusive cache thunk)
 (call-with-input-file (cache-lock cache)
 (lambda (lock)
 (dynamic-wind
 (lambda ()
 (flock lock shared-or-exclusive))
 thunk
 (lambda ()
 (flock lock LOCK_UN))))))
(define (with-read-cache-lock cache thunk)
 (with-cache-lock LOCK_SH cache thunk))
(define (with-write-cache-lock cache thunk)
 (with-cache-lock LOCK_EX cache thunk))
(define* (cache-ref hash
 #:optional (cache (current-cache)))
 (with-read-cache-lock cache
 (lambda ()
 (let ((path (cache-file-path cache hash)))
 (if (file-exists? path)
 (call-with-input-file path
 (lambda (port)
 (eval (read port) (current-module))))
 #f)))))
(define* (cache-set! hash value
 #:optional (cache (current-cache)))
 (with-write-cache-lock cache
 (lambda ()
 (call-with-output-file (cache-file-path cache hash)
 (lambda (port)
 (serialize value port))))))
(define* (cache-link! link-hash other-hash
 #:optional (cache (current-cache)))
 (let ((target (cache-file-path cache other-hash))
 (link (cache-file-path cache link-hash)))
 (with-write-cache-lock cache
 (lambda ()
 (if (file-exists? target)
 (begin
 (when (file-exists? link)
 (delete-file link))
 (symlink (basename target) link))
 (raise-exception
 (make-exception
 (make-external-error)
 (make-exception-with-origin link)
 (make-exception-with-irritants target)
 (make-exception-with-message
 "Target to link does not exist in the cache."))))))))
I would ike to keep the license at the top of the file followed by copyrights then synopsis and commentary and code. Licenses need to be the closest possible to top of the file (when possible) because tools that detect them are expecting to find them in the first lines. So: ```scheme ;;; SPDX-License-Identifier: LGPL-3.0-or-later ;;; SPDX-FileCopyrightText: 2025 Olivier Dion <olivier-dion@proton.me> ;;; ;;; blue/cache.scm --- File-system caching of objects. ;;; ;;; Commentary: ;;; ;;; Whenever an object needs to used from different invocations (processes) of ;;; `blue', then the cache can be used to store that object on the file-system ;;; and load it back later. ;;; ;;; Code: (define-module (blue cache) #:use-module (blue file-system directory) #:use-module (blue serialize) #:use-module (blue states) #:use-module (ice-9 exceptions) #:export (cache-ref cache-link! cache-set! make-cache)) (define (make-cache directory) (mkdir-p directory) (call-with-output-file (format #f "~a/.lock" directory) (lambda (lock) #f)) directory) (define (cache-file-path cache hash) (format #f "~a/~a" cache (number->string (logand hash (1- (ash 1 256))) 16))) ;;; Is this lock really necessary? (define (cache-lock cache) (format #f "~a/.lock" cache)) (define (with-cache-lock shared-or-exclusive cache thunk) (call-with-input-file (cache-lock cache) (lambda (lock) (dynamic-wind (lambda () (flock lock shared-or-exclusive)) thunk (lambda () (flock lock LOCK_UN)))))) (define (with-read-cache-lock cache thunk) (with-cache-lock LOCK_SH cache thunk)) (define (with-write-cache-lock cache thunk) (with-cache-lock LOCK_EX cache thunk)) (define* (cache-ref hash #:optional (cache (current-cache))) (with-read-cache-lock cache (lambda () (let ((path (cache-file-path cache hash))) (if (file-exists? path) (call-with-input-file path (lambda (port) (eval (read port) (current-module)))) #f))))) (define* (cache-set! hash value #:optional (cache (current-cache))) (with-write-cache-lock cache (lambda () (call-with-output-file (cache-file-path cache hash) (lambda (port) (serialize value port)))))) (define* (cache-link! link-hash other-hash #:optional (cache (current-cache))) (let ((target (cache-file-path cache other-hash)) (link (cache-file-path cache link-hash))) (with-write-cache-lock cache (lambda () (if (file-exists? target) (begin (when (file-exists? link) (delete-file link)) (symlink (basename target) link)) (raise-exception (make-exception (make-external-error) (make-exception-with-origin link) (make-exception-with-irritants target) (make-exception-with-message "Target to link does not exist in the cache.")))))))) ```
Author
Owner
Copy link

Okay! I've configured auto-insert mode in the project's dir-local variables so you can do M-x auto-insert to insert this template a header comment of any scheme file. If auto-insert-mode is on the user will be prompted to inject this template for new scheme files.

The changes are in #52.

Okay! I've configured auto-insert mode in the project's dir-local variables so you can do `M-x auto-insert` to insert this template a header comment of any scheme file. If `auto-insert-mode` is on the user will be prompted to inject this template for new scheme files. The changes are in #52.
Owner
Copy link

Add a section in the BLUE info manual under the Contributing explaining this issue.

Add a section in the BLUE info manual under the *Contributing* explaining this issue.
old added this to the alpha milestone 2026年04月01日 19:20:46 +02:00
Author
Owner
Copy link

We should probably use this issue to discuss how we are going to generate some parts of the documentation from the sources.

Currently we are playing with a way to extract documentation from sources here.

We should probably use this issue to discuss how we are going to generate some parts of the documentation from the sources. Currently we are playing with a way to extract documentation from sources [here](https://codeberg.org/lapislazuli/blue/src/user-manual/blue/stencils/guile-texinfo.scm).
Sign in to join this conversation.
No Branch/Tag specified
main
pipeline-operators
documentation
shadow-fields
instance-walker
blue-shell
promote-serializers-to-metacommands
pre-alpha
Labels
Clear labels
bug
Something is not working
contribution welcome
Contributions are very welcome, get started here
discussion
duplicate
This issue or pull request already exists
enhancement
New feature
good first issue
Interested in contributing? Get started here.
help wanted
Need some help
invalid
Something is wrong
optimization
question
More information is needed
upstream
Related to an upstream repository, already reported there
bug
Something is not working
contribution welcome
Contributions are very welcome, get started here
duplicate
This issue or pull request already exists
enhancement
New feature
good first issue
Interested in contributing? Get started here.
help wanted
Need some help
invalid
Something is wrong
question
More information is needed
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lapislazuli/blue#51
Reference in a new issue
lapislazuli/blue
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?