How to add a temporary blank line at the end of buffer safely

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add a temporary blank line at the end of buffer safely

tumashu
-----------------------------------------------------------------------
> Date: Mon, 11 Dec 2017 16:29:16 +0800 (CST)
> From: tumashu  <address@hidden>
> Cc: "address@hidden" <address@hidden>
> 
> by the way, does emacs has a function, which can get the point's left-bottom 
> pixel position,  if not,
> is it possible to add it to emacs?

Doesn't vertical-motion fit the bill?  If not, why not?
------------------------------------------------------------------------
@Eli Zaretskii Thanks for your suggestion, it works very well,  the only problem is that
it can not work when point at the end line of buffer, I use the below code to handle this problem,
(add a temp "\n" then remove) but it seem to hacky.  any good way to solve this problem:

  (if (= (line-end-position) (point-max))
      (let (posn)
        (goto-char (point-max))
        (insert "\n")
        (setq posn (posn-at-point (point) window))
        (delete-char -1)
        posn)
    (vertical-motion 1)
    (posn-at-point (point) window))


Reply | Threaded
Open this post in threaded view
|

Re: How to add a temporary blank line at the end of buffer safely

Eli Zaretskii
> Date: Thu, 11 Jan 2018 16:45:43 +0800 (CST)
> From: tumashu <[hidden email]>
>
> Doesn't vertical-motion fit the bill?  If not, why not?
> ------------------------------------------------------------------------
> @Eli Zaretskii Thanks for your suggestion, it works very well,  the only problem is that
> it can not work when point at the end line of buffer, I use the below code to handle this problem,
> (add a temp "\n" then remove) but it seem to hacky.  any good way to solve this problem:

Something like the below, perhaps?

  (aref (font-info (font-at POS)) 3)

This will give you the height of the font used at position POS.  Then
you could add that to the y-coordinate of the line at EOB, to get the
bottom y-coordinate of that line.  (Caveat: font-at doesn't like to be
called at EOB, so make sure you are one buffer position before that.)

Reply | Threaded
Open this post in threaded view
|

Re:Re: How to add a temporary blank line at the end of buffer safely

tumashu
It works, thanks very much.

At 2018-01-12 00:03:51, "Eli Zaretskii" <[hidden email]> wrote: >> Date: Thu, 11 Jan 2018 16:45:43 +0800 (CST) >> From: tumashu <[hidden email]> >> >> Doesn't vertical-motion fit the bill? If not, why not? >> ------------------------------------------------------------------------ >> @Eli Zaretskii Thanks for your suggestion, it works very well, the only problem is that >> it can not work when point at the end line of buffer, I use the below code to handle this problem, >> (add a temp "\n" then remove) but it seem to hacky. any good way to solve this problem: > >Something like the below, perhaps? > > (aref (font-info (font-at POS)) 3) > >This will give you the height of the font used at position POS. Then >you could add that to the y-coordinate of the line at EOB, to get the >bottom y-coordinate of that line. (Caveat: font-at doesn't like to be >called at EOB, so make sure you are one buffer position before that.)