Function: idlwave-action-and-binding

idlwave-action-and-binding is a byte-compiled function defined in idlwave.el.gz.

Signature

(idlwave-action-and-binding KEY CMD &optional SELECT)

Documentation

KEY and CMD are made into a key binding and an indent action.

KEY is a string - same as for the define-key function. CMD is a function of one argument. CMD is bound to KEY in idlwave-mode-map by defining an anonymous function calling self-insert-command followed by CMD. If KEY contains more than one character a binding will only be set if SELECT is both.

(KEY . CMD) is also placed in the idlwave-indent-expand-table,
replacing any previous value for KEY. If a binding is not set then it will instead be placed in idlwave-indent-action-table.

If the optional argument SELECT is nil then an action and binding are created. If SELECT is noaction, then a binding is always set and no action is created. If SELECT is both then an action and binding will both be created even if KEY contains more than one character. Otherwise, if SELECT is non-nil then only an action is created.

Some examples: No spaces before and 1 after a comma
   (idlwave-action-and-binding "," (lambda (_) (idlwave-surround 0 1)))
A minimum of 1 space before and after = (see idlwave-expand-equal).
   (idlwave-action-and-binding "=" (lambda (_) (idlwave-expand-equal -1 -1)))
Capitalize system variables - action only
   (idlwave-action-and-binding idlwave-sysvar
                               (lambda (_) (capitalize-word 1) t))

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/idlwave.el.gz
;;(defmacro idlwave-with-special-syntax (&rest body)
;;  "Execute BODY with `idlwave-find-symbol-syntax-table'."
;;  `(with-syntax-table idlwave-find-symbol-syntax-table
;;     ,@body))

(defun idlwave-action-and-binding (key cmd &optional select)
  "KEY and CMD are made into a key binding and an indent action.
KEY is a string - same as for the `define-key' function.  CMD is a
function of one argument.  CMD is bound to
KEY in `idlwave-mode-map' by defining an anonymous function calling
`self-insert-command' followed by CMD.  If KEY contains more than one
character a binding will only be set if SELECT is `both'.

\(KEY . CMD) is also placed in the `idlwave-indent-expand-table',
replacing any previous value for KEY.  If a binding is not set then it
will instead be placed in `idlwave-indent-action-table'.

If the optional argument SELECT is nil then an action and binding are
created.  If SELECT is `noaction', then a binding is always set and no
action is created.  If SELECT is `both' then an action and binding
will both be created even if KEY contains more than one character.
Otherwise, if SELECT is non-nil then only an action is created.

Some examples:
No spaces before and 1 after a comma
   (idlwave-action-and-binding \",\"  (lambda (_) (idlwave-surround 0 1)))
A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
   (idlwave-action-and-binding \"=\"  (lambda (_) (idlwave-expand-equal -1 -1)))
Capitalize system variables - action only
   (idlwave-action-and-binding idlwave-sysvar
                               (lambda (_) (capitalize-word 1) t))"
  (if (not (equal select 'noaction))
      ;; Add action
      (let* ((table (if select 'idlwave-indent-action-table
                      'idlwave-indent-expand-table))
	     (table-key (regexp-quote key)))
        (setf (alist-get table-key (symbol-value table) nil nil #'equal) cmd)))
  ;; Make key binding for action
  (if (if (null select) (= (length key) 1)
        (memq select '(noaction both)))
      ;; FIXME: Use `post-self-insert-hook'!
      (define-key idlwave-mode-map key
        (lambda ()
          (interactive)
          (self-insert-command 1)
          (if (functionp cmd) (funcall cmd nil) (eval cmd t))))))