25 Throwaway Macros
Monday, May 18, 2009How many good macros wind up in the bit dumpster each day because we can't be bothered to name the macro, file it, and make it available for others to share? Some, maybe?
Below are 25 throwaway macros.
You might see line breaks in unusual places, like this, because I didn't know how to format my text properly in Blogger when I originally wrote this.
_command void html_validator_preview()
name_info(','VSARG2_MARK|VSARG2_READ_ONLY|
VSARG2_REQUIRES_EDITORCTL)
// Move cursor to end of line, add a
// space, and join with next line.
// Should intelligently remove any extra
// spaces at the end of the top line
_command dh_bring_up, join_line_with_space()
name_info(','VSARG2_REQUIRES_EDITORCTL)
{
save_pos(p);
end_line();
last_event(name2event(' '));maybe_complete();
linewrap_delete_char();
restore_pos(p);
}
// Open current file in external program
// CSE HTML Validator and proceed to
// validate with the current Slickedit file in
_command void html_validator_preview()
name_info(','VSARG2_MARK|VSARG2_READ_ONLY|
VSARG2_REQUIRES_EDITORCTL)
{
_str filename=p_buf_name;
shell("F:\\Software\\CSE_HTMLValidator80\\
cmdlineprocessor.exe -o "filename);
}
// Balance_windows: Neatens up two MDI windows
// by making the two windows the same height
// and width. Makes adjacent windows snug
// like they look right after you split a
// window. Based on a routine from emacs
// emulation.
//
// This macro currently doesn't work on
// more than two MDI windows at once. If
// you do execute the command with more than 2
// windows open, multiple windows will be
// displayed at once, instead of two windows
// balanced next to each other.
/
// Returns: 0 if the windows were
// resized, otherwise 1.
_command int balance_windows()
name_info(','VSARG2_READ_ONLY|VSARG2_ICON|
VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_REQUIRES_MDI)
{
if (_no_child_windows()) {
// No child windows, so they can't be balanced.
return(1);
}
if (_mdi.p_child.p_window_state:=='M') {
message('Only one visible window');
return(1);
}
int count;
int orig_wid;
orig_wid=p_window_id;
count=0;
do {
next_window();
count++;
} while ( p_window_id!=orig_wid );
if (count>1 && count <4) {
_no_resize=1;
tile_windows('h');
_no_resize='';
return(0);
} else {
if (count>=4) {
letter=letter_prompt('More than three '\\'
windows active. Tile them? (y/n/q)','YNQ');
if (upcase(letter)=='Y') {
tile_windows('h');
return(0);
}
}
}
return(1);
}
// example of using filter selection
_command test_filter()
{
if (select_active()) {
lock_selection();
_end_select();
end_line=p_line;
_begin_select();
filter_init();
while (p_line<end_line) {
filt_status=filter_get_string(text);
if (!(_lineflags() & HIDDEN_LF)) {
messageNwait('p_line 'p_line' VIS,
text= 'text' filt_status= 'filt_status);
} else {
messageNwait('line 'p_line ' is HIDDEN');
}
}
filter_restore_pos();
}
}
// run external cmd unh.exe on html file in
// current buffer and display in
// new/current window
_command unhtm()
name_info(','VSARG2_REQUIRES_EDITORCTL)
{
html_fid=p_buf_name;
txt_fid=html_fid:+'.txt'
shell('unh.exe ' html_fid txt_fid);
e(txt_fid);
}
// if arg appears in current line, just delete
// that line
_command del(...) name_info(','VSARG2_REQUIRES_EDITORCTL)
{
// requires a line target
searchstr=arg(1); // TODO: differentiate bet
// numeric & string arg
parse searchstr with delim +1 sstring(delim)opts
save_pos(p);
select_line();
status=search(sstring, 'e>':+opts);
cursor_up();
select_line()
delete_selection();
restore_pos(p);
}
// Show count of hidden lines in a
// selective display
_command count_hidden_lines()
{
NoflinesShown0=((p_Noflines)-p_Nofhidden);
message( NoflinesShown0' visible (selected) lines,
p_Noflines= 'p_Noflines'; p_Nofhidden = 'p_Nofhidden);
}
// insert a horizontal separator line
// consisting of any character selected
// on being prompted
_command insert_separator(...)
name_info(',' VSARG2_READ_ONLY|
VSARG2_REQUIRES_EDITORCTL)
{
parse p_margins with left_ma right_ma new_para_ma;
if (arg(1)=='') {
message('Type a separator character');
key=get_event();
if (event2name(key)=='ESC') {
clear_message();
stop;
}
sepchar=event2name(key);
} else {
sepchar=arg(1);
}
textstr=substr('',1,right_ma,sepchar);
insert_line(textstr);
insert_line('');
down();
clear_message();
}
// expands selective display on selected
// (marked) lines
_command expand_selected()
{
// TODO: test for select_active()
end_select();
selend=p_line;
begin_select();
selbegin=p_line;
row_count=(selend - selbegin + 1);
for (i=0;i<=row_count;++i) {
_lineflags(0,PLUSBITMAP_LF|MINUSBITMAP_LF|
HIDDEN_LF|LEVEL_LF);
down();
}
message('Expanded ' selbegin ' through ' selend);
// might detect + lines and msg
// which ones were expanded
}
// Toggle selective display of all
// _commands in vusrmacs.e or any other file.
// I use this macro frequently, whenever
// I want a quick overview of all my commands by
// name
_command show_commands,cmds()
name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL|
VSARG2_READ_ONLY|VSARG2_REQUIRES_TAGGING)
{
// show all section headers and _commands
all('(^_command|^/\* \<->)','r');
// all('^_command', 'r');
}
// get mark_id for selection in another buffer
_command get_mark_id()
{
if (!select_active()) {
message(get_message(TEXT_NOT_SELECTED_RC));
} else {
mark_id=_alloc_selection();
message('mark_id= 'mark_id);
if (mark_id<0) {
message(get_message(mark_id));
return(mark_id);
}
}
}
// is selection hidden?
// to fix: hide_selection currently deselects after hiding,
// so there's no selection here to check for to toggle
_command is_selhid()
name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY|VSARG2_REQUIRES_AB_SELECTION|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
if (!select_active()) {
message get_message(TEXT_NOT_SELECTED_RC);
stop;
}
mark_id=_alloc_selection();
_get_selinfo(start_col, end_col, dummy);
NofSelectedLines=count_lines_in_selection();
NofSelectedCols=(end_col - start_col);
begin_select();
topline=p_line;
end_select();
botline=p_line;
sticky_message('Marked block:
rows='NofSelectedLines', cols='NofSelectedCols',
left='start_col', right='end_col', top='topline',
bot='botline);
goto_line(topline);
if (!(_lineflags() & HIDDEN_LF)) {
messageNwait("topline not hidden");
} else {
messageNwait('is_selhid: topline is hidden');
}
goto_line(botline);
if (!(_lineflags() & HIDDEN_LF)) {
messageNwait("botline not hidden");
} else {
messageNwait('is_selhid: botline is hidden');
}
}
// add toggle ability to select_all key
_command select_all_toggle()
name_info(','VSARG2_REQUIRES_EDITORCTL)
{
if (!select_active()) {
select_all();
} else {
deselect();
}
}
// append a cmd to end of ".command" retrieve buffer
_command append_retrieve_buffer()
name_info(','VSARG2_CMDLINE|VSARG2_ICON|
VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
{
if (!command_state()) {
cmdline_toggle();
}
get_command(text);
append_retrieve_command(text);
set_command('',1);
}
0 comments:
Post a Comment