* Re: EB double-grep function for bash [not found] <mailman.1702.1468961014.26859.help-gnu-emacs@gnu.org> @ 2016-07-21 16:21 ` Emanuel Berg 0 siblings, 0 replies; 2+ messages in thread From: Emanuel Berg @ 2016-07-21 16:21 UTC (permalink / raw) To: help-gnu-emacs Tomas Nordin wrote: > Since the thread strayed away a little from > emacs already... Only superficially. The problem is how to find a particular Emacs tool. The assumption is that the user knows the conventional designation of the tool and that the same designation is used in Emacs. The answer what to do is as usual not a single answer but a toolbox of methods in itself, one of the tools proposed being greping the Emacs source. To do that we use the conventional shell tools like grep, but one could easily think of several others, e.g., awk, sed, even Perl. To those who didn't know, grep is not only an acronym-contraction, it was once a *command* in one of the early line editors, for "global regular expression print" - which makes sense! I think I read this in either: @book{quarter-century-of-unix, title = {A Quarter Century of UNIX}, author = {Peter Salus}, publisher = {Addison-Wesley}, year = 1994, ISBN = 0201547775, } or @book{sed-awk, title = {sed \& awk}, author = {Dale Dougherty; Arnold Robbins}, publisher = {O'Reilly}, year = 1997, edition = {2nd edition}, ISBN = {1-56592-225-5}, } In Emacs, there is `grep', `grep-find', and so on in /usr/share/emacs/24.4/lisp/progmodes/grep.el (or: /usr/share/emacs/24.4/lisp/progmodes/grep.el.gz) That code is - advanced :) > I made a little change on two > lines in this function to make it run with > bash. (I think the array subscript is a zsh > thing). Here's the lines: > > local files > files=${@:5:$#} Cool :) -- underground experts united .... http://user.it.uu.se/~embe8573 Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic - so far: 58 Blogomatic articles - ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: require basic stuff from specific packages @ 2016-07-16 7:07 Emanuel Berg 2016-07-19 20:43 ` EB double-grep function for bash Tomas Nordin 0 siblings, 1 reply; 2+ messages in thread From: Emanuel Berg @ 2016-07-16 7:07 UTC (permalink / raw) To: help-gnu-emacs Here is another approach, namely to abandon the Emacs documentation and help interface and instead operate directly on the source with shell tools, i.e. grep. The advantage is that it works, and even better perhaps; there is no unsafe `require' just to get function definitions; and, it is much faster. There is also the ease of use advantage because you can get all Elisp in the world and just pour it into a directory and there won't be any conflicts or problems loading or whatever as it'll just be a bunch of dead text! All in all, an unusually good solution - as usual! (yeah - how *do* you get *all* MELPA and GNU ELPA code?) Here is the function: double-grep () { local first=$1 # e.g., trim (most unusual concept first!) local second=$2 # string (the the more usual...) local context=$3 # 0 => no context: hits must be on same line local results=$4 # 10 => show max 10 (double) hits local -a files files=($@[5,-1]) # e.g., ~/sw/emacs24-24.4+1/lisp/**/*.el grep --color=always -C $context $first $files \ | grep --color=always $second \ | head -n $results # invocation example: # # $ cd ~/sw/emacs24-24.4+1/lisp/ # $ double-grep trim string 0 10 **/*.el } -- underground experts united .... http://user.it.uu.se/~embe8573 Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic - so far: 58 Blogomatic articles - ^ permalink raw reply [flat|nested] 2+ messages in thread
* EB double-grep function for bash 2016-07-16 7:07 require basic stuff from specific packages Emanuel Berg @ 2016-07-19 20:43 ` Tomas Nordin 0 siblings, 0 replies; 2+ messages in thread From: Tomas Nordin @ 2016-07-19 20:43 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg writes: > Here is the function: > > double-grep () { > local first=$1 # e.g., trim (most unusual concept first!) > local second=$2 # string (the the more usual...) > > local context=$3 # 0 => no context: hits must be on same line > local results=$4 # 10 => show max 10 (double) hits > > local -a files > files=($@[5,-1]) # e.g., ~/sw/emacs24-24.4+1/lisp/**/*.el > > grep --color=always -C $context $first $files \ > | grep --color=always $second \ > | head -n $results > > # invocation example: > # > # $ cd ~/sw/emacs24-24.4+1/lisp/ > # $ double-grep trim string 0 10 **/*.el > } Since the thread strayed away a little from emacs already... I made a little change on two lines in this function to make it run with bash. (I think the array subscript is a zsh thing). Here's the lines: local files files=${@:5:$#} # e.g., ~/sw/emacs24-24.4+1/lisp/**/*.el -- Tomas Nordin | (The computing freedom explorer) GPG Key: AB09AF78 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-21 16:21 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <mailman.1702.1468961014.26859.help-gnu-emacs@gnu.org> 2016-07-21 16:21 ` EB double-grep function for bash Emanuel Berg 2016-07-16 7:07 require basic stuff from specific packages Emanuel Berg 2016-07-19 20:43 ` EB double-grep function for bash Tomas Nordin
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.