Lisp HUG Maillist Archive

Scrolling editor panes programmatically

I have a CAPI application which has a couple of editor panes with
scrollbars. I want to programmatically scroll the panes to a certain
position (based on the contents of the panes) even if the panes don't
have the focus.

I want to avoid using the SCROLL function directly because in that
case I'd have to compute the amount of scrolling based on the contents
of the editor pane (including font size, line breaks, all that stuff)
so I thought I'd use the editor's "Refresh Screen" command.

My idea was to do it like this, more or less:

  (defun foo (pane)
    (let ((buffer (capi:editor-pane-buffer pane)))
      (editor::buffer-save-excursion (buffer)
        (editor:with-point ((point (editor:current-point)))
          (editor:move-point point
                             (compute-point-where-i-want-to-go))
          (editor:refresh-screen-command)))))

But that doesn't work. Then I looked at the editor's source code and
found out that the definition of "Refresh Screen" is rather short. It
just calls MOVE-LINE-TO-POSITION (which isn't defined in the
sources). So, OK, could I call it directly? I need a "window" for
that, how do I get it? I tried something like this but that also
didn't work:

  (car (editor:buffer-windows buffer))

So, hmm, what's the best way to accomplish this? Can I use "Refresh
Screen" but I'm just too dumb to find out how? Or is there a function
which maps the positon of the current point to its corresponding
scroll position? Anything else that I'm missing?

Thanks,
Edi.


Re: Scrolling editor panes programmatically

Unable to parse email body. Email id is 1773

Re: Scrolling editor panes programmatically

On Tue, 13 Jan 2004 14:23:53 GMT, davef@xanalys.com wrote:

> 1. move the point so it's visible on the screen. This code does that:
>
> (defun compute-point-where-i-want-to-go (buffer)
>   (editor:with-point ((tpoint (editor:buffer-point buffer)))
>     (editor:move-point tpoint (editor:buffers-start buffer))
>     (editor:line-offset tpoint (print (random 20)))
>     (editor:copy-point tpoint)))
>
> (defun foo (interface)
>   (let ((pane (edi-editor interface)))
>     (capi:call-editor pane (list 'foo2 pane))))
>
> (defun foo2 (pane)
>   (let ((buffer (capi:editor-pane-buffer pane))
>         (window (capi:editor-window pane)))
>       (editor::move-line-to-position window (compute-point-where-i-want-to-go buffer) nil)
>       (editor::update-window-after-scroll window nil)))
>       
> (capi:define-interface edi ()
>   ()
>   (:panes 
>    (editor
>     capi:editor-pane
>     :text (apply 'concatenate 'string 
>                  (loop for i below 20 collect (format nil "Line~D~%" i)))
>     :vertical-scroll t
>     :reader edi-editor)
>    (another-pane
>     capi:editor-pane
>     :text "Just somewhere to put the input focus"))
>   (:menus
>    (scroll-menu
>     "Scroll"
>     (("Scroll Random" :selection-callback 'foo :callback-type :interface))))
>   (:menu-bar scroll-menu))
>
>
> (capi:display (make-instance 'edi))

Thanks! That was exactly what I needed!

Edi.


Updated at: 2020-12-10 08:58 UTC