[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to detect two emacs process in Elisp code?
From: |
Emanuel Berg |
Subject: |
Re: How to detect two emacs process in Elisp code? |
Date: |
Thu, 03 Sep 2020 04:41:02 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
stardiviner wrote:
> I load desktop-save-mode session in init.el.
> But when using "bug-hunter-init-file", I need to
> exclude this session init file.
>
> Here is my try:
>
> #+begin_src emacs-lisp
> ;;; detect external system has Emacs process running?
> ;;; If yes, like `bug-hunter' is running. Then don't load session.
> ;;; FIXME
> (let ((emacs-processes
> (length (mapcar
> 'string-to-number
> (seq-filter
> (lambda (str)
> (not (string-empty-p str)))
> (split-string
> ;; (shell-command-to-string "ps -C emacs -o pid=")
> (shell-command-to-string "ps -C emacs -o pid=")
> "\n"))))))
> (when (<= emacs-processes 1)
> (message "init-emacs-session loading")
> (require 'init-emacs-session)))
> #+end_src
Try this:
(require 'seq)
(defun how-many-emacs ()
(let ((emacs-processes
(length (mapcar
#'string-to-number
(seq-filter
(lambda (str)
(not (string-empty-p str)) )
(split-string
(shell-command-to-string "ps -C emacs -o pid=")
"\n") )))))
(message (format "Emacs process: %d" emacs-processes)) ))
;; (how-many-emacs) ; 1
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal