git-package instead of string evaluation

This commit is contained in:
Aleksandr Lebedev 2025-07-23 12:52:06 +02:00
parent b1bc2752fb
commit db9f6ecadc

View file

@ -10,6 +10,7 @@
- [[#keybindings][Keybindings]] - [[#keybindings][Keybindings]]
- [[#focus-new-windows][Focus new windows]] - [[#focus-new-windows][Focus new windows]]
- [[#support-functions][Support functions]] - [[#support-functions][Support functions]]
- [[#git-package][Git package]]
- [[#emacs-function-launcher][Emacs function launcher]] - [[#emacs-function-launcher][Emacs function launcher]]
- [[#copy-to-clipboard][Copy to clipboard]] - [[#copy-to-clipboard][Copy to clipboard]]
- [[#detect-wsl][Detect WSL]] - [[#detect-wsl][Detect WSL]]
@ -174,6 +175,16 @@ Found this [[https://emacs.stackexchange.com/questions/21770/automatically-switc
(lambda (&rest _) (select-window (get-lru-window)))) (lambda (&rest _) (select-window (get-lru-window))))
#+end_src #+end_src
* Support functions * Support functions
** Git package
#+begin_src emacs-lisp
(defun git-package (url)
(let* ((pkg-name (file-name-base (directory-file-name url)))
(pkg-sym (intern pkg-name)))
(eval
`(use-package ,pkg-sym
:vc (:url ,url :rev :newest)
:ensure nil))))
#+end_src
** Emacs function launcher ** Emacs function launcher
Launches emacs function as a window Launches emacs function as a window
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -1366,88 +1377,81 @@ Vterm is a terminal emulator within Emacs. The 'shell-file-name' setting sets t
#+end_src #+end_src
* CMake Projects * CMake Projects
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun eval-elisp-string (code-string) (git-package "https://github.com/darcamo/cmake-integration.git")
"Evaluate the Elisp code contained in CODE-STRING and return the result." (use-package cmake-integration
(eval (read code-string))) :commands (cmake-integration-transient)
(defun use-cmake-integration () :custom
(cmake-integration-generator "Ninja")
(cmake-integration-use-separated-compilation-buffer-for-each-target t))
(defun is-cmake-project? ()
"Determine if the current directory is a CMake project."
(interactive) (interactive)
(eval-elisp-string "(use-package cmake-integration \ (if-let* ((project (project-current))
:vc (:url \"https://github.com/darcamo/cmake-integration.git\" \ (project-root (project-root project))
:rev :newest) \ (cmakelist-path (expand-file-name "CMakeLists.txt" project-root)))
:commands (cmake-integration-transient) \ (file-exists-p cmakelist-path)))
:custom \
(cmake-integration-generator \"Ninja\") \
(cmake-integration-use-separated-compilation-buffer-for-each-target t))"))
(defun is-cmake-project? ()
"Determine if the current directory is a CMake project."
(interactive)
(if-let* ((project (project-current))
(project-root (project-root project))
(cmakelist-path (expand-file-name "CMakeLists.txt" project-root)))
(file-exists-p cmakelist-path)))
(defun cmake-integration-keybindings-mode-turn-on-in-cmake-projects () (defun cmake-integration-keybindings-mode-turn-on-in-cmake-projects ()
"Turn on `cmake-integration-keybindings-mode' in CMake projects." "Turn on `cmake-integration-keybindings-mode' in CMake projects."
(when (is-cmake-project?) (when (is-cmake-project?)
(use-cmake-integration) (cmake-integration-keybindings-mode 1)))
(cmake-integration-keybindings-mode 1)))
(define-minor-mode cmake-integration-keybindings-mode (define-minor-mode cmake-integration-keybindings-mode
"A minor-mode for adding keybindings to compile C++ code using cmake-integration package." "A minor-mode for adding keybindings to compile C++ code using cmake-integration package."
nil nil
"cmake" "cmake"
'( '(
([f5] . cmake-integration-transient) ;; Open main transient menu ([f5] . cmake-integration-transient) ;; Open main transient menu
([M-f9] . cmake-integration-save-and-compile) ;; Ask for the target name and compile it ([M-f9] . cmake-integration-save-and-compile) ;; Ask for the target name and compile it
([f9] . cmake-integration-save-and-compile-last-target) ;; Recompile the last target ([f9] . cmake-integration-save-and-compile-last-target) ;; Recompile the last target
([C-f9] . cmake-integration-run-ctest) ;; Run CTest ([C-f9] . cmake-integration-run-ctest) ;; Run CTest
([f10] . cmake-integration-run-last-target) ;; Run the target (using any previously set command line parameters) ([f10] . cmake-integration-run-last-target) ;; Run the target (using any previously set command line parameters)
([S-f10] . kill-compilation) ([S-f10] . kill-compilation)
([C-f10] . cmake-integration-debug-last-target) ;; Debug the target (using any previously set command line parameters) ([C-f10] . cmake-integration-debug-last-target) ;; Debug the target (using any previously set command line parameters)
([M-f10] . cmake-integration-run-last-target-with-arguments) ;; Ask for command line parameters to run the target ([M-f10] . cmake-integration-run-last-target-with-arguments) ;; Ask for command line parameters to run the target
([M-f8] . cmake-integration-select-configure-preset) ;; Ask for a preset name and call CMake to configure the project ([M-f8] . cmake-integration-select-configure-preset) ;; Ask for a preset name and call CMake to configure the project
([f8] . cmake-integration-cmake-reconfigure) ;; Call CMake to configure the project using the last chosen preset ([f8] . cmake-integration-cmake-reconfigure) ;; Call CMake to configure the project using the last chosen preset
)
) )
)
(define-globalized-minor-mode global-cmake-integration-keybindings-mode (define-globalized-minor-mode global-cmake-integration-keybindings-mode
cmake-integration-keybindings-mode cmake-integration-keybindings-mode-turn-on-in-cmake-projects) cmake-integration-keybindings-mode cmake-integration-keybindings-mode-turn-on-in-cmake-projects)
(global-cmake-integration-keybindings-mode) (global-cmake-integration-keybindings-mode)
;; Extend project.el to recognize local projects based on a .project file ;; Extend project.el to recognize local projects based on a .project file
(cl-defmethod project-root ((project (head local))) (cl-defmethod project-root ((project (head local)))
(cdr project)) (cdr project))
(defun mu--project-files-in-directory (dir) (defun mu--project-files-in-directory (dir)
"Use `fd' to list files in DIR." "Use `fd' to list files in DIR."
(let* ((default-directory dir) (let* ((default-directory dir)
(localdir (file-local-name (expand-file-name dir))) (localdir (file-local-name (expand-file-name dir)))
(command (format "fd -t f -0 . %s" localdir))) (command (format "fd -t f -0 . %s" localdir)))
(project--remote-file-names (project--remote-file-names
(sort (split-string (shell-command-to-string command) "\0" t) (sort (split-string (shell-command-to-string command) "\0" t)
#'string<)))) #'string<))))
(cl-defmethod project-files ((project (head local)) &optional dirs) (cl-defmethod project-files ((project (head local)) &optional dirs)
"Override `project-files' to use `fd' in local projects." "Override `project-files' to use `fd' in local projects."
(mapcan #'mu--project-files-in-directory (mapcan #'mu--project-files-in-directory
(or dirs (list (project-root project))))) (or dirs (list (project-root project)))))
(defun mu-project-try-local (dir) (defun mu-project-try-local (dir)
"Determine if DIR is a non-Git project. "Determine if DIR is a non-Git project.
DIR must include a .project file to be considered a project." DIR must include a .project file to be considered a project."
(let ((root (locate-dominating-file dir ".project"))) (let ((root (locate-dominating-file dir ".project")))
(and root (cons 'local root)))) (and root (cons 'local root))))
(use-package project (use-package project
:defer t :defer t
:config :config
(add-to-list 'project-find-functions 'mu-project-try-local) (add-to-list 'project-find-functions 'mu-project-try-local)
) )
#+end_src #+end_src
* Direnv * Direnv
Loading of environment for the buffers Loading of environment for the buffers
@ -1493,19 +1497,18 @@ Emacs has built-in programming language modes for Lisp, Scheme, DSSSL, Ada, ASM,
[[https://github.com/emacs-twist/nix3.el][nix3.el]] [[https://github.com/emacs-twist/nix3.el][nix3.el]]
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package promise :ensure t) ;; nix3 dependency (use-package promise :ensure t) ;; nix3 dependency
(eval-elisp-string "(use-package nix3 \ (git-package "https://github.com/emacs-twist/nix3.el")
:vc (:url \"https://github.com/emacs-twist/nix3.el\" \ (use-package nix3
:rev :newest)\ :init
:init \ (let* ((mainpkg-dir (file-name-directory (locate-library "nix3")))
(let* ((mainpkg-dir (file-name-directory (locate-library \"nix3\"))) \ (subpkg-dir (expand-file-name "extra" mainpkg-dir)))
(subpkg-dir (expand-file-name \"extra\" mainpkg-dir))) \ (add-to-list 'load-path subpkg-dir)))
(add-to-list 'load-path subpkg-dir)))")
(use-package magit-nix3 (use-package magit-nix3
:after magit-status :after magit-status
:config :config
(magit-nix3-flake-mode t)) (magit-nix3-flake-mode t))
#+end_src #+end_src
** GLSL ** GLSL
#+begin_src emacs-lisp #+begin_src emacs-lisp