Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] is a R2/View Editor hook available ?

From: gerardcote::gmail::com at: 20-Aug-2009 17:20

Hi, While I looke at the source of the R2/View editor, I found there was a ctx-edit/view-file launched somewhere. Looking further to see if I could get a hook to include some enhancements, I never found a way to do that. May be there exists but I can't get further. Some help or explanation is needed. However I would like to share with other newcomers how I got more details about the way I found the internal workings of the editor, even if I stalled at a level that is not too deep ... From the REBOL documentation I found that with a combination of simple instructions I could get the details of the ctx-edit objectand its view-file function (or method). See the code below : I tried to keep the comments to a minimum that is nevertheless useful. Sorry for the lengthy process - Any suggestion to not overbook the ML is welcome We need a single place to share our experiments and quickly find what others did in the past. The and the ML seem the better place to me - Am I right to think so ? Eventually more and more places open and it becomes hard to gather all this useful information May be only pointers are required for follow-ups. ;===================================================================== ; Small tests to see how the Rebol/View embedded editor is functioning ;=====================================================================
>> source editor
editor: func [file /app app-word /local tmp][ either link? [ if block? ctx-edit [ ctx-edit: context either all [ value? 'fileset-files? tmp: fileset-files? 'desktop find tmp %desktop/edit.r tmp: load/header link-root/desktop/edit.r ] [next tmp] [ctx-edit] ] either app [ctx-edit/view-file/app file app-word] [ctx-edit/view-file file] ] [ either exists? tmp: view-root/desktop/scripts/edit.r [do/args tmp file] [ if block? ctx-edit [ctx-edit: context ctx-edit] ctx-edit/view-file file ] ] ] ;================================================================================ ; The I tried to isolate the part that was really running when started. ; Here is how I proceeded - manually tracing by inserting some instructions ; for printing, pausing and stopping. ;================================================================================ old-editor: :editor ;<--- First get a safe copy of the editor: func [file /app app-word /local tmp][ ; original editor source content either link? [ ; then adapt my own copy of the editor if block? ctx-edit [ ; code before launching more tests ctx-edit: context either all [ value? 'fileset-files? tmp: fileset-files? 'desktop find tmp %desktop/edit.r tmp: load/header link-root/desktop/edit.r ] [print "MK-1" next tmp ] [print "MK-2" ctx-edit] ; <--- some prints inserted here and there ] either app [print "MK-3" ctx-edit/view-file/app file app-word] [print "MK-4" ctx-edit/view-file file] ] [ either exists? tmp: view-root/desktop/scripts/edit.r [print "MK-5" do/args tmp file] [ if block? ctx-edit [print "MK-6" ctx-edit: context ctx-edit] print "MK-7" probe ctx-edit ; <--- tried some more experiments below to discover that it is ask "Suite ?" ; the last line that really executes in my situation ! print "OK" ; Before finding this, I had a good time trying to see ctx-edit/view-file "" ; where do come from the link-root/desktop/... halt ; finally I had to suggest myself that this situation ctx-edit/view-file ; is probably taken into account when the editor is running ] ; from a connected mode (but can't say more) ] ]
>> editor: :old-editor ; <-- After my
exploration, better be doing the garbage collection
>> ctx-edit/view-file "" ; <-- manual launch of the editor to see
if it is similar to a normal ; start-up of the editor when the >> editor "" command is used.
>> type? ctx-edit ; <-- test the nature of this ctx-edit
(normally ctx- is used to mean a context == object! ; and this done with an object.
>> probe first ctx-edit
[self prefs dirty-edit this-file this-app t1 s1 h1 f1 edit-prefs ed-lo save-lo ff fb fc fp find-lo resize refresh save-prefs open-as new-file save-as save-file up-file open-file result ask-save save-edit do-file quit-edit quit-now caret start last-str last-case last-pat find-text search find-str find-again find-next find' scroll-to show-help help-text keymap scroll-edit init form-title view-file] ;================================================================================ ; As a personal test, I tried to find every word beginning with the letter k ; got some problems since "k" is diff from a char ; finally I found a way to do it - maybe better or shorter ways exist. ;===========================================================================
>> foreach item first ctx-edit [if (to-char "k") == to-char first to-string
item [probe item]] keymap ;================================================================================ ; May be I could edit this table - but I don't know what to do when the key is detected :( ;===========================================================================
>> probe ctx-edit/keymap
[ #"^S" [save-file] #"^W" [quit-edit] #"^Q" [quit-edit] #"^O" [open-as] #"^N" [new-file] #"^E" [do-file] #"^F" [find-text] #"^G" [find-again] F3 [find-text] F5 [do-file] page-up [scroll-edit true -1] page-down [scroll-edit true 1] ] ;=============================== ; Let's explore further ... ;==========================
>> probe ctx-edit/view-file ; <--- Oups!
view-file seems to be evaluated. ** Script Error: view-file is missing its file argument ; Let's see if it is a function ? ** Where: halt-view ** Near: probe ctx-edit/view-file
>> type? get in ctx-edit 'view-file ; <--- Yes it
really is a function waiting == function! ; for a file parameter.
>> probe get in ctx-edit 'view-file ; <--- Get the
contents in a safe way! func [file /app app-word][ ; similar to using the 'source function if not save-edit [exit] if app [this-app: app-word] t1/text: none t1/line-list: none if not viewed? ed-lo [ if exists? prefs [edit-prefs: make edit-prefs load/all prefs] t1/para/wrap?: edit-prefs/wrap ed-lo/offset: edit-prefs/offset if outside? system/view/screen-face/size ed-lo/offset + 20x20 [ ed-lo/offset: 40x40 save-prefs ] resize edit-prefs/size ed-lo/text: form-title file view/new/options ed-lo [resize] init center-face/with find-lo ed-lo if not overlap? find-lo system/view/screen-face [find-lo/offset: ed-lo/offset + 20] ] open-file file if 1 = length? system/view/screen-face/pane [do-events] ] ;======================================================================================= ; Also looked under the edit-prefs and the associated file containing ; the user-prefs but nothing useful was found there. ; May be the ed-lo or some other part of the ctx-edit object ; contains the required code to modify but I am no more able to do this and go further ;======================================================================================= ;======================================================================================= ; Below is a snippet taken from the REBOL web site ; This is how we can redirect the output of some mezzanine function to another destination ; Here the new print-str function is a modified copy of the old 'print source code ;======================================================================================= output: make string! 1000 print-str: func third :print [ repend output [reform :value newline] ] ; End of the current exploration -- Gérard Côté Québec, Canada