Update elisp/arch-ros2.el

This commit is contained in:
Alexander Rosenberg 2025-02-20 20:28:42 -08:00
parent 0fd70fb03c
commit 2d072241a7
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -83,51 +83,60 @@ This will prepend the values to VAR."
(setenv var (string-join (seq-difference parts (cdr entry)) ":"))))) (setenv var (string-join (seq-difference parts (cdr entry)) ":")))))
(remhash var arch-ros2--saved-env-vars))) (remhash var arch-ros2--saved-env-vars)))
(defmacro arch-ros2-with-modify-global-env (&rest body)
"Execute BODY, modifying the default toplevel `process-environment'."
`(let ((process-environment (default-toplevel-value 'process-environment)))
(unwind-protect
(progn ,@body)
(set-default-toplevel-value 'process-environment process-environment))))
(defun arch-ros2-activate () (defun arch-ros2-activate ()
"Activate a ROS2 development environment." "Activate a ROS2 development environment."
(interactive) (interactive)
(setq arch-ros2-active t) (arch-ros2-with-modify-global-env
(add-to-list 'mode-line-misc-info arch-ros2-mode-line-format) (setq arch-ros2-active t)
(arch-ros2--add-to-path "/opt/ros/humble/bin/") (add-to-list 'mode-line-misc-info arch-ros2-mode-line-format)
(arch-ros2--set-env-var "AMENT_PREFIX_PATH" arch-ros2-root) (arch-ros2--add-to-path "/opt/ros/humble/bin/")
(arch-ros2--set-env-var "CMAKE_PREFIX_PATH" arch-ros2-root) (arch-ros2--set-env-var "AMENT_PREFIX_PATH" arch-ros2-root)
(arch-ros2--set-env-var "COLCON_PREFIX_PATH" arch-ros2-root) (arch-ros2--set-env-var "CMAKE_PREFIX_PATH" arch-ros2-root)
(arch-ros2--set-env-var "ROS_DISTRO" arch-ros2-distro) (arch-ros2--set-env-var "COLCON_PREFIX_PATH" arch-ros2-root)
(arch-ros2--set-env-var "ROS_LOCALHOST_ONLY" "0") (arch-ros2--set-env-var "ROS_DISTRO" arch-ros2-distro)
(arch-ros2--set-env-var "ROS_PYTHON_VERSION" (arch-ros2--set-env-var "ROS_LOCALHOST_ONLY" "0")
(car (split-string arch-ros2-python-version "\\."))) (arch-ros2--set-env-var "ROS_PYTHON_VERSION"
(arch-ros2--set-env-var "ROS_VERSION" (car (split-string arch-ros2-python-version "\\.")))
(number-to-string arch-ros2-version)) (arch-ros2--set-env-var "ROS_VERSION"
(arch-ros2--add-file-to-var (number-to-string arch-ros2-version))
"LD_LIBRARY_PATH" (arch-ros2--add-file-to-var
(expand-file-name "opt/rviz_ogre_vendor/lib" "LD_LIBRARY_PATH"
arch-ros2-root) (expand-file-name "opt/rviz_ogre_vendor/lib"
(expand-file-name "lib" arch-ros2-root)
arch-ros2-root)) (expand-file-name "lib"
(arch-ros2--add-file-to-var arch-ros2-root))
"PKG_CONFIG_PATH" (expand-file-name "lib/pkgconfig" arch-ros2-root)) (arch-ros2--add-file-to-var
(let ((python-dir (expand-file-name "PKG_CONFIG_PATH" (expand-file-name "lib/pkgconfig" arch-ros2-root))
(concat "lib/python" arch-ros2-python-version) (let ((python-dir (expand-file-name
arch-ros2-root))) (concat "lib/python" arch-ros2-python-version)
(arch-ros2--add-file-to-var "PYTHONPATH" arch-ros2-root)))
(expand-file-name "dist-packages" python-dir) (arch-ros2--add-file-to-var "PYTHONPATH"
(expand-file-name "site-packages" python-dir)))) (expand-file-name "dist-packages" python-dir)
(expand-file-name "site-packages" python-dir)))))
(defun arch-ros2-deactivate () (defun arch-ros2-deactivate ()
"Deactivate the ROS2 development environment." "Deactivate the ROS2 development environment."
(interactive) (interactive)
(setq arch-ros2-active nil (arch-ros2-with-modify-global-env
mode-line-misc-info (cl-remove arch-ros2-mode-line-format (setq arch-ros2-active nil
mode-line-misc-info mode-line-misc-info (cl-remove arch-ros2-mode-line-format
:test 'equal)) mode-line-misc-info
(maphash (lambda (k v) :test 'equal))
(cond (maphash (lambda (k v)
((stringp k) (cond
(arch-ros2--restore-env-var k)) ((stringp k)
((eq k 'exec-path) (arch-ros2--restore-env-var k))
(setq exec-path (seq-difference exec-path v)) ((eq k 'exec-path)
(remhash 'exec-path arch-ros2--saved-env-vars)))) (setq exec-path (seq-difference exec-path v))
arch-ros2--saved-env-vars)) (remhash 'exec-path arch-ros2--saved-env-vars))))
arch-ros2--saved-env-vars)))
(provide 'arch-ros2) (provide 'arch-ros2)
;;; arch-ros2.el ends here ;;; arch-ros2.el ends here