calc: Making Selections

 
 11.1.1 Making Selections
 ------------------------
 
 To select a sub-formula, move the Emacs cursor to any character in that
 sub-formula, and press ‘j s’ (‘calc-select-here’).  Calc will highlight
 the smallest portion of the formula that contains that character.  By
 default the sub-formula is highlighted by blanking out all of the rest
 of the formula with dots.  Selection works in any display mode but is
 perhaps easiest in Big mode (‘d B’).  Suppose you enter the following
 formula:
 
                 3    ___
          (a + b)  + V c
      1:  ---------------
              2 x + 1
 
 (by typing ‘' ((a+b)^3 + sqrt(c)) / (2x+1)’).  If you move the cursor to
 the letter ‘b’ and press ‘j s’, the display changes to
 
                 .    ...
          .. . b.  . . .
      1*  ...............
              . . . .
 
 Every character not part of the sub-formula ‘b’ has been changed to a
 dot.  (If the customizable variable
 ‘calc-highlight-selections-with-faces’ is non-‘nil’, then the characters
 not part of the sub-formula are de-emphasized by using a less noticeable
 face instead of using dots.  SeeDisplaying Selections.)  The ‘*’
 next to the line number is to remind you that the formula has a portion
 of it selected.  (In this case, it’s very obvious, but it might not
 always be.  If Embedded mode is enabled, the word ‘Sel’ also appears in
 the mode line because the stack may not be visible.  SeeEmbedded
 Mode.)
 
    If you had instead placed the cursor on the parenthesis immediately
 to the right of the ‘b’, the selection would have been:
 
                 .    ...
          (a + b)  . . .
      1*  ...............
              . . . .
 
 The portion selected is always large enough to be considered a complete
 formula all by itself, so selecting the parenthesis selects the whole
 formula that it encloses.  Putting the cursor on the ‘+’ sign would have
 had the same effect.
 
    (Strictly speaking, the Emacs cursor is really the manifestation of
 the Emacs “point,” which is a position _between_ two characters in the
 buffer.  So purists would say that Calc selects the smallest sub-formula
 which contains the character to the right of “point.”)
 
    If you supply a numeric prefix argument N, the selection is expanded
 to the Nth enclosing sub-formula.  Thus, positioning the cursor on the
 ‘b’ and typing ‘C-u 1 j s’ will select ‘a + b’; typing ‘C-u 2 j s’ will
 select ‘(a + b)^3’, and so on.
 
    If the cursor is not on any part of the formula, or if you give a
 numeric prefix that is too large, the entire formula is selected.
 
    If the cursor is on the ‘.’ line that marks the top of the stack
 (i.e., its normal “rest position”), this command selects the entire
 formula at stack level 1.  Most selection commands similarly operate on
 the formula at the top of the stack if you haven’t positioned the cursor
 on any stack entry.
 
    The ‘j a’ (‘calc-select-additional’) command enlarges the current
 selection to encompass the cursor.  To select the smallest sub-formula
 defined by two different points, move to the first and press ‘j s’, then
 move to the other and press ‘j a’.  This is roughly analogous to using
 ‘C-@’ (‘set-mark-command’) to select the two ends of a region of text
 during normal Emacs editing.
 
    The ‘j o’ (‘calc-select-once’) command selects a formula in exactly
 the same way as ‘j s’, except that the selection will last only as long
 as the next command that uses it.  For example, ‘j o 1 +’ is a handy way
 to add one to the sub-formula indicated by the cursor.
 
    (A somewhat more precise definition: The ‘j o’ command sets a flag
 such that the next command involving selected stack entries will clear
 the selections on those stack entries afterwards.  All other selection
 commands except ‘j a’ and ‘j O’ clear this flag.)
 
    The ‘j S’ (‘calc-select-here-maybe’) and ‘j O’
 (‘calc-select-once-maybe’) commands are equivalent to ‘j s’ and ‘j o’,
 respectively, except that if the formula already has a selection they
 have no effect.  This is analogous to the behavior of some commands such
 Rules::) and is mainly intended to be used in keyboard macros that
 implement your own selection-oriented commands.
 
    Selection of sub-formulas normally treats associative terms like ‘a +
 b - c + d’ and ‘x * y * z’ as single levels of the formula.  If you
 place the cursor anywhere inside ‘a + b - c + d’ except on one of the
 variable names and use ‘j s’, you will select the entire four-term sum.
 
    The ‘j b’ (‘calc-break-selections’) command controls a mode in which
 the “deep structure” of these associative formulas shows through.  Calc
 actually stores the above formulas as ‘((a + b) - c) + d’ and ‘x * (y *
 z)’.  (Note that for certain obscure reasons, by default Calc treats
 multiplication as right-associative.)  Once you have enabled ‘j b’ mode,
 selecting with the cursor on the ‘-’ sign would only select the ‘a + b -
 c’ portion, which makes sense when the deep structure of the sum is
 considered.  There is no way to select the ‘b - c + d’ portion; although
 this might initially look like just as legitimate a sub-formula as ‘a +
 b - c’, the deep structure shows that it isn’t.  The ‘d U’ command can
 be used to view the deep structure of any formula (SeeNormal Language
 Modes).
 
    When ‘j b’ mode has not been enabled, the deep structure is generally
 hidden by the selection commands—what you see is what you get.
 
    The ‘j u’ (‘calc-unselect’) command unselects the formula that the
 cursor is on.  If there was no selection in the formula, this command
 has no effect.  With a numeric prefix argument, it unselects the Nth
 stack element rather than using the cursor position.
 
    The ‘j c’ (‘calc-clear-selections’) command unselects all stack
 elements.