[Openmcl-devel] Keybindings

Ron Garret ron at awun.net
Thu Jun 25 00:00:51 PDT 2009

On Jun 24, 2009, at 11:42 PM, Gary Byers wrote:

> On Wed, 24 Jun 2009, Ron Garret wrote:
>> Pressing TAB indents the current line, but not the current region (if
>> there's one selected.  If I do this:
>> (hi:bind-key "Indent Region" #k"tab")
>> then TAB indents the current region if one is selected, but not the
>> current line if one is not.
>> Is there any way to get TAB to do both depending on whether or not
>> there is a selection?
> Sure: define a command that does both, depending on whether or not
> there's a selection, then bind #k"tab" to that command.


(defcommand "Indent" (p)
   "Invokes function held by the Hemlock variable \"Indent Function\",
   moving point past region if called with argument."
   (if (region-active-p)
     (let ((region (current-region)))
       (with-mark ((start (region-start region) :left-inserting)
                   (end (region-end region) :left-inserting))
         (indent-region-for-commands (region start end))))
     (let ((point (current-point)))
       (with-mark ((mark point :left-inserting))
         (cond ((or (not p) (zerop p))
                (funcall (value indent-function) mark)
                (when (mark< point mark)
                  (move-mark point mark)))
                (if (plusp p)
                  (unless (line-offset point (1- p))
                    (buffer-end point))
                  (unless (line-offset mark (1+ p))
                    (buffer-start mark)))
                (indent-region-for-commands (region mark point))
                (find-attribute (line-start point) :whitespace  


More information about the Openmcl-devel mailing list