;;; mon-env-proc-utils.el --- procedures for interacting w/ process environment ;; -*- mode: EMACS-LISP; -*-> ;;; ================================================================ ;; Copyright © 2010-2024 MON KEY. All rights reserved. ;;; ================================================================ ;; FILENAME: mon-env-proc-utils.el ;; AUTHOR: MON KEY ;; MAINTAINER: MON KEY ;; CREATED: 2010-11-23T19:12:48-05:00Z ;; VERSION: 1.0.0 ;; COMPATIBILITY: Emacs23.* ;; KEYWORDS: external, execute, extensions, lisp, emacs, ;;; ================================================================ ;;; COMMENTARY: ;; ================================================================= ;; DESCRIPTION: ;; mon-env-proc-utils provides procedures for interacting w/ process environment ;; ;; FUNCTIONS:▶▶▶ ;; `mon-get-env-vars-symbols', `mon-get-env-vars-emacs', ;; `mon-get-env-vars-strings', `mon-get-emacsd-paths', `mon-get-proc-w-name', ;; `mon-get-sys-proc-list', `mon-insert-sys-proc-list', `mon-get-process', ;; `mon-get-system-specs', `mon-escape-string-for-cmd', `mon-cmd', ;; `mon-terminal', `mon-firefox', `mon-conkeror', ;; ;; FUNCTIONS:◀◀◀ ;; ;; MACROS: ;; ;; METHODS: ;; ;; CLASSES: ;; ;; CONSTANTS: ;; ;; FACES: ;; ;; VARIABLES: ;; `*mon-env-proc-utils-xrefs*', ;; ;; GROUPS: ;; `mon-env-proc-utils', ;; ;; ALIASED/ADVISED/SUBST'D: ;; `mon-get-system-process' -> `mon-get-process' ;; `mon-get-system-process-list' -> `mon-get-sys-proc-list' ;; `mon-insert-system-process-list' -> `mon-insert-sys-proc-list' ;; `mon-get-system-process-w-name' -> `mon-get-proc-w-name' ;; ;; DEPRECATED: ;; ;; RENAMED: ;; ;; MOVED: ;; `mon-get-system-specs' <- mon-utils.el ;; `mon-get-env-vars-symbols' <- mon-utils.el ;; `mon-get-env-vars-strings' <- mon-utils.el ;; `mon-get-env-vars-emacs' <- mon-utils.el ;; `mon-get-sys-proc-list' <- mon-utils.el ;; `mon-insert-sys-proc-list' <- mon-utils.el ;; `mon-get-proc-w-name' <- mon-utils.el ;; `mon-get-process' <- mon-utils.el ;; `mon-escape-string-for-cmd' <- mon-utils.el ;; `mon-terminal' <- mon-utils.el ;; `mon-cmd' <- mon-utils.el ;; `mon-firefox' <- mon-utils.el ;; `mon-conkeror' <- mon-utils.el ;; TODO: ;; ;; NOTES: ;; ;; SNIPPETS: ;; ;; REQUIRES: ;; ;; THIRD-PARTY-CODE: ;; ;; FIRST-PUBLISHED: ;; ;; FILE-CREATED: ;; ;; ;; ================================================================= ;;; LICENSE: ;; ================================================================= ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 3, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth ;; Floor, Boston, MA 02110-1301, USA. ;; ================================================================= ;; Permission is granted to copy, distribute and/or modify this ;; document under the terms of the GNU Free Documentation License, ;; Version 1.3 or any later version published by the Free Software ;; Foundation; with no Invariant Sections, no Front-Cover Texts, ;; and no Back-Cover Texts. A copy of the license is included in ;; the section entitled ``GNU Free Documentation License''. ;; ;; A copy of the license is also available from the Free Software ;; Foundation Web site at: ;; (URL `http://www.gnu.org/licenses/fdl-1.3.txt'). ;;; ============================== ;; Copyright © 2010-2024 MON KEY ;;; ============================== ;;; CODE: (eval-when-compile (require 'cl-lib)) (unless (and (intern-soft "*IS-MON-OBARRAY*") (bound-and-true-p *IS-MON-OBARRAY*)) (setq *IS-MON-OBARRAY* (make-vector 17 nil))) (declare-function w32-shell-execute "w32fns.c") ;;; ============================== ;;; :CREATED (defgroup mon-env-proc-utils nil "Customization group for variables and functions of :FILE mon-env-proc-utils.el\n :SEE-ALSO `mon-base', `mon-xrefs', `mon-macs', `mon-dir-locals', `mon-error-warn', `mon-regexp-symbols', `mon-dir-utils', `mon-line-utils', `mon-seq-utils', `mon-plist-utils', `mon-string-utils', `mon-insertion-utils', `mon-replacement-utils', `mon-buffer-utils', `mon-window-utils', `mon-button-utils', `mon-type-utils', `mon-type-utils-vars', `mon-image-utils', `mon-bzr-utils', `mon-env-proc-utils', `mon-testme-utils', `mon-error-utils', `mon-url-utils', `mon-boxcutter'.\n▶▶▶" ;; :prefix "" :link '(emacs-library-link :tag "\n:FILE mon-env-proc-utils.el" "mon-env-proc-utils.el") :group 'mon-base) ;;; ============================== ;;; :CREATED (defcustom *mon-env-proc-utils-xrefs* '(mon-get-system-specs mon-get-env-vars-symbols mon-get-env-vars-strings mon-get-env-vars-emacs mon-get-sys-proc-list mon-insert-sys-proc-list mon-get-proc-w-name mon-get-process mon-escape-string-for-cmd mon-terminal mon-cmd mon-firefox mon-conkeror *mon-env-proc-utils-xrefs*) "Xrefing list of `mon-*-'symbols, functions constants, and variables.\n The symbols contained of this list are defined in :FILE mon-env-proc-utils.el\n :SEE-ALSO `*mon-default-loads-xrefs*', `*mon-default-start-loads-xrefs*', `*mon-dir-locals-alist-xrefs*', `*mon-dir-utils-xrefs*', `*mon-keybindings-xrefs*', `*mon-testme-utils-xrefs*', `*mon-button-utils-xrefs*', `*mon-bzr-utils-xrefs*' `*mon-buffer-utils-xrefs*', `*mon-error-utils-xrefs*', `*mon-line-utils-xrefs*', `*mon-macs-xrefs*', `*mon-plist-utils-xrefs*', `*mon-post-load-hooks-xrefs*', `*mon-seq-utils-xrefs*', `*mon-string-utils-xrefs*', `*mon-type-utils-xrefs*', `*mon-window-utils-xrefs*', `*naf-mode-xref-of-xrefs*', `*mon-slime-xrefs*', `*naf-mode-faces-xrefs*', `*naf-mode-date-xrefs*', `*mon-ulan-utils-xrefs*', `*google-define-redux-xrefs*', `*mon-xrefs-xrefs'.\n▶▶▶" :type '(repeat symbol) :group 'mon-env-proc-utils :group 'mon-xrefs) ;;; ============================== ;;; :PREFIX "mgss-" ;;; :CREATED (defun mon-get-system-specs (&optional insrtp intrp) "Return the output of shell-command 'uname -a'.\n When called-interactively or INSRTP is non-nil insert at point.\n Does not move point.\n :EXAMPLE\n\n\(mon-get-system-specs\)\n \(mon-with-inhibit-buffer-read-only \(save-excursion \(newline\) \(mon-get-system-specs t\)\)\)\n :SEE-ALSO `system-name', `mon-get-env-vars-strings', `mon-get-env-vars-symbols', `mon-get-env-vars-emacs', `mon-get-proc-w-name', `mon-get-sys-proc-list', `mon-insert-sys-proc-list', `setenv', `setenv-internal', `getenv', `read-envvar-name', `substitute-in-file-name', `substitute-env-vars', `process-environment', `initial-environment'.\n▶▶▶" (interactive "i\np") (if (executable-find "uname") (let ((mgss-unm (shell-command-to-string "uname -a"))) (setq mgss-unm (replace-regexp-in-string "[[:blank:]]+" " " mgss-unm)) (if (or insrtp intrp) (save-excursion (newline) (princ mgss-unm (current-buffer))) mgss-unm)) (when (eq system-type 'windows-nt) ;; (mon-message :w-spec '(":FUNCTION `mon-get-system-specs' " ;; "-- the command `uname -a' is not available")) (message "The command `uname -a' is not available")))) ;; ;;; :TEST-ME (mon-get-system-specs) ;;; :TEST-ME (mon-get-system-specs t) ;;; ============================== ;;; :PREFIX "mgevsym-" ;;; :CREATED (defun mon-get-env-vars-symbols () "Return a list of symbols for current-process' environmental-variables.\n like `mon-get-env-vars-strings' but returns symbols instead of strings.\n :EXAMPLE\n\n\(mon-get-env-vars-symbols\)\n :SEE-ALSO `mon-get-env-vars-strings', `mon-get-system-specs', `mon-help-emacs-introspect', `setenv', `setenv-internal', `getenv', `read-envvar-name', `substitute-in-file-name', `substitute-env-vars', `process-environment', `initial-environment'.\n▶▶▶" (interactive) ;; :WAS ;; (let ((mgevsym-proc-env process-environment) ;; mgevsym-gthr) ;; (dolist (mgevsym-D-1 mgevsym-proc-env mgevsym-gthr) ;; (when (string-match "\\(.*\\)=.*" mgevsym-D-1) ;; (push (car (read-from-string mgevsym-D-1 (match-beginning 0) (match-end 1))) mgevsym-gthr))))) (let* ((mgevsym-proc-env process-environment) (mgevsym-obarray (make-vector (length mgevsym-proc-env) nil))) (mapc #'(lambda (mgevsym-L-1) (when (string-match "\\(.*\\)=.*" mgevsym-L-1) (intern (substring mgevsym-L-1 (match-beginning 0) (match-end 1)) mgevsym-obarray))) mgevsym-proc-env) ;; Reuse local var mgevsym-proc-env to store symbols accumulated to mgevsym-obarray (setq mgevsym-proc-env nil) (mapatoms #'(lambda (mgevsym-L-2) (unless (null mgevsym-L-2) (push mgevsym-L-2 mgevsym-proc-env))) mgevsym-obarray) (setq mgevsym-proc-env (nreverse mgevsym-proc-env)))) ;;; ============================== ;;; :PREFIX "mgevs-" ;;; :COURTESY :FILE emacs/lisp/env.el :WAS `read-envvar-name' ;;; :CREATED (defun mon-get-env-vars-strings (&optional as-strings insrtp intrp) "Return a list strings for the current process' enviromental variables.\n When AS-STRINGS is non-nil or called with a prefix-arg return as strings.\n When insrtp or called-interactively insert returned vars at point.\n :EXAMPLE\(mon-get-env-vars-strings\)\n \(mon-get-env-vars-strings t\)\n \(mon-with-inhibit-buffer-read-only \(save-excursion \(newline\) \(mon-get-env-vars-strings nil t\)\)\)\n :SEE-ALSO `mon-get-env-vars-symbols', `mon-get-env-vars-emacs', `mon-get-system-specs', `mon-help-emacs-introspect', `process-environment', `initial-environment', `setenv', `getenv', `read-envvar-name'.\n▶▶▶" (interactive "P\ni\np") (let ((mgevs-getenvs (mapcar #'(lambda (mgevs-L-1) (let ((mgevs-L-1-str (substring mgevs-L-1 0 (string-match-p "=" mgevs-L-1)))) (if (multibyte-string-p mgevs-L-1-str) (decode-coding-string mgevs-L-1-str locale-coding-system t) mgevs-L-1-str))) ;; :NOTE Why did this use append here? (append process-environment)))) (setq mgevs-getenvs (sort mgevs-getenvs #'string<)) (when as-strings (setq mgevs-getenvs (concat "\"" (mapconcat #'identity mgevs-getenvs "\"\n\"") "\""))) (cond ((or insrtp intrp) ;; (mapc (lambda (x) (prin1 x (current-buffer))) mgevs-getenvs) (if as-strings (prin1 mgevs-getenvs (current-buffer)) (princ mgevs-getenvs (current-buffer)))) (t (if as-strings (prin1 mgevs-getenvs) mgevs-getenvs))))) ;; ;;; :TEST-ME (mon-get-env-vars-strings) ;;; :TEST-ME (mon-get-env-vars-strings t) ;;; :TEST-ME (mon-get-env-vars-strings nil nil) ;;; :TEST-ME (mon-get-env-vars-strings t t) ;;; :TEST-ME (mon-get-env-vars-strings nil t) ;;; :TEST-ME (princ (mon-get-env-vars-strings t) (current-buffer)) ;;; :TEST-ME (prin1 (mon-get-env-vars-strings t) (current-buffer)) ;;; ============================== ;;; :PREFIX "mgeve-" ;;; :CREATED (defun mon-get-env-vars-emacs (&optional insrtp intrp) "Return an list of the current environmental variables of the running Emacs.\n Alist Keys have the form:\n \(:ENV-VAR \"VALUE-STRING\"\) \(ENV_VAR \"VALUE-STRING\"\)\n For each colon prefixed :ENV-VAR key there is an equivalent symbol key. Each has an identical value.\n :EXAMPLE\n\n\(mon-get-env-vars-emacs\)\n \(mapcar 'car \(mon-get-env-vars-emacs\)\)\n :NOTE MON stores some local variables in `*mon-misc-path-alist*'. When this symbol is present values associated with the key ``the-emacs-vars'' will also included when generating the return value.\n When called-interactively pretty-print return value in buffer named \"*MON-EMACS-ENV-VARS*\".\n :SEE info node `(emacs)General Variables'.\n :SEE-ALSO `mon-get-env-vars-strings', `mon-get-env-vars-symbols' `mon-get-system-specs', `mon-insert-sys-proc-list', `mon-get-sys-proc-list', `mon-get-proc-w-name', `mon-get-process', `mon-help-process-functions', `mon-help-emacs-introspect', `emacs-pid', `process-environment', `initial-environment', `getenv', `setenv'.\n▶▶▶" (interactive "i\np") (let ((mgeve-vars (mon-intersection (mon-get-env-vars-symbols) (append ;; MON-LOCAL-VARS (when (bound-and-true-p *mon-misc-path-alist*) (cadr (assq 'the-emacs-vars *mon-misc-path-alist*))) (cl-do* ((i '( ;; :LENNART-EMACS-W32-VARS EMACSCLIENT_STARTING_SERVER EMACS_SERVER_FILE ;; :GNUS-MAIL ;; MH NNTPSERVER REPLYTO SAVEDIR SMTPSERVER MAIL ;; ORGANIZATION VERSION_CONTROL HISTFILE EMAIL EMACS_UNIBYTE CDPATH ;; :STANDARD-EMACS-VARS EMACS_DIR INFOPATH INCPATH EMACSLOADPATH EMACSDATA EMACSPATH PATH EMACSDOC ESHELL SHELL TERM DBUS_SESSION_BUS_ADDRESS HOME INFOPATH LOGNAME ) i) (j (pop i) (pop i)) (k)) ((null j) (nreverse k)) (when (getenv (format "%s" j)) (push j k)))) nil t)) gthr-env-vars) (dolist (mgeve-D-1 mgeve-vars (setq gthr-env-vars (nreverse gthr-env-vars))) (let ((mgeve-D-lcl-is-var (car (memq mgeve-D-1 mgeve-vars))) mgeve-D-lcl-var-prs) (unless (null mgeve-D-lcl-is-var) (let* ((mgeve-D-lcl2-frmt-var (upcase (format "%s" mgeve-D-lcl-is-var))) (mgeve-D-lcl2-get-var (file-truename (getenv mgeve-D-lcl2-frmt-var)))) (push `(,(car (read-from-string (subst-char-in-string 95 45 (concat ":" mgeve-D-lcl2-frmt-var)))) . ,mgeve-D-lcl2-get-var) mgeve-D-lcl-var-prs) (push `(,(car (read-from-string mgeve-D-lcl2-frmt-var)) . ,mgeve-D-lcl2-get-var) mgeve-D-lcl-var-prs))) (setq mgeve-D-lcl-var-prs (nreverse mgeve-D-lcl-var-prs)) (push (car mgeve-D-lcl-var-prs) gthr-env-vars) (push (cadr mgeve-D-lcl-var-prs) gthr-env-vars))) insrtp ;; Not currently evaluating INSRTP. ;;(when intrp (or (and intrp (let ((mgeve-get-bfr (get-buffer-create "*MON-EMACS-ENV-VARS*"))) (with-current-buffer (buffer-name mgeve-get-bfr) (erase-buffer) (pp-display-expression gthr-env-vars (buffer-name mgeve-get-bfr)) (mon-g2be -1) (insert ";; :MON-EMACS-ENV-VARS output from:\n;; (mon-get-env-vars-emacs nil t)\n;;\n")))) gthr-env-vars))) ;; ;;; :TEST-ME (mon-get-env-vars-emacs) ;;; :TEST-ME (mapcar 'car (mon-get-env-vars-emacs)) ;;; ============================== ;;; :PREFIX "mgspl" ;;; :NOTE MON recently found the :FILE proced.el ;;; Some of this might be accomplished with that excellent package. ;;; :CREATED (defun mon-get-sys-proc-list (&optional intrp) "Return a full lisp list of current system-proceses.\n When called-interactively return results in buffer \"*MON-GET-SYS-PROCESSES*\".\n :EXAMPLE:\n\n(mon-get-sys-proc-list)\n\n\(mon-get-sys-proc-list t\)\n :ALIASED-BY `mon-get-system-process-list'.\n :SEE-ALSO `mon-get-process',`mon-insert-sys-proc-list', `mon-help-process-functions', `mon-get-env-vars-strings', `mon-get-env-vars-symbols', `mon-get-env-vars-emacs', `mon-get-system-specs', `mon-help-emacs-introspect', `emacs-pid'.\n▶▶▶" (interactive "p") (let (mgspl) (dolist (sys-proc (list-system-processes) (setq mgspl (nreverse mgspl))) (push (process-attributes sys-proc) mgspl)) (or (and intrp (pp-display-expression mgspl "*MON-GET-SYS-PROCESSES*")) mgspl))) ;; ;;; :TEST-ME (mon-get-sys-proc-list) ;;; :TEST-ME (mon-get-sys-proc-list t) ;;; ============================== ;;; :PREFIX "mispl-" ;;; :NOTE MON recently found the :FILE proced.el ;;; Some of this might be accomplished with that excellent package. ;;; CREATED: (defun mon-insert-sys-proc-list () "Insert a full lisp list of current system-proceses at point. Does not move point.\n :ALIASED-BY `mon-insert-system-process-list'.\n :SEE-ALSO `mon-get-process', `mon-get-sys-proc-list', `mon-insert-sys-proc-list', `emacs-pid', `mon-get-env-vars-strings', `mon-get-env-vars-symbols' `mon-get-env-vars-emacs', `mon-get-system-specs' `mon-help-emacs-introspect'.\n▶▶▶" (interactive) (save-excursion (newline) (mapc #'(lambda (mispl-L-1) (princ (concat ";;;\n" (pp mispl-L-1))(current-buffer))) (mon-get-sys-proc-list)))) ;;; ============================== ;;; :PREFIX "mgpwn-" ;;; :NOTE MON recently found the :FILE proced.el ;;; Some of this might be accomplished with that excellent package. ;;; :CREATED (defun mon-get-proc-w-name (proc-w-name) "Return list of `process-attributes' for all PROC-W-NAME.\n PROC-W-NAME \(a string\) names a process by command/executable name.\n When multiple commands of the same name exists return value is sorted youngest process first.\n :EXAMPLE\n\n\(mon-get-proc-w-name \"emacs\"\)\n :NOTE On w32 it is not required give the .exe suffix.\n :ALIASED-BY `mon-get-system-process-w-name'.\n :SEE-ALSO `mon-get-process', `mon-get-sys-proc-list', `mon-get-sys-proc-list', `mon-help-process-functions', `list-system-processes'.\n▶▶▶" (eval-when-compile (require 'time-date)) (let (mgpwn-fnd-proc) (mapc #'(lambda (mgpwn-L-1) (let ((mgpwn-L-1-chk-com-nm (assq 'comm mgpwn-L-1))) (and mgpwn-L-1-chk-com-nm (string-match-p proc-w-name (cdr mgpwn-L-1-chk-com-nm)) ;"emacs.exe" (push mgpwn-L-1 mgpwn-fnd-proc)))) (mon-get-sys-proc-list)) (and mgpwn-fnd-proc (or (and (> (length mgpwn-fnd-proc) 1) (sort mgpwn-fnd-proc #'(lambda (mgpwn-L-1-t1 mgpwn-L-1-t2) ;; Make sure the process has a start time. (setq mgpwn-L-1-t1 (assq 'start mgpwn-L-1-t1)) (setq mgpwn-L-1-t2 (assq 'start mgpwn-L-1-t2)) (and mgpwn-L-1-t1 mgpwn-L-1-t2 (time-less-p (cdr mgpwn-L-1-t2) (cdr mgpwn-L-1-t1)))))) mgpwn-fnd-proc)))) ;; ;;; :TEST-ME (mon-get-proc-w-name "mrxvt") ;;; :TEST-ME (mon-get-proc-w-name "emacs") ;;; :TEST-ME (mon-get-proc-w-name "svchost") ;;; :TEST-ME (mon-get-proc-w-name "bubba") ;;; :TEST-ME (mon-get-proc-w-name (invocation-name)) ;;; ============================== ;;; :NOTE Built to test for "mysql" command before looking for a comint. ;;; MON recently found the :FILE proced.el ;;; Some of this might be accomplished with that excellent package. ;;; :NOTE `mon-get-process' uses `flet' cl--find-if -> `find-if' ;;; :CREATED (defun mon-get-process (&optional proc-comm) "Find the process-id for process invoked with command. When PROC-COMM is non-nil it is a command name to find. Default is value of \(invocation-name\).\n :NOTE This function is GNU/Linux centric! However, unlike `mon-get-proc-w-name' this function can match multiple processes with identical invocation commands.\n :EXAMPLE\n\n\(if IS-W32-P \(mon-get-process \(concat \(invocation-name\) \".exe\"\)\) \(mon-get-process \(invocation-name\)\)\)\n \(mon-get-process \"Finder\"\) ; Darwin\n :ALIASED-BY `mon-get-system-process'.\n :SEE-ALSO `mon-insert-sys-proc-list', `mon-get-sys-proc-list', `mon-help-process-functions'.\n▶▶▶" (interactive) (let* (mgp-mtchs (mpg-prc-lst (list-system-processes)) ;;(nreverse (list-system-processes))) (mgp-map-procs #'(lambda (mgp-L-1) (cl-flet ((cl--fi (cl-pred cl-list &rest cl-keys) ;; `find-if' (apply 'find nil cl-list :if cl-pred cl-keys))) (let ((mgp-L1-lcl-mtch (cl--fi #'(lambda (mgp-L1-flcl) (and (eql (car mgp-L1-flcl) 'comm) (equal (cdr mgp-L1-flcl) (if proc-comm proc-comm invocation-name)))) (process-attributes mgp-L-1)))) (when mgp-L1-lcl-mtch (if (not mpg-prc-lst) (push `(,mgp-L-1 ,mgp-L1-lcl-mtch) mpg-prc-lst) (push mgp-L-1 mgp-mtchs)))))))) (mapc mgp-map-procs mpg-prc-lst) (if mgp-mtchs (progn (setq mpg-prc-lst nil) (mapc mgp-map-procs mgp-mtchs) ;; :WAS (if mpg-prc-lst mpg-prc-lst)) (or mpg-prc-lst)) mgp-mtchs))) ;; ;;; :TEST-ME (if IS-W32-P ;;; (mon-get-process (concat (invocation-name) ".exe")) ;;; (mon-get-process (invocation-name))) ;;; ============================== ;;; :PREFIX "mesfc-" ;;; :CREATED (defun mon-escape-string-for-cmd (unescape a-string &rest more-strings) "Return A-STRING escaped for passing to the w32 cmd.exe e.g `/' -> `\\\\'. When MORE-STRINGS is non-nil escape these also.\n When UNESCAPE is non-nil unescape A-STRING and/or MORE-STRINGS.\n :SEE-ALSO `convert-standard-filename', `w32-shell-dos-semantics'. `w32-quote-process-args', `mon-exchange-slash-and-backslash', `mon-escape-lisp-string-region', `mon-unescape-lisp-string-region'.\n▶▶▶" (let ((mesfc-mr-str (if more-strings (cons a-string more-strings) a-string)) (mesfc-rplc (if unescape #'(lambda (mesfc-L-1) (replace-regexp-in-string "\\\\" "/" mesfc-L-1)) #'(lambda (mesfc-L-2) (replace-regexp-in-string "/" "\\\\" mesfc-L-2))))) (if (consp mesfc-mr-str) (mapconcat mesfc-rplc mesfc-mr-str " ") (funcall mesfc-rplc mesfc-mr-str)))) ;;; ============================== (defun mon-terminal () "When `gnu-linuxp' launch a terminal.\n When `win32p' invoke Cygwin Bash in cmd console.\n :SEE-ALSO `mon-cmd' which when win32p returns the NT Command console. `mon-shell', `mon-make-shell-buffer', `w32shell-cmd-here', `w32shell-cmd', `w32shell-explorer', `mon-help-process-functions'.\n▶▶▶" (interactive) (cond ((and (intern-soft "IS-BUG-P" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-BUG-P)) (message "You don't have the goods for this")) ((and (intern-soft "IS-MON-P-W32" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-MON-P-W32)) (w32-shell-execute "open" "cmd.exe" "C:\\Cygwin.bat")) ((and (intern-soft "IS-MON-P-GNU" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-MON-P-GNU)) (shell-command "mrxvt")) (t (message ":FUNCTION `mon-terminal' -- check the manual :P")))) ;;; ============================== (defun mon-cmd () "When `win32p' launch the NT Command console.\n When `gnu-linuxp' launch a terminal \(mrxvt\).\n :SEE `mon-terminal' which when `win32p' gives a Cygwin bash shell wrapped in a cmd console.\n :SEE-ALSO `mon-shell', `mon-make-shell-buffer', `w32shell-cmd-here', `w32shell-cmd', `w32-shell-execute', `w32shell-explorer', `shell-command', `shell', `mon-help-process-functions'.\n▶▶▶" (interactive) (cond ((and (intern-soft "IS-W32-P" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-W32-P)) (w32-shell-execute "open" "cmd")) ((and (intern-soft "IS-GNU-P" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-GNU-P)) ;; :WAS (shell-command "terminal") (shell-command "mrxvt")) (t (message ":FUNCTION `mon-cmd' -- not sure which terminal/console to use")))) ;;; ============================== (defun mon-firefox (url &optional intrp) "Jump to the running firefox and open URL in new tab.\n :SEE-ALSO `browse-url-firefox-program',`mon-conkeror', `browse-url-generic-program', `browse-url-browser-function', `browse-url-generic'.\n▶▶▶" (interactive "i\np") (when intrp (setq url (read-string ":FUNCTION `mon-firefox' -- which URL: "))) (browse-url-firefox url)) ;;; ============================== (defun mon-conkeror (url) "Launch or find a running conkeror web browser with URL.\n :NOTE To enusre Emacs gets existing conkeror process put following in conkeror-rc file: url_remoting_fn = load_url_in_new_buffer; require\(\"clicks-in-new-buffer.js\");\n :SEE-ALSO `mon-firefox', `browse-url-firefox-program', `browse-url-generic-program',`browse-url-browser-function', `browse-url-generic'.\n▶▶▶" (interactive "s:FUNCTION `mon-conkeror' -- what URL: ") (eval-when-compile (require 'browse-url)) (if (string-match "conkeror" browse-url-generic-program) (cond ;; :NOTE These conditionals are here so we can adjust as needed. ((and (intern-soft "IS-MON-P-W32" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-MON-P-W32)) (browse-url-generic url)) ((and (intern-soft "IS-MON-P-GNU" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-MON-P-GNU)) (browse-url-generic url)) ((and (intern-soft "IS-BUG-P" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-BUG-P)) (browse-url-generic url)) ((and (intern-soft "IS-MON-SYSTEM-P" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-MON-SYSTEM-P)) (browse-url-generic url)) ((and (intern-soft "IS-NOT-A-MON-SYSTEM" obarray) ;; *IS-MON-OBARRAY* (bound-and-true-p IS-NOT-A-MON-SYSTEM)) (browse-url-generic url)) (t (mon-format :w-fun #'error :w-spec '(":FUNCTION `mon-conkeror' " "-- can not grok your system and/or " "conkeror not set as `browse-url-generic-program'")))) (mon-format :w-fun #'error :w-spec '(":FUNCTION `mon-conkeror' " "-- conkeror not set `browse-url-generic-program'")))) ;;; ============================== (provide 'mon-env-proc-utils) ;;; ============================== ;; Local Variables: ;; mode: EMACS-LISP ;; coding: utf-8 ;; generated-autoload-file: "./mon-loaddefs.el" ;; End: ;;; ==================================================================== ;;; mon-env-proc-utils.el ends here ;;; EOF