Author Topic: Need a new buffer opened - call macro example  (Read 131 times)

TKasparek

  • Senior Community Member
  • Posts: 219
  • Hero Points: 27
Need a new buffer opened - call macro example
« on: November 27, 2019, 08:14:51 pm »
Can someone point me to an example or explain how I can have a macro called when a new buffer is opened? I have a macro that requires setup for each buffer and located in the per-buffer data area using _GetBufferInfoHtPtr. I have a fast macro that needs to be called that validates a buffer is of a certain type and installs the correct settings via  _SetBufferInfoHt(). The problem that is currently I need to do the setup/SetBuffer.. step manually. I would like this to be done automatically (as well as automatically update menu item settings for it). But I need a system callback that will call my setup macro first. Any thoughts?

Graeme

  • Senior Community Member
  • Posts: 2385
  • Hero Points: 314
Re: Need a new buffer opened - call macro example
« Reply #1 on: November 28, 2019, 10:37:04 am »
Search slick macro sources for call_list - you get the results below.  call_list calls all of the functions whose name starts with the specified prefix.  So
call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
calls all the functions whose name starts with _buffer_add_
So if you search slick sources for _buffer_add_ you'll find this - among other things
void _buffer_add_tabs(int newbuffid, _str name, int flags = 0);
All the _buffer_add_ functions get called when a new buffer is opened.

There's also _switchbuf_  - functions that get called when you switch to a different buffer.
You can iterate through open buffers using the for_each_buffer function.

How did you find out about  _SetBufferInfoHt() ?

Code: [Select]
Find all "CALL_LIST", Whole word, "C:\Program Files\SlickEdit Pro 23.0.2\macros", "*.e;*.sh"
File C:\Program Files\SlickEdit Pro 23.0.2\macros\applet.e
  1307 4:   call_list("_prjupdate_");
File C:\Program Files\SlickEdit Pro 23.0.2\macros\b2k.e
  651 4:   call_list('_eventtab_modify_',keytab_used,event);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\beautifier.e
  1295 4:   call_list('_hformatSaveScheme_',langid,LanguageSettings.getBeautifierProfileName(langid));
File C:\Program Files\SlickEdit Pro 23.0.2\macros\bind.e
  619 8:       call_list('_eventtab_modify_',keytab_used,index2event(keyindex));
  645 6:     call_list('_eventtab_modify_',keytab_used,event2index(k));
  714 4:   call_list('_eventtab_modify_',keytab_used,event2index(k));
