text-pane control

Started by Dmi, October 28, 2007, 03:27:58 PM

Previous topic - Next topic

Dmi

Hello, guys!



Recently I have a look into newlisp-edit.



I'd like to improve some things (such as completion and indenting) from my nlc project.



But I didn't found some control tricks. Point me please...



Can I set thee position of the caret for the text area (for example, after set-text)?



I can get event for any regular character typed, but can I prevent it from appearing in the text area?
WBR, Dmi

Lutz

#1
QuoteCan I set thee position of the caret for the text area (for example, after set-text)?


yes, use gs:select-text with-out the last parameter


Quotebut can I prevent it from appearing in the text area?


no, no direct way of doing this, you could roll your own text control drawing characters on a canvas and using gs:key-event to get key strokes.



Lutz

Dmi

#2
Thanks, Lutz!



Another questions:



As I can understand, editarea in newlisp-ediit is tabbed. But



1. editarea-hendler doesn't receive the index of the tab (for set-text)

2. select-text doesn't have a syntax to specify the index of the tab.



Does this matters?



...now I got errors like
missing parenthesis : "...))n                                 "
called from user defined function gs:check-event

Frequently (not each time) after editarea is modified within editarea-handler.
WBR, Dmi

Lutz

#3
Quote1. editarea-hendler doesn't receive the index of the tab (for set-text)

2. select-text doesn't have a syntax to specify the index of the tab.


but it receives the id of the gs:text-pane. The id for the gs:text-pane is created here:


(define (open-currentpath-in-tab)
(set 'currentDir (join (chop (parse currentPath {\|/} 0)) "/" ))
(set 'currentFile (last (parse currentPath {\|/} 0)))
(set 'currentEdit (make-editor-tab currentDir currentFile))
(set 'edit-buffer-clean true)
(set 'currentDot 0 'currentMark 0)
(gs:insert-tab 'EditorTabs currentEdit currentFile (length tabs-stack))
(gs:request-focus 'EditorTabs (length tabs-stack))
(gs:request-focus currentEdit) ; set focus in edit area
(gs:set-cursor currentEdit "wait")

(gs:set-text 'TheEditor (string "newLISP edit - " currentPath))
(gs:enable 'FileSaveAs)

(gs:load-text currentEdit currentPath)
(set 'currentSyntaxStatus (current-file-syntax))
(theme-handler (string "ViewTheme" currentThemeIdx))
(gs:set-cursor currentEdit "default")
)


the id is stored in the global variable 'currentEdit'. Whenever a different tab is clicked the following function gets fired:


(define (editortabs-handler id tab title idx)
(update-current-tab)
(set 'currentTabIndex idx)
; get new tab edit area settings
(set 'currentEdit tab)
(switch-to-tab tab idx)
)


... switches 'currentEdit' to the changed gs:text-pane id. 'editortabs-handler' is the handler for the 'gs:tabbed-pane'. So 'gs:select-text' always uses the id of the 'gs:text-pane', which it gets from 'currentEdit'.


missing parenthesis : "...))n                                 "
called from user defined function gs:check-event


a changed eventhandler code misses a parenthesis. To make debugging life easier you could put


(println event)

inside the definition of 'gs:check-event' in guiserver.lsp (around line 812). The first element in the event is the name of the handler, followed by all the parameters.



Lutz

Dmi

#4
Lutz, I done some work for the indent.

This is the modified editarea-handler:
       (if     (= code 10)
                (let (p (gs:get-text-position id)
                     (b (INDENT:indent (parse (gs:get-text id) "n"))))
                  (gs:set-text id (join b "n"))
                  (let (l (+ 1 (length (join (0 (- (p 0) 1) b) "n")))
                        r (regex "^ *" (b (p 0))))
                    (if r (set 'l (+ l (r 2))))
                    (gs:select-text id l l)
                    (gs:set-syntax currentEdit currentSyntaxStatus)))
                (= code 65535) ; crtl or meta keys wit or w/o shift

the first and last strings are from original code, the middle part is new.

You must preload indent.lsp from http://en.feautec.pp.ru/store/indent.lsp">http://en.feautec.pp.ru/store/indent.lsp



For me this seems to be working, except that I modify my gs:check-event's line from

(eval-string event)

to

(eval-string (string event))

without that I got  a really underground knock-knock effect :-)
WBR, Dmi

Lutz

#5
Nice, perhaps you can post a complete modified newlisp-edit.lsp on http://en.feautec.pp.ru">http://en.feautec.pp.ru ?



If there is a need to modify guiserver.lsp routines, you always can have your own definitions in your program file after loading guiserver.lsp and before using the function.



Lutz

Dmi

#6
http://en.feautec.pp.ru/store/newlisp-edit">//http://en.feautec.pp.ru/store/newlisp-edit - the modified version with the auto-indenting.



It loads two libs via http from en.feautec.pp.ru - if someone is disagree, it may download them locally and to modify the script.



If the program will fail while typing with "missing parenthesis " error, let me know.



(edited: corrected url for newlisp-edit)
WBR, Dmi