Re: Selecting a portion of text in editor pane

Martin Simmons <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
You need to use capi:call-editor to make editor operations update the pane
correctly.  It is documented as taking a string naming an editor command, but
you can also give it a function of one argument (which is always nil).

E.g.

(capi:apply-in-pane-process 
 editor
 'capi:call-editor
 editor
 (lambda (arg)
   (declare (ignore arg))
   (editor:use-buffer (capi:editor-pane-buffer editor)
     (editor:forward-character-command 1))))

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/



>>>>> On Wed, 24 Sep 2025 04:53:51 +0000, Krupka Michal (as michal dot krupka at upol dot cz) said:
> 
> The Editor just doesn't behave as I would expect if used this way. For example, suppose I want to move the cursor by one character:
> 
> (setf editor (capi:contain (make-instance 'capi:editor-pane :text "Text")))
> 
> (capi:apply-in-pane-process 
>  editor
>  (lambda ()
>    (editor:use-buffer (capi:editor-pane-buffer editor)
>      (editor:forward-character-command 1))))
> 
> After this, the cursor does not move and stays at the beginning of the text. What should I do to make this example work?
> 
> Michal
> 
> 
> > 22. 9. 2025 v 22:52, Martin Půda (as mapuda at seznam dot cz) <[email protected]>:
> > 
> > Got it, I was able to reproduce that behaviour. Anyway, those are just some dummy points for testing, the important part is (setf (editor:variable-value "Highlight Active Region" :buffer (capi:editor-pane-buffer my-editor)) t), so selected text is highlighted and reachable via capi:editor-pane-selected-text. Replace select-some-text with this:
> > 
> > (defun select-some-text (editor-pane)
> >   (capi:apply-in-pane-process 
> >    editor-pane
> >    (lambda ()
> >      (let* ((buffer (capi:editor-pane-buffer editor-pane))
> >             (buffer-point (editor:buffer-point buffer))
> >             (start (editor:buffers-start buffer))
> >             (start-point (editor:copy-point start :temporary))
> >             (end-point (editor:copy-point start :temporary)))
> > 
> >        (editor:line-offset start-point 1 5)
> >        (editor:line-offset end-point 2 3)
> >                 (editor:move-point buffer-point start-point)
> >        (editor:set-current-mark end-point)
> > 
> >        (print (capi:editor-pane-selected-text editor-pane))))))
> > 
> > But I noticed this: after calling select-some-text and pressing Delete, actual deleted area was between end-point and cursor... so maybe you will have to overwrite input-model for Delete to something like (editor:use-buffer buffer
> >        (editor:delete-region-command nil)).
> > 
> > ---------- Původní e-mail ----------
> > Od: Krupka Michal (as michal dot krupka at upol dot cz) <[email protected]>
> > Komu: Martin Půda <[email protected]>
> > Kopie: [email protected] <[email protected]>
> > Datum: 22. 9. 2025 19:44:53
> > Předmět: Re: Selecting a portion of text in editor pane
> > Well, if I break the test to parts like this: 
> > 
> > (setf my-editor (make-instance 'capi:editor-pane 
> > :text "This is the first line of text. 
> > This is the second line. 
> > And here is the third line. 
> > Finally, the fourth line of text." 
> > :visible-min-height 150 
> > :visible-min-width 400)) 
> > 
> > (capi:contain my-editor) 
> > 
> > (progn 
> > (setf (editor:variable-value "Highlight Active Region" :buffer (capi:editor-pane-buffer my-editor)) t) 
> > (select-some-text my-editor)) 
> > 
> > then the last form doesn't always work for me. Just try to click to several places of text or select some parts of it and then evaluate the last form. 
> > 
> > Michal 
> > 
> > > 22. 9. 2025 v 10:37, Martin Půda (as mapuda at seznam dot cz) <[email protected]>: 
> > > 
> > > Something like this? 
> > > 
> > > (defun select-some-text (editor-pane) 
> > > (capi:apply-in-pane-process 
> > > editor-pane 
> > > (lambda () 
> > > (let* ((buffer (capi:editor-pane-buffer editor-pane)) 
> > > (buffer-point (editor:buffer-point buffer)) 
> > > (start-point (editor:copy-point buffer-point :temporary)) 
> > > (end-point (editor:copy-point buffer-point :temporary))) 
> > > 
> > > (editor:line-offset start-point 1 5) 
> > > (editor:line-offset end-point 2 3) 
> > > (editor:move-point buffer-point start-point) 
> > > (editor:set-current-mark end-point) 
> > > 
> > > (print (capi:editor-pane-selected-text editor-pane)))))) 
> > > 
> > > (let ((my-editor (make-instance 'capi:editor-pane 
> > > :text "This is the first line of text. 
> > > This is the second line. 
> > > And here is the third line. 
> > > Finally, the fourth line of text." 
> > > :visible-min-height 150 
> > > :visible-min-width 400))) 
> > > (capi:contain my-editor) 
> > > (setf (editor:variable-value "Highlight Active Region" :buffer (capi:editor-pane-buffer my-editor)) t) 
> > > (select-some-text my-editor)) 
> > > 
> > > 
> > > ---------- Původní e-mail ---------- 
> > > Od: Krupka Michal (as michal dot krupka at upol dot cz) <[email protected]> 
> > > Komu: Lisp Hug Lispworks <[email protected]> 
> > > Datum: 21. 9. 2025 22:19:47 
> > > Předmět: Selecting a portion of text in editor pane 
> > > Hello, 
> > > 
> > > I need to select a part of text in capi:editor-pane given two buffer points. I tried this (inside a correct process) but it doesn't work correctly: 
> > > 
> > > (editor:use-buffer (capi:editor-pane-buffer my-pane) 
> > > (editor:move-point (editor:current-point) point-1) 
> > > (editor:set-current-mark point-2)) 
> > > 
> > > Any advice? Thanks. 
> > > 
> > > Michal 
> > > 
> > > _______________________________________________ 
> > > Lisp Hug - the mailing list for LispWorks users 
> > > [email protected] 
> > > http://www.lispworks.com/support/lisp-hug.html 
> > 
> > 
> > _______________________________________________ 
> > Lisp Hug - the mailing list for LispWorks users 
> > [email protected] 
> > http://www.lispworks.com/support/lisp-hug.html
> 
> 
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> [email protected]
> http://www.lispworks.com/support/lisp-hug.html
> 

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.