Function: sh-feature

sh-feature is a byte-compiled function defined in sh-script.el.gz.

Signature

(sh-feature ALIST &optional FUNCTION)

Documentation

Index ALIST by the current shell.

If ALIST isn't a list where every element is a cons, it is returned as is. Else indexing follows an inheritance logic which works in two ways:

  - Fall back on successive ancestors (see sh-ancestor-alist) as long as
    the alist contains no value for the current shell.
    The ultimate default is always sh.

  - If the value thus looked up is a list starting with sh-append,
    we call the function sh-append with the rest of the list as
    arguments, and use the value. However, the next element of the
    list is not used as-is; instead, we look it up recursively
    in ALIST to allow the function called to define the value for
    one shell to be derived from another shell.
    The value thus determined is physically replaced into the alist.

If FUNCTION is non-nil, it is called with one argument, the value thus obtained, and the result is used instead.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/sh-script.el.gz
(defun sh-feature (alist &optional function)
  "Index ALIST by the current shell.
If ALIST isn't a list where every element is a cons, it is returned as is.
Else indexing follows an inheritance logic which works in two ways:

  - Fall back on successive ancestors (see `sh-ancestor-alist') as long as
    the alist contains no value for the current shell.
    The ultimate default is always `sh'.

  - If the value thus looked up is a list starting with `sh-append',
    we call the function `sh-append' with the rest of the list as
    arguments, and use the value.  However, the next element of the
    list is not used as-is; instead, we look it up recursively
    in ALIST to allow the function called to define the value for
    one shell to be derived from another shell.
    The value thus determined is physically replaced into the alist.

If FUNCTION is non-nil, it is called with one argument,
the value thus obtained, and the result is used instead."
  (or (if (consp alist)
	  ;; Check for something that isn't a valid alist.
	  (let ((l alist))
	    (while (and l (consp (car l)))
	      (setq l (cdr l)))
	    (if l alist)))

      (let ((orig-sh-shell sh-shell))
	(let ((sh-shell sh-shell)
	      elt val)
	  (while (and sh-shell
		      (not (setq elt (assq sh-shell alist))))
	    (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
	  ;; If the shell is not known, treat it as sh.
	  (unless elt
	    (setq elt (assq 'sh alist)))
	  (setq val (cdr elt))
	  (if (and (consp val)
		   (memq (car val) '(sh-append sh-modify)))
	      (setq val
		    (apply (car val)
			   ;; Refer to the value for a different shell,
			   ;; as a kind of inheritance.
			   (let ((sh-shell (car (cdr val))))
			     (sh-feature alist))
			   (cddr val))))
	  (if function
	      (setq sh-shell orig-sh-shell
		    val (funcall function val)))
	  val))))