mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-16 02:50:26 -08:00
; * lisp/treesit.el (treesit--install-language-grammar-1): Minor fix.
This commit is contained in:
parent
724da28763
commit
0b58ea0e60
1 changed files with 21 additions and 16 deletions
|
|
@ -36,6 +36,7 @@
|
||||||
(eval-when-compile (require 'subr-x)) ; For `string-join'.
|
(eval-when-compile (require 'subr-x)) ; For `string-join'.
|
||||||
(require 'cl-seq)
|
(require 'cl-seq)
|
||||||
(require 'font-lock)
|
(require 'font-lock)
|
||||||
|
(require 'seq)
|
||||||
|
|
||||||
;;; Function declarations
|
;;; Function declarations
|
||||||
|
|
||||||
|
|
@ -2684,27 +2685,30 @@ content as signal data, and erase buffer afterwards."
|
||||||
(out-dir lang url &optional source-dir grammar-dir cc c++)
|
(out-dir lang url &optional source-dir grammar-dir cc c++)
|
||||||
"Install and compile a tree-sitter language grammar library.
|
"Install and compile a tree-sitter language grammar library.
|
||||||
|
|
||||||
OUT-DIR is the directory to put the compiled library file, it
|
OUT-DIR is the directory to put the compiled library file. If it
|
||||||
defaults to ~/.emacs.d/tree-sitter.
|
is nil, the \"tree-sitter\" directory under user's Emacs
|
||||||
|
configuration directory is used (and automatically created if not
|
||||||
|
exist).
|
||||||
|
|
||||||
For LANG, URL, SOURCE-DIR, GRAMMAR-DIR, CC, C++, see
|
For LANG, URL, SOURCE-DIR, GRAMMAR-DIR, CC, C++, see
|
||||||
`treesit-language-source-alist'. If anything goes wrong, this
|
`treesit-language-source-alist'. If anything goes wrong, this
|
||||||
function signals an error."
|
function signals an error."
|
||||||
(let* ((lang (symbol-name lang))
|
(let* ((lang (symbol-name lang))
|
||||||
(default-directory "/tmp")
|
(default-directory (make-temp-file "treesit-workdir" t))
|
||||||
(workdir (expand-file-name "treesit-workdir-00893133134"))
|
(workdir (expand-file-name "repo"))
|
||||||
(source-dir (expand-file-name (or source-dir "src") workdir))
|
(source-dir (expand-file-name (or source-dir "src") workdir))
|
||||||
(grammar-dir (expand-file-name (or grammar-dir "") workdir))
|
(grammar-dir (expand-file-name (or grammar-dir "") workdir))
|
||||||
(cc (or cc "cc"))
|
(cc (or cc (seq-find #'executable-find '("cc" "gcc" "c99"))
|
||||||
(c++ (or c++ "c++"))
|
;; If no C compiler found, just use cc and let
|
||||||
(soext (pcase system-type
|
;; `call-process' signal the error.
|
||||||
('darwin "dylib")
|
"cc"))
|
||||||
((or 'ms-dos 'cywin 'windows-nt) "dll")
|
(c++ (or c++ (seq-find #'executable-find '("c++" "g++"))
|
||||||
(_ "so")))
|
"c++"))
|
||||||
|
(soext (or (car dynamic-library-suffixes)
|
||||||
|
(signal 'treesit-error '("Emacs cannot figure out the file extension for dynamic libraries for this system, because `dynamic-library-suffixes' is nil"))))
|
||||||
(out-dir (or (and out-dir (expand-file-name out-dir))
|
(out-dir (or (and out-dir (expand-file-name out-dir))
|
||||||
(expand-file-name
|
(locate-user-emacs-file "tree-sitter")))
|
||||||
"tree-sitter" user-emacs-directory)))
|
(lib-name (concat "libtree-sitter-" lang soext)))
|
||||||
(lib-name (format "libtree-sitter-%s.%s" lang soext)))
|
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(message "Cloning repository")
|
(message "Cloning repository")
|
||||||
|
|
@ -2713,8 +2717,9 @@ function signals an error."
|
||||||
"git" nil t nil "clone" url "--depth" "1" "--quiet"
|
"git" nil t nil "clone" url "--depth" "1" "--quiet"
|
||||||
workdir)
|
workdir)
|
||||||
;; cp "${grammardir}"/grammar.js "${sourcedir}"
|
;; cp "${grammardir}"/grammar.js "${sourcedir}"
|
||||||
(copy-file (concat grammar-dir "/grammar.js")
|
(copy-file (expand-file-name "grammar.js" grammar-dir)
|
||||||
(concat source-dir "/grammar.js"))
|
(expand-file-name "grammar.js" source-dir)
|
||||||
|
t t)
|
||||||
;; cd "${sourcedir}"
|
;; cd "${sourcedir}"
|
||||||
(setq default-directory source-dir)
|
(setq default-directory source-dir)
|
||||||
(message "Compiling library")
|
(message "Compiling library")
|
||||||
|
|
@ -2739,7 +2744,7 @@ function signals an error."
|
||||||
(rx bos (+ anychar) ".o" eos))
|
(rx bos (+ anychar) ".o" eos))
|
||||||
"-o" ,lib-name))
|
"-o" ,lib-name))
|
||||||
;; Copy out.
|
;; Copy out.
|
||||||
(copy-file lib-name (concat out-dir "/") t)
|
(copy-file lib-name (file-name-as-directory out-dir) t t)
|
||||||
(message "Library installed to %s/%s" out-dir lib-name))
|
(message "Library installed to %s/%s" out-dir lib-name))
|
||||||
(when (file-exists-p workdir)
|
(when (file-exists-p workdir)
|
||||||
(delete-directory workdir t)))))
|
(delete-directory workdir t)))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue