Skip to content

Commit

Permalink
refactor: make some unused macros obsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed May 18, 2024
1 parent cca9a46 commit d46cdb8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 78 deletions.
11 changes: 6 additions & 5 deletions core/me-builtin.el
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,12 @@ See `+whitespace-auto-cleanup-except-current-line'."
:hook ((server-after-make-frame minemacs-after-startup) . +scratch-replace-with-persistent-scratch)
:init
;; When we start in a non-daemon Emacs, we start a server when Emacs is idle.
(+lazy-unless! (daemonp)
(unless (server-running-p)
(let ((inhibit-message t))
(server-start nil t)
(+info! "Started Emacs daemon in background.")))))
(unless (daemonp)
(+lazy!
(unless (server-running-p)
(let ((inhibit-message t))
(server-start nil t)
(+info! "Started Emacs daemon in background."))))))

(use-package speedbar ; config from Crafted Emacs
:custom
Expand Down
20 changes: 0 additions & 20 deletions core/me-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -249,31 +249,11 @@ This inhebits both the echo area and the `*Messages*' buffer."
"Run BODY after Emacs gets loaded, a.k.a. after `minemacs-loaded'."
`(with-eval-after-load 'minemacs-loaded ,@body))

(defmacro +deferred-when! (condition &rest body)
"Like `+deferred!', with BODY executed only if CONDITION is non-nil."
(declare (indent 1))
`(when ,condition (+deferred! ,@body)))

(defmacro +deferred-unless! (condition &rest body)
"Like `+deferred!', with BODY executed only if CONDITION is nil."
(declare (indent 1))
`(unless ,condition (+deferred! ,@body)))

(defmacro +lazy! (&rest body)
"Run BODY as a lazy block (see `minemacs-lazy')."
`(with-eval-after-load 'minemacs-lazy
(+eval-when-idle-for! +lazy-delay ,@body)))

(defmacro +lazy-when! (condition &rest body)
"Like `+lazy!', with BODY executed only if CONDITION is non-nil."
(declare (indent 1))
`(when ,condition (+lazy! ,@body)))

(defmacro +lazy-unless! (condition &rest body)
"Like `+lazy!', with BODY executed only if CONDITION is nil."
(declare (indent 1))
`(unless ,condition (+lazy! ,@body)))

(defmacro +after-load! (features &rest body)
"Execute BODY after FEATURES have been loaded."
(declare (indent 1))
Expand Down
42 changes: 22 additions & 20 deletions modules/me-daemon.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@
;;; Code:

;; Email (mu4e)
(+lazy-when! (and (memq 'me-email minemacs-modules) (not (+package-disabled-p 'mu4e)))
(when (and +mu4e-available-p +mu4e-auto-start (require 'mu4e nil :noerror))
(defvar +daemon--mu4e-persist-timer
(run-at-time
(* 10) ;; 10s
(* 60 3) ;; 3min
(lambda ()
(unless (or (+lockedp 'mu) (mu4e-running-p))
(+info! "Starting `mu4e' in background.")
(let ((inhibit-message t))
(mu4e t))))))))
(when (and (memq 'me-email minemacs-modules) (not (+package-disabled-p 'mu4e)))
(+lazy!
(when (and +mu4e-available-p +mu4e-auto-start (require 'mu4e nil :noerror))
(defvar +daemon--mu4e-persist-timer
(run-at-time
(* 10) ;; 10s
(* 60 3) ;; 3min
(lambda ()
(unless (or (+lockedp 'mu) (mu4e-running-p))
(+info! "Starting `mu4e' in background.")
(let ((inhibit-message t))
(mu4e t)))))))))

;; RSS (elfeed)
(+lazy-when! (and (memq 'me-rss minemacs-modules) (not (+package-disabled-p 'elfeed)))
(when (require 'elfeed nil :noerror)
(run-at-time
(* 60 5) ;; 5min
(* 60 60) ;; 1h
(lambda ()
(+info! "Updating RSS feed.")
(let ((inhibit-message t))
(elfeed-update))))))
(when (and (memq 'me-rss minemacs-modules) (not (+package-disabled-p 'elfeed)))
(+lazy!
(when (require 'elfeed nil :noerror)
(run-at-time
(* 60 5) ;; 5min
(* 60 60) ;; 1h
(lambda ()
(+info! "Updating RSS feed.")
(let ((inhibit-message t))
(elfeed-update)))))))


(provide 'me-daemon)
Expand Down
67 changes: 34 additions & 33 deletions modules/me-robot.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,40 @@
("\\.action\\'" . gdb-script-mode)))
(add-to-list 'auto-mode-alist ext-mode))

(+deferred-when! (cl-some (lambda (cmd) (and cmd (executable-find cmd)))
(list +ros-mcap-command +ros-rosbag-command +ros-ros2-command))
;; A mode to display info from ROS bag files (via MCAP)
(define-derived-mode rosbag-info-mode conf-colon-mode "ROS bag"
"Major mode for viewing ROS/ROS2 bag files."
:interactive nil
(buffer-disable-undo)
(set-buffer-modified-p nil)
(setq-local buffer-read-only t
truncate-lines t))

(defun rosbag-info-mode-open-file (file)
"Browse the contents of an ROS bag (v1, SQLite, or MCAP) file."
(interactive "fROS/ROS2/MCAP bag file name: ")
(let ((bag-format (file-name-extension file)))
(if (not (member bag-format '("bag" "db3" "mcap")))
(user-error "File \"%s\" doesn't seem to be a ROS/ROS2 bag file."
(file-name-nondirectory file))
(let ((buffer-read-only nil)
(buff (get-buffer-create
(format "*ROS (%s) %s*" (upcase bag-format) (file-name-nondirectory file)))))
(pop-to-buffer buff)
(pcase bag-format
("bag"
(call-process +ros-rosbag-command
nil buff nil "info" (expand-file-name file)))
("db3"
(call-process +ros-ros2-command
nil buff nil "bag" "info" (expand-file-name file)))
("mcap"
(call-process +ros-mcap-command
nil buff nil "info" (expand-file-name file)))
(rosbag-info-mode)))))))
(when (cl-some (lambda (cmd) (and cmd (executable-find cmd)))
(list +ros-mcap-command +ros-rosbag-command +ros-ros2-command))
(+deferred!
;; A mode to display info from ROS bag files (via MCAP)
(define-derived-mode rosbag-info-mode conf-colon-mode "ROS bag"
"Major mode for viewing ROS/ROS2 bag files."
:interactive nil
(buffer-disable-undo)
(set-buffer-modified-p nil)
(setq-local buffer-read-only t
truncate-lines t))

(defun rosbag-info-mode-open-file (file)
"Browse the contents of an ROS bag (v1, SQLite, or MCAP) file."
(interactive "fROS/ROS2/MCAP bag file name: ")
(let ((bag-format (file-name-extension file)))
(if (not (member bag-format '("bag" "db3" "mcap")))
(user-error "File \"%s\" doesn't seem to be a ROS/ROS2 bag file."
(file-name-nondirectory file))
(let ((buffer-read-only nil)
(buff (get-buffer-create
(format "*ROS (%s) %s*" (upcase bag-format) (file-name-nondirectory file)))))
(pop-to-buffer buff)
(pcase bag-format
("bag"
(call-process +ros-rosbag-command
nil buff nil "info" (expand-file-name file)))
("db3"
(call-process +ros-ros2-command
nil buff nil "bag" "info" (expand-file-name file)))
("mcap"
(call-process +ros-mcap-command
nil buff nil "info" (expand-file-name file)))
(rosbag-info-mode))))))))

(when (>= emacs-major-version 29)
(push 'docker-tramp straight-built-in-pseudo-packages))
Expand Down

0 comments on commit d46cdb8

Please sign in to comment.