File C:\Program Files\SlickEdit Pro 23.0.2\macros\cbrowser.e
  1205 4:   call_list("_on_popup2_",translate("_cbrowse_menu","_","-"),menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\ccode.e
  442 7:      call_list('_lexer_updated_', lexername);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\compile.e
  6480 4:   call_list("_postbuild_", args);
  6551 4:   call_list("_prebuild_", arg(1));
File C:\Program Files\SlickEdit Pro 23.0.2\macros\context.e
  199 7:      call_list("_LoadBackgroundTaggingSettings");
  520 10:         call_list("-before-context-combo-select-",p_window_id);
  523 10:         call_list("-after-context-combo-select-",p_window_id);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\diffedit.e
  656 4:   call_list('_diffOnStart_');
  991 4:   call_list('_diffOnExit_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\diffmf.e
  1947 7:      call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1948 7:      call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\dir.e
  738 10:         call_list('_cd_',getcwd());
File C:\Program Files\SlickEdit Pro 23.0.2\macros\dirlist.e
  178 16:               call_list("_cd_",new_path);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\dlgeditv.e
  1596 7:      call_list('_on_popup2_',translate(name_name(index),'_','-'),menu_handle);
  1598 10:         call_list('_on_popup_',translate(name_name(index),'_','-'),menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\eclipse.e
  525 6://   call_list('_cbsave_');
  1252 13:            call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1253 13:            call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1284 4:   call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1285 4:   call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\emulate.e
  275 4:   call_list('_eventtab_modify_',defeventtab default_keys,'');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\fileproject.e
  152 9:      //call_list('_prjconfig_');  // Active config changed
  192 7:      call_list('_prjopen_',true);
  201 9:      //call_list('_prjconfig_');  // Active config changed. I don't think we need this.
  459 4:   call_list('_prjconfig_');  // Active config changed
File C:\Program Files\SlickEdit Pro 23.0.2\macros\files.e
  114 35:// together calls to handlers for call_list callbacks.
  591 16:               call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  592 16:               call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  595 19:                  call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  596 19:                  call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1016 7:      call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1017 7:      call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1053 10:         call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1054 10:         call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  1209 12:         //call_list('_buffer_renamed_',p_buf_id,p_buf_name,old_buf_name,old_buf_flags);
  2311 4:   call_list('_document_renamed_',p_buf_id,p_DocumentName,newDocumentName,p_buf_flags);
  2314 4:   call_list('_document_renamedAfter_',p_buf_id,oldDocumentName,newDocumentName,p_buf_flags);
  2694 10:         call_list('_cd_',getcwd());
  2772 6:void call_list(_str prefix_name, ...)
  2774 11:   //say("call_list H"__LINE__": prefix="prefix_name);
  2911 4:   call_list('_actapp_', gettingFocus);
  3080 7:      call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  3081 7:      call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  5363 9: * @see call_list
File C:\Program Files\SlickEdit Pro 23.0.2\macros\ftpclien.e
  1258 7:      call_list('_ftpCwdHistoryAddRemove_',formWid);
  1524 7:      call_list('_ftpProfileAddRemove_',formWid);
  1669 7:      call_list('_ftpProfileAddRemove_',formWid);
  1895 7:      call_list('_ftpQIdle_');
  1911 31:      if( _ftpQ._length()<1 ) call_list('_ftpQIdle_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\ftpopen.e
  875 7:      call_list('_ftpCwdHistoryAddRemove_',formWid);
  1092 7:      call_list('_ftpProfileAddRemove_',formWid);
  1245 7:      call_list('_ftpProfileAddRemove_',formWid);
  1536 7:      call_list('_ftpQIdle_');
  1551 31:      if( _ftpQ._length()<1 ) call_list('_ftpQIdle_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\ftpq.e
  93 7:      call_list('_ftpQIdle_');
  264 4:   call_list('_ftpQBusy_');
  355 4:   call_list('_ftpQBusy_');
  5182 10:         call_list('_ftpQIdle_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\ini.e
  86 7:      call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  87 7:      call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  96 10:         call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  97 10:         call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  134 4:   call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  135 4:   call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\keybindings.e
  661 6:   //call_list('_eventtab_modify_', keyTableIndex, key);
  729 9:      //call_list('_eventtab_modify_', keyTableIndex, key);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\last.e
  472 13:            call_list('_cbquit_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\main.e
  2036 7:      call_list('_eventtab_modify_',kt_index,'');
  2549 4:   call_list("dllinit_");
  2772 12:           call_list('_prjopen_',false);
  2775 12:           call_list('_workspace_opened_');
  2876 6:     call_list('_prjopen_',false);
  2879 6:     call_list('_workspace_opened_');
  3470 7:      call_list('_eventtab_modify_',_default_keys,'');
  3644 4:   call_list('_eventtab_modify_',_default_keys,'');
  4491 4:   call_list('_eventtab_modify_',defeventtab default_keys,'');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\maketags.e
  281 7:      call_list("_LoadBackgroundTaggingSettings");
File C:\Program Files\SlickEdit Pro 23.0.2\macros\menu.e
  129 4:   call_list("_MenuAddFileHist_",filename);
  182 4:   call_list("_MenuRemoveFileHist_", filename);
  527 16:               call_list("_MenuRemoveFileHist_", tfilename);
  1447 4:   call_list('-init-menu-',menu_handle,no_child_windows);
  2311 6:   //call_list("_MenuAddFileHist_",filename);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\mouse.e
  3042 4:   call_list('_on_popup2_',translate(menu_name,'_','-'),menu_handle);
  3044 7:      call_list('_on_popup_',translate(menu_name,'_','-'),menu_handle);
  3351 4:   call_list('_on_popup2_',translate(menu_name,'_','-'),menu_handle,true);
  3353 7:      call_list('_on_popup_',translate(menu_name,'_','-'),menu_handle,true);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\optionsxml.e
  6562 7:      call_list('_cbafter_import_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\os2cmds.e
  366 4:   call_list("_cbstop_process_");
  692 13:            call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  693 13:            call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  808 7:      call_list('_internal_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  809 7:      call_list('_buffer_add_',p_buf_id,p_buf_name,p_buf_flags);
  942 7:      call_list('_cd_',param);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\phpopts.e
  2803 4:   call_list('_prjupdate_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\picture.e
  754 10:         call_list('_on_popup2_',translate(menu_name,'_','-'),menu_handle);
  756 13:            call_list('_on_popup_',translate(menu_name,'_','-'),menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\proctree.e
  1944 4:   call_list("_on_popup2_",translate("_tagbookmark_menu","_","-"),menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\projconv.e
  3945 7:      call_list('_prjupdate_');
  4250 4:   call_list('_prjconfig_');  // Active config changed
File C:\Program Files\SlickEdit Pro 23.0.2\macros\project.e
  3842 4:   call_list("_prjedit_", gProjectHandle);
  7186 22:         p_window_id.call_list("_prjupdatedirs_");
  7199 19:      p_window_id.call_list("_prjupdate_");
  8017 7:      call_list("_LoadBackgroundTaggingSettings");
  9584 4:   call_list("_workspace_file_add", ProjectName, newfilename);
  9585 18:   //p_window_id.call_list("_prjupdate_");
File C:\Program Files\SlickEdit Pro 23.0.2\macros\projgui.e
  269 25:            p_window_id.call_list("_prjupdatedirs_");
  273 25:            p_window_id.call_list("_prjupdate_");
File C:\Program Files\SlickEdit Pro 23.0.2\macros\ptoolbar.e
  1909 7:      call_list("_prjupdate_");
  2091 4:   call_list("_prjupdate_");
  2418 7:      call_list("_LoadBackgroundTaggingSettings");
  2925 10:         call_list("_prjupdate_");
  3277 49:   _str menu_name = name;  // Need this for the call_list later
  3445 4:   call_list('_on_popup_', translate(menu_name, '_', '-'), menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\restore.e
  619 59:            // Don't have to call cd here, but we must do call_list
  1448 7:      call_list('_srgmon_');//, '', '', '', relativeToDir);
  1451 4:   call_list('_srmon_'); //, '', '', '', relativeToDir);
  1638 7:      call_list('_srg_');
  1791 4:   call_list('_sr_', '', '', '', relativeToDir);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\saveload.e
  74 7:      call_list('_cbsave_');
  97 4:   call_list('_cbquit_',p_buf_id,p_buf_name,p_DocumentName,p_buf_flags);
  105 3:  call_list('_cbquit2_',buf_id,buf_name,doc_name,buf_flags);
  137 4:   call_list('_buffer_renamed_',p_buf_id,p_buf_name,new_name,p_buf_flags);
  146 4:   call_list('_buffer_renamedAfter_',p_buf_id,oldBufName,new_name,p_buf_flags);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\sftpclien.e
  133 7:      call_list('_ftpProfileAddRemove_',formWid);
  353 7:      call_list('_ftpCwdHistoryAddRemove_',formWid);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\sftpopen.e
  227 7:      call_list('_ftpCwdHistoryAddRemove_',formWid);
  647 7:      call_list('_ftpProfileAddRemove_',formWid);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\slickc.e
  2014 4:   call_list("_before_write_state_");
  2432 6:   //call_list("_on_load_module_", module, option);
  2659 4:   call_list("_on_unload_module_", filename);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\stdprocs.e
  3479 6:   //call_list('_gotfocus_');
  3486 4:   call_list('_lostfocus_');
  3526 4:   call_list('_switchbuf_',old_buffer_name,option,swold_pos,swold_buf_id);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tagfind.e
  800 4:   call_list("_on_popup2", translate("_tagbookmark_menu", "_", "-"), menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tagform.e
  430 7:      call_list("_LoadBackgroundTaggingSettings");
  2052 4:   call_list('_prjupdate_');
  2190 7:      call_list("_LoadBackgroundTaggingSettings");
  2385 7:      call_list("_LoadBackgroundTaggingSettings");
  2669 7:      call_list("_LoadBackgroundTaggingSettings");
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tagrefs.e
  1845 4:   call_list("_on_popup2", translate("_tagbookmark_menu", "_", "-"), menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tags.e
  319 4:   call_list(prefix,filename,options);
  336 7:      call_list(a1,a2,a3);
  339 7:      call_list(TAGFILE_REFRESH_CALLBACK_PREFIX);
  11218 4:   call_list("_LoadBackgroundTaggingSettings");
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tagwin.e
  2535 4:   call_list("_on_popup2", translate("_tagbookmark_menu", "_", "-"), menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tbclass.e
  2994 4:   call_list("_on_popup2_",translate("_tbclass_members_menu","_","-"),menu_handle);
  3040 4:   call_list("_on_popup2_",translate("_tbclass_classes_menu","_","-"),menu_handle);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\tbopen.e
  1686 7:      call_list("_cd_",path);
  3747 4:   call_list('_prjupdate_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\vc.e
  946 7:      call_list('_cd_');
  3445 10:         call_list('_cbmdibuffer_unhidden_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\vi.e
  511 4:   call_list('_vi_switchmode_');
File C:\Program Files\SlickEdit Pro 23.0.2\macros\window.e
  626 12:           call_list('_cbmdibuffer_hidden_');
  632 9:        call_list('_cbmdibuffer_hidden_');
  639 9:        call_list('_cbmdibuffer_hidden_');
  645 12:           call_list('_cbmdibuffer_hidden_');
  1358 4:   call_list('_config_reload_');
  1391 4:   call_list('-exit-', endingSession);
  1409 4:   call_list('-cb-exitbefore-save-config-', endingSession);
File C:\Program Files\SlickEdit Pro 23.0.2\macros\wkspace.e
  152 4:   call_list('_prjclose_',singeFileProject);
  266 4:   call_list("_MenuAddWorkspaceHist_",filename);
  1461 4:   call_list('_workspace_opened_');
  2521 4:   call_list('_prjupdate_');
  2765 4:   call_list('_prjupdate_');
  3013 4:   call_list('_wkspace_close_');
  3014 4:   call_list('_prjconfig_');  // Active config changed
  5120 7:      call_list('_prjconfig_');  // Active config changed
  5273 9:      //call_list('_prjclose_');
  5283 7:      call_list('_prjconfig_');  // Active config changed
  5315 7:      call_list('_prjopen_',false);
  8488 4:   call_list('_workspace_file_add', _project_name, Filename);
  10541 7:      call_list('_prjupdate_');
  11841 4:   call_list('_project_opened');
  11856 4:   call_list('_workspace_refresh_');
Total found: 180     Matching files: 53     Total files searched: 477

TKasparek

  • Senior Community Member
  • Posts: 219
  • Hero Points: 27
Re: Need a new buffer opened - call macro example
« Reply #2 on: December 03, 2019, 12:13:23 am »
Thanks! A _buffer_add_ function is exactly what I was looking for. I'm surprised this functionality isn't documented in the SE Help. A search indicates it's referenced only once with a very loose example.

I did a lot of SE macros investigation when making a macro I call RegexColor. It uses a lot of the concepts from the SE SymbolColorAnalyzer; I'm pretty sure I first discovered *BufferInfoHt functionality there. It's also documented a bit in the help if you search for it by name.

Do you know how to get a callback for when the buffer window is scrolled or changes size? Currently, I run a timer to look for a change in the buffer window position to re-color if outside of the colored line ranges. This functionality would also be very useful.

Bamsen

  • Community Member
  • Posts: 53
  • Hero Points: 6
Re: Need a new buffer opened - call macro example
« Reply #3 on: December 03, 2019, 07:10:14 am »
How do you add a _buffer_add_ function and include it in the list of functions to be called?

Graeme

  • Senior Community Member
  • Posts: 2385
  • Hero Points: 314
Re: Need a new buffer opened - call macro example
« Reply #4 on: December 03, 2019, 10:39:14 am »
How do you add a _buffer_add_ function and include it in the list of functions to be called?
Like this
void _buffer_add_water(int newbuffid, _str name, int flags = 0)
{
    say("buffer is " :+ name);
}
That's all you have to do.  Because the function name starts with _buffer_add_ it is called automatically.  Slick has a thing called a "names table" - search for "names table" in the help.  The names table allows slick to search (at runtime) for all functions whose name starts with a particular prefix.  Slick macro code uses late binding where all function calls to macro code go via the names table.  This allows you to reload a macro file and have all the rest of the already compiled macro code still call the functions in your newly loaded module without themselves being recompiled.