help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what is the point of point-min?


From: Rob Thorpe
Subject: Re: what is the point of point-min?
Date: 29 Aug 2003 05:44:00 -0700

Jesper Harder <address@hidden> wrote in message news:<address@hidden>...
> Barry Margolin <address@hidden> writes:
> 
> > Jesper Harder  <address@hidden> wrote:
> >
> >>Is this the way they work:
> >>
> >>(defun region-beginning ()
> >>  (min (point) (mark)))
> >>
> >>(defun region-end ()
> >>  (max (point) (mark)))
> >
> > Use the Source, Luke.
> 
> If they were Lisp functions I would have just read the source.  But
> 
> * I hate reading C.
> 
> * It's much more cumbersome to find the function definition for
>   built-in functions, i.e. there's no handy hyperlink to the source
>   when doing `C-h f' like there is for Lisp functions.
> 
> >>or are there other instances where `region-beginning' is different
> >>from `point'?
> >
> > Even if there aren't now, you should allow for the possibility in the
> > future.
> 
> Yes, in newly written code.  But it might not be worthwhile to change
> stable (currently feature-freezed) code with the possibility of
> introducing bugs if there's no difference between (region-end) and
> (max (point) (mark)).

I don't know what this moaning about reading emacs source is about,
its not easy, but its not exactly brain surgery.  The behaviour of
region-beginning is subtly different from point.  Firstly as previous
posters have mentioned it will swap the two around to put them in the
right order.  Secondly it will obey the value of the variable
transient-mark-mode, if it is set to non-nil then the mark will
deactivate when the buffer contents change.
Given the function you have posted:

(global-set-key [delete] 
  (lambda () (interactive) 
     (if mark-active
               (kill-region (point) (mark)) 
       (delete-char 1))))

This version in transient mark mode will delete the region even though
in this mode it is not thought of as existing after a character is
inserted into the buffer.

>From editfns.c:-

/* Return the start or end position of the region.
   BEGINNINGP non-zero means return the start.
   If there is no region active, signal an error. */

static Lisp_Object
region_limit (beginningp)
     int beginningp;
{
  extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c.
*/
  Lisp_Object m;
  
  if (!NILP (Vtransient_mark_mode)
      && NILP (Vmark_even_if_inactive)
      && NILP (current_buffer->mark_active))
    Fsignal (Qmark_inactive, Qnil);
  
  m = Fmarker_position (current_buffer->mark);
  if (NILP (m))
    error ("There is no region now");
  
  if ((PT < XFASTINT (m)) == beginningp)
    m = make_number (PT);
  return m;
}

DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0,
0,
  "Return position of beginning of region, as an integer.")
  ()
{
  return region_limit (1);
}

DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0,
  "Return position of end of region, as an integer.")
  ()
{
  return region_limit (0);
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]