Next: , Previous: , Up: Basic Commands   [Contents][Index]


2.4 Filtering

Filtering is a simple way to perform a fairly arbitrary transformation on text. Filtering text replaces the string in each line with the result of applying a LISP function of one argument to that string. The function must neither destructively modify the argument nor the return value. It is an error for the function to return a string containing newline characters.

Command: Filter Region

This function prompts for an expression which is evaluated to obtain a function to be used to filter the text in the region. For example, to capitalize all the words in the region one could respond:

Function: #'string-capitalize

Since the function may be called many times, it should probably be compiled. Functions for one-time use can be compiled using the compile function as in the following example which removes all the semicolons on any line which contains the string "PASCAL":

Function: (compile nil '(lambda (s)
                          (if (search "PASCAL" s)
                              (remove #\; s)
                              s)))

Next: Searching and Replacing, Previous: Modification Commands, Up: Basic Commands   [Contents][Index]