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]]
- [[#focus-new-windows][Focus new windows]]
- [[#support-functions][Support functions]]
- [[#git-package][Git package]]
- [[#emacs-function-launcher][Emacs function launcher]]
- [[#copy-to-clipboard][Copy to clipboard]]
- [[#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))))
#+end_src
* 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
Launches emacs function as a window
#+begin_src emacs-lisp
@ -1366,88 +1377,81 @@ Vterm is a terminal emulator within Emacs. The 'shell-file-name' setting sets t
#+end_src
* CMake Projects
#+begin_src emacs-lisp
(defun eval-elisp-string (code-string)
"Evaluate the Elisp code contained in CODE-STRING and return the result."
(eval (read code-string)))
(defun use-cmake-integration ()
(git-package "https://github.com/darcamo/cmake-integration.git")
(use-package cmake-integration
:commands (cmake-integration-transient)
: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)
(eval-elisp-string "(use-package cmake-integration \
:vc (:url \"https://github.com/darcamo/cmake-integration.git\" \
:rev :newest) \
:commands (cmake-integration-transient) \
: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)))
(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 ()
"Turn on `cmake-integration-keybindings-mode' in CMake projects."
(when (is-cmake-project?)
(use-cmake-integration)
(cmake-integration-keybindings-mode 1)))
(defun cmake-integration-keybindings-mode-turn-on-in-cmake-projects ()
"Turn on `cmake-integration-keybindings-mode' in CMake projects."
(when (is-cmake-project?)
(cmake-integration-keybindings-mode 1)))
(define-minor-mode cmake-integration-keybindings-mode
"A minor-mode for adding keybindings to compile C++ code using cmake-integration package."
nil
"cmake"
'(
([f5] . cmake-integration-transient) ;; Open main transient menu
([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
([C-f9] . cmake-integration-run-ctest) ;; Run CTest
([f10] . cmake-integration-run-last-target) ;; Run the target (using any previously set command line parameters)
([S-f10] . kill-compilation)
([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-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
)
(define-minor-mode cmake-integration-keybindings-mode
"A minor-mode for adding keybindings to compile C++ code using cmake-integration package."
nil
"cmake"
'(
([f5] . cmake-integration-transient) ;; Open main transient menu
([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
([C-f9] . cmake-integration-run-ctest) ;; Run CTest
([f10] . cmake-integration-run-last-target) ;; Run the target (using any previously set command line parameters)
([S-f10] . kill-compilation)
([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-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
)
)
(define-globalized-minor-mode global-cmake-integration-keybindings-mode
cmake-integration-keybindings-mode cmake-integration-keybindings-mode-turn-on-in-cmake-projects)
(define-globalized-minor-mode global-cmake-integration-keybindings-mode
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
(cl-defmethod project-root ((project (head local)))
(cdr project))
;; Extend project.el to recognize local projects based on a .project file
(cl-defmethod project-root ((project (head local)))
(cdr project))
(defun mu--project-files-in-directory (dir)
"Use `fd' to list files in DIR."
(let* ((default-directory dir)
(localdir (file-local-name (expand-file-name dir)))
(command (format "fd -t f -0 . %s" localdir)))
(project--remote-file-names
(sort (split-string (shell-command-to-string command) "\0" t)
#'string<))))
(defun mu--project-files-in-directory (dir)
"Use `fd' to list files in DIR."
(let* ((default-directory dir)
(localdir (file-local-name (expand-file-name dir)))
(command (format "fd -t f -0 . %s" localdir)))
(project--remote-file-names
(sort (split-string (shell-command-to-string command) "\0" t)
#'string<))))
(cl-defmethod project-files ((project (head local)) &optional dirs)
"Override `project-files' to use `fd' in local projects."
(mapcan #'mu--project-files-in-directory
(or dirs (list (project-root project)))))
(cl-defmethod project-files ((project (head local)) &optional dirs)
"Override `project-files' to use `fd' in local projects."
(mapcan #'mu--project-files-in-directory
(or dirs (list (project-root project)))))
(defun mu-project-try-local (dir)
"Determine if DIR is a non-Git project.
DIR must include a .project file to be considered a project."
(let ((root (locate-dominating-file dir ".project")))
(and root (cons 'local root))))
(defun mu-project-try-local (dir)
"Determine if DIR is a non-Git project.
DIR must include a .project file to be considered a project."
(let ((root (locate-dominating-file dir ".project")))
(and root (cons 'local root))))
(use-package project
:defer t
:config
(add-to-list 'project-find-functions 'mu-project-try-local)
)
(use-package project
:defer t
:config
(add-to-list 'project-find-functions 'mu-project-try-local)
)
#+end_src
* Direnv
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]]
#+begin_src emacs-lisp
(use-package promise :ensure t) ;; nix3 dependency
(eval-elisp-string "(use-package nix3 \
:vc (:url \"https://github.com/emacs-twist/nix3.el\" \
:rev :newest)\
:init \
(let* ((mainpkg-dir (file-name-directory (locate-library \"nix3\"))) \
(subpkg-dir (expand-file-name \"extra\" mainpkg-dir))) \
(add-to-list 'load-path subpkg-dir)))")
(use-package promise :ensure t) ;; nix3 dependency
(git-package "https://github.com/emacs-twist/nix3.el")
(use-package nix3
:init
(let* ((mainpkg-dir (file-name-directory (locate-library "nix3")))
(subpkg-dir (expand-file-name "extra" mainpkg-dir)))
(add-to-list 'load-path subpkg-dir)))
(use-package magit-nix3
:after magit-status
:config
(magit-nix3-flake-mode t))
(use-package magit-nix3
:after magit-status
:config
(magit-nix3-flake-mode t))
#+end_src
** GLSL
#+begin_src emacs-lisp