Function: eshell-parse-modifiers

eshell-parse-modifiers is a byte-compiled function defined in em-pred.el.gz.

Signature

(eshell-parse-modifiers)

Documentation

Parse value modifiers and predicates at point.

Return a cons cell of the form

  (PRED-FUNC-LIST . MOD-FUNC-LIST)

PRED-FUNC-LIST is a list of predicate functions. MOD-FUNC-LIST is a list of result modifier functions. PRED-FUNCS take a filename and return t if the test succeeds; MOD-FUNCS take any list of strings and perform a modification, returning the resultant list of strings.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-pred.el.gz
(defun eshell-parse-modifiers ()
  "Parse value modifiers and predicates at point.
Return a cons cell of the form

  (PRED-FUNC-LIST . MOD-FUNC-LIST)

PRED-FUNC-LIST is a list of predicate functions.  MOD-FUNC-LIST
is a list of result modifier functions.  PRED-FUNCS take a
filename and return t if the test succeeds; MOD-FUNCS take any
list of strings and perform a modification, returning the
resultant list of strings."
  (let (negate follow preds mods)
    (condition-case nil
	(while (not (eobp))
	  (let ((char (char-after)))
	    (cond
	     ((eq char ?')
	      (forward-char)
	      (if (looking-at "[^|':]")
		  (let ((func (read (current-buffer))))
		    (if (and func (functionp func))
			(setq preds (eshell-add-pred-func (eval func t) preds
							  negate follow))
		      (error "Invalid function predicate `%s'"
			     (eshell-stringify func))))
		(error "Invalid function predicate")))
	     ((eq char ?^)
	      (forward-char)
	      (setq negate (not negate)))
	     ((eq char ?-)
	      (forward-char)
	      (setq follow (not follow)))
	     ((eq char ?|)
	      (forward-char)
	      (if (looking-at "[^|':]")
		  (let ((func (read (current-buffer))))
		    (if (and func (functionp func))
			(setq mods
			      (cons (lambda (lst) (mapcar func lst))
				    mods))
		      (error "Invalid function modifier `%s'"
			     (eshell-stringify func))))
		(error "Invalid function modifier")))
	     ((eq char ?:)
	      (forward-char)
	      (let ((mod (assq (char-after) eshell-modifier-alist)))
		(if (not mod)
		    (error "Unknown modifier character `%c'" (char-after))
		  (forward-char)
		  (setq mods (cons (eval (cdr mod) t) mods)))))
	     (t
	      (let ((pred (assq char eshell-predicate-alist)))
		(if (not pred)
		    (error "Unknown predicate character `%c'" char)
		  (forward-char)
		  (setq preds
			(eshell-add-pred-func (eval (cdr pred) t) preds
					      negate follow))))))))
      (end-of-buffer
       (error "Predicate or modifier ended prematurely")))
    (cons (nreverse preds) (nreverse mods))))