[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Need help improving an elisp 'GNU grep --version' query
From: |
Andrew M. Scott |
Subject: |
Need help improving an elisp 'GNU grep --version' query |
Date: |
Mon, 25 Aug 2003 09:42:27 -0700 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
Goal:
Elisp code that can query GNU 'grep --version' feedback so I can
conditionally use more advanced GNU grep-command option flags, if a
more advanced version of grep is available.
I'm looking for a *clean* solution that I can extend for use with the
--version results of other GNU utilities.
Current Ugly Code fragments:
(defun my-grep-version ()
(interactive)
(insert (shell-command "ggrep --version | head -1 | awk '{print $4}'" t nil))
(backward-delete-char 1))
This M-x my-grep-version returns "2.5.1" or "2.4.2" at point in the current
buffer and "Invalid character: 01414, 780, 0x30c" in the minibuffer.
;; This next snippet would work if my-grep-version were a string variable with
;; value"2.5.1" or "2.4.2"
(if (string-lessp "2.7" (my-grep-version))
(progn
;; GNU grep 2.5+
;; (setq grep-command "ggrep -nH -i --color=always --exclude='\.newsrc.*'
")
(setq grep-command "ggrep -nH -i --exclude='\.newsrc.*' ")
)
;; GNU grep 2.4 or earlier
(setq grep-command "ggrep -nH -i ")
)
Notes & Questions:
1. How do I capture the output of the (shell-command ....) stuff
into a variable? I'd rather my-grep-version be a variable vs. a
function, so I test it later in my .emacs.
2. GNU 'grep --version' returns its version information to stderr not
stdout. I played with several variations of shell-command and
call-process and couldn't figure out how to get the results of the
(shell-command .. ) or equivalent stderr result into a variable
which I could test.
Thanks in advance.
Andy Scott
--
The opinions expressed herein are mine, *not* Intel's.
Andrew M. Scott, Intel Corporation - WCCG-DA Strategic Capabilities
Intel Corporation, M/S CH6-210 Voice: 480-554-9615 RIM PIN: 16545823
ascott@sedona.intel.com (e-mail with "PAGE" in subj to forward to RIM)
- Need help improving an elisp 'GNU grep --version' query,
Andrew M. Scott <=