9.2
2 Enigma API: File Context
| (require enigma/emacs/file/context) | package: enigma-app |
procedure
(similar-emacs-lisp-name? emacs-lisp-path supposed-path) → boolean? emacs-lisp-path : path-string? supposed-path : path-string?
Check if supposed-path has a name similar to
emacs-lisp-path.
procedure
(find-likely-emacs-lisp-segments file-path) → (listof path?)
file-path : path-string?
Find paths in the tree of file-path with similar names.
procedure
(guess-load-path emacs-lisp-files) → (listof path?)
emacs-lisp-files : (listof path?)
Guess the Emacs Lisp load-path from the given files.
procedure
(find-emacs-lisp-context start-path)
→
(listof path?) (listof path?) start-path : path-string?
Find Emacs Lisp files and their load-path under start-path.
The source code of this module:
#lang racket/base (require racket/contract/base) (require racket/list) (require racket/set) (require threading) (require "../../system/utils/find.rkt") (require "../../system/utils/path.rkt") (provide (contract-out [similar-emacs-lisp-name? (-> path-string? path-string? boolean?)] [find-likely-emacs-lisp-segments (-> path-string? (listof path?))] [guess-load-path (-> (listof path?) (listof path?))] [find-emacs-lisp-context (-> path-string? (values (listof path?) (listof path?)))])) (define (similar-emacs-lisp-name? emacs-lisp-path supposed-path) (define lisp-name (path->name emacs-lisp-path)) (define lispy-name (regexp-replace #rx"\\.el$" lisp-name "")) (define path-name (path->name supposed-path)) (cond [(~> (string-append "^" lispy-name "(_|-).*") regexp (regexp-match path-name) (and #true))] [(~> (string-append ".*(_|-)" lispy-name "$") regexp (regexp-match path-name) (and #true))] [(~> (string-append ".*(_|-)" lisp-name "$") regexp (regexp-match path-name) (and #true))] [(equal? lispy-name path-name)] [(equal? lisp-name path-name)] [else #false])) (define (find-likely-emacs-lisp-segments file-path) (for/list ([path (make-paths-tree file-path)] #:when (similar-emacs-lisp-name? file-path path)) path)) (define (guess-load-path emacs-lisp-files) (~> emacs-lisp-files (map find-likely-emacs-lisp-segments _) flatten list->set set->list (filter directory-exists? _))) (define (find-emacs-lisp-context start-path) (define emacs-lisp-files (find-emacs-lisp-files start-path)) (define load-path (guess-load-path emacs-lisp-files)) (values emacs-lisp-files load-path))