source: trunk/src/netlabs/macros/modeexec.e@ 3300

Last change on this file since 3300 was 3300, checked in by Andreas Schnellbacher, 6 years ago
  • Replaced Tab and Backtab configuration.
  • Added more options for Tab and Backtab keys and its altered variants.
  • Backtab now handles tab chars in a line correctly. For that tab chars are expanded first. The cursor sol. is now correct.
  • Removed obsolete funcs, consts and universals like WANT_TAB_INSERTION_TO_SPACE and tab_keys.
  • Also removed SMARTFILE.
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 66.1 KB
Line 
1/****************************** Module Header *******************************
2*
3* Module Name: modeexec.e
4*
5* Copyright (c) Netlabs EPM Distribution Project 2004
6*
7* $Id: modeexec.e 3300 2018-12-07 23:17:23Z aschn $
8*
9* ===========================================================================
10*
11* This file is part of the Netlabs EPM Distribution package and is free
12* software. You can redistribute it and/or modify it under the terms of the
13* GNU General Public License as published by the Free Software
14* Foundation, in version 2 as it comes in the "COPYING" file of the
15* Netlabs EPM Distribution. This library is distributed in the hope that it
16* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18* General Public License for more details.
19*
20****************************************************************************/
21; Provides Set* commands for mode-specific configuration.
22;
23; Settings are handled with different priorities:
24;
25; 1. Default settings (configurable via Options menu, lowest priority)
26;
27; 2. Mode settings (configurable via MODECFG.E and/or PROFILE.ERX, using
28; 'ModeExecute <mode> Set*' commands )
29;
30; 3. File settings (configurable via File properties menu, highest priority)
31;
32; The settings of 2. and 3. are saved in array vars. It is determined, if a
33; setting has to be executed at defload or defselect using lists. After the
34; mode settings are applied (either at defload or at the first defselect),
35; they can be overwritten with file specific settings.
36;
37; Any change of mode will reset the file settings to the mode defaults. The
38; file-specific array vars will be deleted in order to have the mode
39; settings re-applied after that.
40
41; ---------------------------------------------------------------------------
42; You may want to reset all prior used ModeExecute defs with
43; 'ModeExecute CLEAR'.
44;
45; Syntax: ModeExecute <mode> <set_cmd> <args>
46;
47; <set_cmd> <args>
48;
49; SetStreamMode 0 | 1
50; SetInsertMode 0 | 1
51; SetHighlight 0 | 1
52; SetTabs <number> or <list of numbers>
53; SetMatchTab 0 | 1
54; SetMargins <left> <right> <par>
55; SetTextColor <number> or <color_name> (see COLORS.E)
56; SetMarkColor <number> or <color_name> (see COLORS.E)
57; (Hint: place cursor on COLORS.E and press Alt+1 to
58; load the file)
59; SetTextFont <font_size>.<font_name>[.<font_sel>]
60; <font_size> and <font_name> can be exchanged.
61; Any EPM font specification syntax is
62; accepted as well. The args are case-sensitive.
63; SetToolbar <toolbar_name> (must be defined in NEPMD.INI)
64; SetDynaspell 0 | 1
65; SetEditOptions see description of EDIT command
66; SetSaveOptions see description of SAVE command
67; SetSearchOptions see description of LOCATE and REPLACE commands
68; (plus undocumented TB options)
69; SetKeyset <keyset_name> [<list_of_keyset_defs>]
70;
71; Settings for syntax expansion:
72; SetExpand 0 | 1
73; SetIndent <number> (default = first number of tabs)
74; SetHeaderStyle 1 | 2
75; HeaderStyle 1 (default):
76; /********************
77; * |
78; ********************/
79; HeaderStyle 2:
80; /********************
81; * |
82; *******************/
83; SetHeaderLength <-- header_length --> (default = 77)
84; SetEndCommented 0 | 1
85; SetMatchChars <space-separated list of pairs> (default = '')
86; list of possible pairs: '{ } [ ] ( ) < >'
87; SetCommentAutoTerminate
88; 0 | 1 (default = 0)
89; SetFunctionSpacing
90; 'N' | 'C' | 'SC' | 'SCE' (default = 'C')
91; 'N' no spaces
92; 'C' space after a comma in a parameter list
93; 'S' space after start (opening parenthesis) of a parameter list
94; 'E' space before end (closing parenthesis) of a parameter list
95; SetClosingBraceAutoIndent
96; 0 | 1 (default = 0)
97; SetCodingStyle <coding_style>
98; Coding styles can be defined with the
99; AddCodingStyle command, even in PROFILE.ERX
100;
101; Settings for keyset C_KEYS:
102; SetCBraceStyle 'BELOW' | 'APPEND' | 'INDENT' | 'HALFINDENT'
103; (default = 'BELOW')
104; SetCCaseStyle 'INDENT' | 'BELOW' (style of "case" statement,
105; default = 'INDENT')
106; SetCDefaultStyle 'INDENT' | 'BELOW' (style of "default" statement,
107; default = 'INDENT')
108; SetCMainStyle 'STANDARD' | 'SHORT' (style of "main" statement,
109; default = 'SHORT')
110; SetCCommentStyle 'CPP' | 'C' (use either // ... or /* ... */, if
111; EndCommented = 1, default = 'CPP')
112
113; Settings for keyset REXX_KEYS:
114; SetRexxDoStyle 'APPEND' | 'INDENT' | 'BELOW' (style of "do"
115; statement, default = 'BELOW')
116; SetRexxIfStyle 'ADDELSE' | 'NOELSE' (style of "if" statement,
117; default = 'NOELSE')
118; SetRexxCase 'LOWER' | 'MIXED' | 'UPPER' (default = 'LOWER')
119; SetRexxForceCase 0 | 1 (default = 1)
120; 1 means: change case of typed statements as
121; well, not only of the added statements
122;
123; Any <set_cmd> can also be executed in EPM's commandline. Then it will
124; affect only the current file.
125;
126; SetTextColor 31 (31 = (15 = white) + (16 = blue background))
127
128; Specify DEFAULT as <args>, if you want to reset a setting to NEPMD's
129; default value.
130;
131; SetTextColor default
132
133; If you want to reset all settings of the current file to the default
134; settings for a mode, then use the mode command:
135;
136; Mode 0 (redetermine mode and apply mode-specific settings)
137; Mode rexx (change mode to REXX and apply all REXX-specific settings)
138
139/*
140; maybe planned some time
141- SetBackupFiles
142- SetBackupPath
143- autosave?
144- SetBracketMatch
145- SetHelpNdxFiles
146- SetMenu -- switch Project menu
147- SetMenuAttribute -- toggle MIA_DISABLED
148- SetMenuText -- show current section/function
149- SetToolbarItem -- change bitmap as 'modified' notification
150- SetRunAction
151- SetLockOnModify
152*/
153
154; ---------------------------------------------------------------------------
155
156compile if not defined(SMALL) -- If SMALL not defined, then being separately compiled
157define INCLUDING_FILE = 'MODEEXEC.E'
158
159include 'stdconst.e'
160EA_comment 'This defines mode-specific commands.'
161
162;const
163; compile if not defined(NLS_LANGUAGE)
164; NLS_LANGUAGE = 'ENGLISH'
165; compile endif
166; include NLS_LANGUAGE'.e'
167
168compile endif
169
170const
171; Should a ModeExec command, being executed after startup, process all files
172; in the ring or just the current? (A ModeExec command applies always to
173; later-loaded files.)
174; Setting this to 1 would execute many commands and sometimes (maybe after
175; 10 times executing it) EPM crashes with a Memory Mapped File exception,
176; saying "not my memory".
177compile if not defined( MODEEXEC_PROCESS_RING)
178 MODEEXEC_PROCESS_RING = 0
179compile endif
180
181; ---------------------------------------------------------------------------
182; Every defined setting name must be added to either the 'loadsettingslist'
183; or the 'selectsettingslist' array var to make the setting take effect on
184; defload or defselect.
185; In order to make these list extendible easily by additional macro files,
186; array vars are used.
187; The lists must be built before 'InitModeConfig', defined in MODECFG.E is
188; executed at defmain. Therefore definit is a good choice for that.
189; At all places here settings have the prefix 'Set' stripped before being
190; added to lists. But when a setting is saved with a value, it's always
191; saved with the prefix to make the string executable directly.
192definit
193 saved_rc = rc
194 --dprintf( 'MODEEXEC: definit executed, rc at definit start = 'rc)
195 call AddAVar( 'loadsettingslist',
196 'Highlight Margins Tabs DynaSpell CodingStyle')
197 call AddAVar( 'selectsettingslist',
198 'Toolbar Keyset Expand Matchtab' ||
199 ' EditOptions SaveOptions SearchOptions' ||
200 ' StreamMode InsertMode' ||
201 ' TextFont TextColor MarkColor Indent' ||
202 ' HeaderStyle HeaderLength EndCommented' ||
203 ' MatchChars CommentAutoTerminate' ||
204 ' FunctionSpacing ClosingBraceAutoIndent')
205 --dprintf( 'MODEEXEC: definit executed, rc at definit end = 'rc)
206 -- Restore rc to make link/linkverify get the right rc, because definit
207 -- is executed immediately at linking and maybe changes the rc that link
208 -- sees.
209 rc = saved_rc
210
211; ---------------------------------------------------------------------------
212defc ResetFileSettings
213 args = arg(1)
214
215 fProcessLoad = 0
216 fProcessSelect = 0
217 wp1 = wordpos( 'LOAD', upcase( args))
218 wp2 = wordpos( 'SELECT', upcase( args))
219 if wp1 then
220 fProcessLoad = 1
221 args = delword( args, wp1, 1)
222 endif
223 if wp2 then
224 fProcessSelect = 1
225 args = delword( args, wp2, 1)
226 endif
227 -- Default is to process both
228 if not wp1 & not wp2 then
229 fProcessLoad = 1
230 fProcessSelect = 1
231 endif
232
233 LoadSettingsList = GetAVar( 'loadsettingslist')
234 SelectSettingsList = GetAVar( 'selectsettingslist')
235 -- Set all <setting>.<fid> array vars to empty
236 getfileid fid
237 SettingsList = LoadSettingsList SelectSettingsList
238 do w = 1 to words(SettingsList)
239 wrd = word( SettingsList, w)
240 call SetAVar( fid'.'lowcase(wrd), '')
241 enddo
242 call SetAVar( fid'.modesettingsapplied', 0)
243 -- Process settings
244 -- Todo: pass args to the following commands to process only these
245 -- and not the entire settings lists.
246 if fProcessLoad then
247 'ProcessLoadSettings'
248 endif
249 if fProcessSelect then
250 'ProcessSelectSettings'
251 endif
252
253; ---------------------------------------------------------------------------
254; Processes all mode-specific defload settings.
255; Executed by defload and defc ResetFileSettings.
256; (defc Mode and ResetMode call ResetFileSettings when the mode has changed.)
257defc ProcessLoadSettings
258 universal nepmd_hini
259 universal LoadState -- empty: before loading
260 -- 1: defload is running
261 -- 2: defload processed
262 -- 0: afterload processed
263 args = arg(1)
264 dprintf( 'LOAD', 'ProcessLoadSettings entered for 'args)
265
266 if not .visible then
267 return
268 endif
269 LoadSettingsList = GetAVar( 'loadsettingslist')
270
271 parse arg Mode calling_fid
272 Mode = strip(Mode)
273 calling_fid = strip(calling_fid)
274
275 if Mode = '' then
276 Mode = GetMode() -- Doesn't work properly during file loading, because current file
277 -- has probably changed? Therefore Mode is submitted as arg.
278 endif
279
280 KeyPath = '\NEPMD\User\KeywordHighlighting\AutoRefresh'
281 refresh_on = QueryConfigKey( KeyPath)
282 if refresh_on then
283 if LoadState then -- during file loading
284 CheckFlag = GetHiliteCheckFlag(Mode)
285 else
286 CheckFlag = ''
287 endif
288 else
289 CheckFlag = 'N'
290 endif
291
292 KeyPath = '\NEPMD\User\KeywordHighlighting'
293 default_on = QueryConfigKey( KeyPath)
294
295 getfileid fid
296 if isnum(calling_fid) then
297 if calling_fid <> fid then
298 --dprintf( 'No load settings processed. File not on top anymore:' ||
299 -- ' 'calling_fid.filename', current: 'fid.filename)
300 return
301 endif
302 endif
303 -- Execute mode-specific settings
304 -- Using standard definition for HookExecute. Calling another defc here is
305 -- so slow, that file to be processed is not on top anymore.
306 prefix = 'hook.'
307 HookName = 'load_'lowcase(Mode)
308 imax = GetAVar( prefix''HookName'.0')
309 if imax = '' then
310 imax = 0
311 endif
312 do i = 1 to imax
313 Cmd = GetAVar( prefix''HookName'.'i)
314 Cmd -- execute command
315 enddo
316
317 -- Copy mode-specific coding style to file-specific one. This is only used
318 -- to query the current coding style later.
319 next = GetAVar( 'modecodingstyle.'Mode)
320 call SetAVar( fid'.codingstyle', next)
321
322 if LoadState then -- during defload processing
323
324 -- Activate keyword highlighting, if not already done by load_<mode> hook
325 next = GetAVar( fid'.highlight') -- get file setting
326 if next = '' | next = 'DEFAULT' then
327 NepmdActivateHighlight( default_on, Mode, CheckFlag, nepmd_hini)
328 endif
329
330 elseif LoadState = 0 then -- when changing a mode
331
332 List = LoadSettingsList
333 do w = 1 to words( List) -- Only LoadSettings need to be reset for default mode
334 wrd = word( List, w)
335 next = GetAVar( fid'.'lowcase(wrd)) -- get file setting
336 if next = '' | next = 'DEFAULT' then
337 'Set'wrd 'DEFAULT' -- execute load setting with 'DEFAULT'
338 endif
339 enddo
340 -- Refresh the mode field on statusline.
341 -- Don't process this on defload, because it's already executed there.
342 'RefreshInfoLine MODE'
343 -- Maybe the load and load_once hook should here be executed as well?
344
345 endif
346
347; ---------------------------------------------------------------------------
348; Executed by defc ProcessSelect, using the select hook
349; and by defc ResetFileSettings.
350; (defc Mode and ResetMode call ResetFileSettings when the mode has changed.)
351defc ProcessSelectSettings
352 if not .visible then
353 return
354 endif
355 SelectSettingsList = GetAVar('selectsettingslist')
356
357 -- Get file-specific setting names
358 -- Check if a setting is set as array var (maybe as a file setting)
359 getfileid fid
360 UsedFileSettings = ''
361 -- Check if mode settings already overtaken from the hook to current file's array var
362 fModeSettingsApplied = GetAVar(fid'.modesettingsapplied')
363 if fModeSettingsApplied then
364 do w = 1 to words(SelectSettingsList)
365 wrd = word( SelectSettingsList, w)
366 wrd = lowcase( wrd)
367 SettingsValue = GetAVar(fid'.'wrd)
368 if wrd = 'keyset' & SettingsValue = 'std' then
369 SettingsValue = 'DEFAULT'
370 endif
371 if SettingsValue <> '' & SettingsValue <> 'DEFAULT' then
372 UsedFileSettings = UsedFileSettings wrd
373 endif
374 enddo
375 UsedFileSettings = strip(UsedFileSettings)
376 endif
377 --dprintf( 'UsedFileSettings = 'UsedFileSettings)
378
379 -- Execute mode-specific settings
380 -- Using the standard definition for HookExecute, extended with a check, if
381 -- config is set by the file instead of the mode.
382 Mode = GetMode()
383 prefix = 'hook.'
384 HookName = 'select_'lowcase(Mode)
385 imax = GetAVar(prefix''HookName'.0')
386 if imax = '' then
387 imax = 0
388 endif
389 UsedModeSettings = ''
390 do i = 1 to imax
391 Cmd = GetAVar(prefix''HookName'.'i)
392 parse value Cmd with wrd SettingsValue
393 if leftstr( upcase(wrd), 3) = 'SET' then
394 wrd = substr( wrd, 4) -- strip 'Set'
395 endif
396 if not wordpos( upcase(wrd), upcase(UsedFileSettings)) then
397 dprintf( 'MODEEXEC', 'MODE: 'Cmd' -- '.filename)
398 Cmd -- execute command
399 UsedModeSettings = UsedModeSettings wrd
400 endif
401 enddo
402 UsedModeSettings = strip(UsedModeSettings)
403 if not fModeSettingsApplied then
404 call SetAVar( fid'.modesettingsapplied', 1)
405 endif
406
407 -- Execute file-specific settings
408 do w = 1 to words(UsedFileSettings)
409 wrd = word( UsedFileSettings, w)
410 SettingsValue = GetAVar(fid'.'lowcase( wrd))
411 Cmd = 'Set'wrd SettingsValue
412 dprintf( 'MODEEXEC', 'FILE: 'Cmd' -- '.filename)
413 Cmd -- execute command
414 enddo
415
416 -- Restore settings to defaults for other settings used by previous file.
417 -- Tracking every non-default setting in the array var 'lastusedsettings'
418 -- increases performance, because only those settings are changed.
419 CurSettings = strip(UsedModeSettings' 'UsedFileSettings)
420 LastSettings = GetAVar('lastusedsettings')
421 --dprintf( 'lastsettings = 'LastSettings)
422 do w = 1 to words(LastSettings)
423 wrd = word( LastSettings, w)
424 if wordpos( upcase(wrd), upcase(CurSettings)) = 0 then
425 Cmd = 'Set'wrd 'DEFAULT' -- execute select setting with 'DEFAULT'
426 dprintf( 'MODEEXEC', 'RESET: 'Cmd' -- '.filename)
427 Cmd -- execute command
428 endif
429 enddo
430 call SetAVar( 'lastusedsettings', CurSettings)
431
432; ---------------------------------------------------------------------------
433; Add cmd to the select hook. This hook will be executed by HookExecute, by
434; defc ProcessSelect at ProcessAfterLoad and/or defselect.
435; (The defc ProcessLoadSettings is executed directly, without the HookExecute
436; command. This is required to process these settings for the correct file.)
437definit
438 'HookAdd select ProcessSelectSettings'
439
440; ---------------------------------------------------------------------------
441; Determine on which stack the cmd should be put on or delete the stacks.
442; Syntax:
443; ModeExecute <mode> <set_cmd> <value> to define a <value> for
444; <set_cmd>, that is used for files
445; with mode <mode>
446; ModeExecute DEFAULT <set_cmd> <value> to define the default <value>
447; for <set_cmd> (only possible for
448; some syntax expansion settings)
449; ModeExecute CLEAR to clear all existing settings,
450; but default <values> are not
451; effected
452; ModeExecute <mode> CLEAR to clear all existing settings
453; for <mode>
454; /*To change settings of already loaded files, too, use ModeExecuteRefresh.*/
455defc ModeExecute, ModeExec
456 universal LoadState -- empty: before loading
457 -- 1: defload is running
458 -- 2: defload processed
459 -- 0: afterload processed
460 LoadSettingsList = GetAVar( 'loadsettingslist')
461 SelectSettingsList = GetAVar( 'selectsettingslist')
462 parse value arg(1) with Mode Cmd Args
463 Mode = strip(Mode)
464 Cmd = strip(Cmd)
465 Args = strip(Args)
466 Mode = upcase(Mode)
467
468 if Mode = 'CLEAR' then
469 -- Clear existing load_<mode> and select_<mode> hooks
470 List = GetAVar('usedsettings_modes')
471 do w = 1 to words(List)
472 wrd = word( List, w)
473 'HookDelAll load_'lowcase(wrd)
474 'HookDelAll select_'lowcase(wrd)
475 call DelAVar('usedsettings_modes', wrd)
476 enddo
477 return 0
478 elseif Mode = 'DEFAULT' then
479 -- Define settings for DEFAULT pseudo mode
480 Cmd 'DEFINEDEFAULT' Args
481 return 0
482 elseif Cmd = 'CLEAR' then
483 -- Clear existing load_<mode> and select_<mode> hooks for <mode>
484 'HookDelAll load_'lowcase(Mode)
485 'HookDelAll select_'lowcase(Mode)
486 call DelAVar('usedsettings_modes', Mode)
487 return 0
488 endif
489
490 -- Execute the SetCodingStyle <set_cmd> immediately
491 if upcase( Cmd) = 'SETCODINGSTYLE' then
492 call ExecuteCodingStyle( Mode, Args)
493 return 0
494 endif
495
496 wrd = Cmd
497 if leftstr( upcase( wrd), 3) = 'SET' then
498 wrd = substr( wrd, 4) -- strip 'Set'
499 endif
500
501 if wordpos( upcase(wrd), upcase(SelectSettingsList)) then
502 -- These settings don't stick with the current file.
503 -- Execute them during ProcessAfterload and at/or defselect.
504 'HookChange select_'lowcase(Mode) Cmd Args
505 -- Save a list of used defselect settings for every mode
506 call AddAVar('usedsettings_'lowcase(Mode), wrd)
507 elseif wordpos( upcase(wrd), upcase(LoadSettingsList)) then
508 -- These settings stick with the current file and don't need additional
509 -- handling at defselect.
510 -- Execute them at defload only.
511 'HookChange load_'lowcase(Mode) Cmd Args
512 else
513 sayerror 'ModeExecute: "'Cmd Args'" is an invalid setting. Add "'wrd ||
514 '" to the select/loadsettingslist array var.'
515 return 1
516 endif
517
518 if LoadState = 0 then -- after afterload
519 dprintf( 'MODEEXEC', 'LoadState = 'LoadState', calling RingRefreshSettings' arg(1))
520compile if MODEEXEC_PROCESS_RING
521 --dprintf( 'MODEEXEC', 'RingRefreshSetting 'arg(1)' for '.filename)
522 'RingRefreshSetting' arg(1)
523 -- Todo for SetCodingStyle:
524 -- o Loop through all files only once, not once per subsetting.
525 -- o Refresh only one setting, not all.
526 -- Until that is done, settings should only be executed for the
527 -- current file. Otherwise EPM would crash after executing ModeExecute
528 -- several times.
529compile else
530 if Mode = GetMode() then
531 --dprintf( 'MODEEXEC', arg(1)' for '.filename)
532 Cmd Args
533 endif
534compile endif
535 endif
536
537 -- Save a list of used modes to be able to delete all settings
538 if not wordpos( Mode, GetAVar('usedsettings_modes', Mode)) then
539 call AddAVar('usedsettings_modes', Mode)
540 endif
541
542; ---------------------------------------------------------------------------
543; Syntax: RingRefreshSetting <mode> <cmd> <args>
544; Refresh specified setting for those files in the ring, whose settings were
545; not changed with a Set* command of MODEEXEC.E before. Should be executed
546; by
547; - any command, that changes default defload settings
548; currently, these are: SetHighlight, SetMargins, SetTabs,
549; SetCodingStyle
550; not effected: SetKeys SetDynaSpell (only saved as field var)
551; - a modeexecuterefresh command, if executed by hand, after file is
552; loaded.
553; <cmd> must have the name of the array var plus 'Set' prepended.
554defc RingRefreshSetting
555 universal StatusFieldFlags
556 universal TitleFieldFlags
557 parse value arg(1) with Mode Cmd Args
558 Mode = upcase(Mode)
559 parse value lowcase(Cmd) with 'set' SettingName -- Strip leading 'set'
560
561 getfileid startfid
562 display -3
563 fid = startfid
564 dprintf( 'RINGCMD', 'RingRefreshSetting')
565 do f = 1 to filesinring(1) -- prevent looping forever, hidden files must be included
566 if Mode = 'DEFAULT' then
567 next = GetAVar( fid'.'SettingName) -- query file setting
568 if next = 'DEFAULT' | next = '' then -- unset if setting was not changed by any modeexecute
569 Cmd 'REFRESHDEFAULT' Args -- execute arg(1) with 'REFRESHDEFAULT' parameter prepended
570 endif
571 elseif Mode = GetMode() then
572 if f = 1 then
573 ResetCmd = 'ResetFileSettings' -- all settings (reset of a single setting is not implemented)
574 else
575 ResetCmd = 'ResetFileSettings LOAD' -- all load settings (reset of a single setting is not implemented)
576 endif
577 ResetCmd Cmd Args -- ResetFilesettings currently processes all settings
578 endif
579 nextfile
580 getfileid fid
581 if fid = startfid then -- maybe startfid is not valid anymore at this time
582 leave
583 endif
584 enddo
585 'postme activatefile' startfid -- postme required for some Cmds, e.g. SetHighlight
586 'postme RefreshInfoLine' StatusFieldFlags TitleFieldFlags --refresh all
587 -- Minor bug: InsertMode is not refreshed here.
588 'postme display' 3
589
590; ---------------------------------------------------------------------------
591/*
592; Use this command instead of ModeExecute after files are loaded.
593defc ModeExecuteRefresh, ModeExecRefresh
594 'ModeExecute' arg(1)
595 'RingRefreshSetting' arg(1)
596*/
597
598; ---------------------------------------------------------------------------
599; Add file-specific setting name and its value to the array.
600; Add setting name to list of lastusedsettings.
601; This is used by several select setting defs.
602defproc UseSetting
603 SettingName = arg(1)
604 SettingValue = arg(2)
605 getfileid fid
606 if GetAVar( fid'.'lowcase( SettingName)) <> SettingValue then
607 call SetAVar( fid'.'lowcase( SettingName), SettingValue)
608 if not wordpos( upcase(SettingName), upcase(GetAVar('lastusedsettings'))) then
609 call AddAVar( 'lastusedsettings', SettingName)
610 endif
611 endif
612
613; ---------------------------------------------------------------------------
614; Query a setting for a mode. If no setting specified, all settings are
615; returned, separated by '|'
616defproc GetModeSetting
617 Setting = arg(1)
618 Mode = arg(2)
619
620 -- Strip possible prepended 'Set'
621 if leftstr( upcase( Setting), 3) = 'SET' then
622 Setting = substr( Setting, 4)
623 endif
624
625 if Mode = '' then
626 Mode = GetMode()
627 endif
628
629 -- These setting names don't have 'Set' prepended.
630 LoadSettingsList = GetAVar( 'loadsettingslist')
631 SelectSettingsList = GetAVar( 'selectsettingslist')
632
633 if pos( upcase( Setting), upcase( LoadSettingsList)) then
634 PrefixList = 'load_'
635 elseif pos( upcase( Setting), upcase( SelectSettingsList)) then
636 PrefixList = 'select_'
637 else
638 PrefixList = 'load_ select_'
639 -- Setting not found in any list, so reset it
640 Setting = ''
641 endif
642
643 Val = ''
644 do w = 1 to words( PrefixList)
645 Prefix = word( PrefixList, w)
646 -- Query mode setting
647 rest = HookGet( Prefix''lowcase( GetMode()))
648
649 if Setting = '' then
650 -- Return all settings, separated by '|'
651 -- These settings have 'Set' prepended. Some segments between '|'
652 -- chars are empty.
653 if Val = '' then
654 Val = rest
655 else
656 Val = Val'|'rest
657 endif
658 else
659 -- Find single setting
660 do while rest <> ''
661 parse value rest with next'|'rest
662 parse value next with ThisSetting ThisValue
663 if upcase( strip( ThisSetting)) = 'SET'upcase( Setting) then
664 Val = ThisValue
665 leave
666 endif
667 enddo
668 endif
669 enddo
670
671 return Val
672
673; ---------------------------------------------------------------------------
674defc ShowModeSetting
675 Val = GetModeSetting( arg(1))
676 if arg(1) <> '' then
677 sayerror 'Value for 'arg(1)' and current mode is: 'Val
678 else
679 sayerror 'ModeSettings for current mode: 'Val
680 endif
681
682; ---------------------------------------------------------------------------
683; List all mode- and file-specific settings for all files in the ring.
684defc RingDumpSettings
685 LoadSettingsList = GetAVar( 'loadsettingslist')
686 SelectSettingsList = GetAVar( 'selectsettingslist')
687 SettingsList = LoadSettingsList SelectSettingsList
688 SettingsList = SettingsList' modesettingsapplied' -- append system var
689 -- Check max. length of 1600. Current length = 416.
690 --dprintf( 'length( SettingsList) = 'length( SettingsList))
691 if length( SettingsList) > 1599 then
692 'SayError String "SettingsList" too long: Max. string length (1600) reached.'
693 endif
694 TmpFileName = '.FILE_SETTINGS'
695 getfileid startfid
696 display -3
697 if pfile_exists(TmpFileName) then
698 'xcom e /n' TmpFileName -- activate tmp file
699 else
700 'xcom e /c' TmpFileName -- create tmp file
701 deleteline -- delete first line (EPM automatically creates line 1)
702 endif
703 getfileid tmpfid
704 savedlast = .last
705 .autosave = 0
706 parse value getdatetime() with Hour24 Minutes Seconds . Day MonthNum Year0 Year1 .
707 Date = rightstr(Year0 + 256*Year1, 4, 0)'-'rightstr(monthnum, 2, 0)'-'rightstr(Day, 2, 0)
708 Time = rightstr(hour24, 2)':'rightstr(Minutes,2,'0')':'rightstr(Seconds,2,'0')
709 insertline copies('-', 78), .last + 1
710 insertline 'File settings - created on 'Date' 'Time, .last + 1
711 varname = ' Defload settings ='
712 line = varname
713 do w = 1 to words(LoadSettingsList)
714 wrd = word( LoadSettingsList, w)
715 if length(line) + length(wrd) > 77 then
716 insertline line, .last + 1
717 line = copies( ' ', length(varname)) wrd
718 else
719 line = line wrd
720 endif
721 enddo
722 if line > '' then
723 insertline line, .last + 1
724 endif
725 varname = ' Defselect settings ='
726 line = varname
727 do w = 1 to words(SelectSettingsList)
728 wrd = word( SelectSettingsList, w)
729 if length(line) + 1 + length(wrd) > 78 then
730 insertline line, .last + 1
731 line = copies( ' ', length(varname)) wrd
732 else
733 line = line wrd
734 endif
735 enddo
736 if line > '' then
737 insertline line, .last + 1
738 endif
739 insertline ' Defselect usedsettings_modes = 'GetAVar( 'usedsettings_modes'), .last + 1
740 insertline ' Defselect lastusedsettings = 'GetAVar( 'lastusedsettings'), .last + 1
741 activatefile startfid
742 fid = startfid
743 dprintf( 'RINGCMD', 'RingDumpSettings')
744 do f = 1 to filesinring(1) -- just an upper limit
745 if .visible then -- omit hidden files
746 insertline .filename, tmpfid.last + 1, tmpfid
747 -- Add mode
748 insertline ' 'leftstr( 'mode', max( length('mode'), 22))' = 'GetMode(), tmpfid.last + 1, tmpfid
749 do w = 1 to words(SettingsList)
750 wrd = word( SettingsList, w)
751 SettingName = lowcase(wrd)
752 SettingValue = GetAVar( fid'.'SettingName) -- query file setting
753 insertline ' 'leftstr( SettingName, max( length(SettingName), 22))' = 'SettingValue, tmpfid.last + 1, tmpfid
754 enddo
755 endif
756 nextfile
757 getfileid fid
758 if fid = startfid then
759 leave
760 endif
761 enddo
762 insertline '', tmpfid.last + 1, tmpfid
763 tmpfid.modify = 0
764 activatefile tmpfid
765 .line = savedlast + 1
766 display 3
767
768; ---------------------------------------------------------------------------
769; Set* commands
770; These commands can be used with the ModeExecute command. Then they set the
771; value for all files of a mode. If a <set_cmd> is used alone, only the
772; current activated file is effected.
773; Syntax:
774; <set_cmd> <value>
775; ---------------------------------------------------------------------------
776; Execute this only at defload or -- when file has default setting -- after
777; changing the default value. In that case use the parameter
778; REFRESHDEFAULT <new_default_value>.
779defc SetHighlight
780 universal nepmd_hini
781 universal LoadState
782 SettingName = 'highlight'
783
784 getfileid fid
785 SettingValue = GetAVar( fid'.'SettingName)
786 arg1 = upcase(arg(1))
787 wp = wordpos( 'REFRESHDEFAULT', arg1)
788 RefreshDefault = (wp > 0)
789 if RefreshDefault then
790 arg1 = delword( arg1, wp, 1) -- remove 'REFRESHDEFAULT' from arg1
791 endif
792 CheckFlag = ''
793 wp = wordpos( 'N', arg1)
794 if wp > 0 then
795 CheckFlag = 'N'
796 arg1 = delword( arg1, wp, 1) -- remove 'N' from arg1
797 endif
798
799 if CheckFlag = '' then
800 if LoadState then
801 KeyPath = '\NEPMD\User\KeywordHighlighting\AutoRefresh'
802 refresh_on = QueryConfigKey( KeyPath)
803 if refresh_on then
804 CheckFlag = GetHiliteCheckFlag(Mode)
805 endif
806 endif
807 endif
808
809 KeyPath = '\NEPMD\User\KeywordHighlighting' -- for default value if arg1 = 'DEFAULT' or empty
810 if arg1 = 'DEFAULT' then
811 on = QueryConfigKey( KeyPath)
812 elseif arg1 = 0 then
813 on = 0
814 else
815 on = 1
816 endif
817
818 -- Process the following at RefreshDefault only if setting has default value
819 if RefreshDefault & not (SettingValue = '' | SettingValue = 'DEFAULT') then
820 return
821 endif
822
823 -- Process setting
824 Mode = GetMode()
825 call NepmdActivateHighlight( on, Mode, CheckFlag, nepmd_hini)
826
827 -- Save the value in an array var, to determine 'DEFAULT' state later
828 -- Process the following not at RefreshDefault
829 if SettingValue <> arg1 & not RefreshDefault then
830 call SetAVar( fid'.'SettingName, arg1)
831 endif
832
833; ---------------------------------------------------------------------------
834; Execute this only at defload or -- when file has default setting -- after
835; changing the default value. In that case use the parameter
836; REFRESHDEFAULT <new_default_value>.
837defc SetMargins -- defc margins exist
838 -- LoadState stores if tabs or margins were already set by the EA's
839 -- EPM.TABS or EPM.MARGINS. Every loaded file reuses it, therefore it can
840 -- only be used at defload.
841 universal LoadState
842 -- fid'.modesettingsapplied' is reset to 0 by 'ResetFileSettings'
843 getfileid fid
844 ModeSettingsApplied = GetAVar(fid'.modesettingsapplied')
845 SettingName = 'margins'
846 InfolineName = 'MARGINS'
847
848 getfileid fid
849 SettingValue = GetAVar( fid'.'SettingName)
850 arg1 = upcase(arg(1))
851 wp = wordpos( 'REFRESHDEFAULT', arg1)
852 RefreshDefault = (wp > 0)
853 if RefreshDefault then
854 arg1 = delword( arg1, wp, 1) -- remove 'REFRESHDEFAULT' from arg1
855 endif
856
857 SetFromEa = 0
858 -- Search EPM.TABS in .eaarea
859 Found = find_ea( 'EPM.MARGINS', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen)
860 if Found & ea_valuelen <> 0 then
861 SetFromEa = 1
862 endif
863
864 -- Process the following at RefreshDefault only if setting has default value
865 if RefreshDefault & not (SettingValue = '' | SettingValue = 'DEFAULT') then
866 return
867 endif
868
869 if arg1 = 'DEFAULT' | arg1 = 0 then
870 if LoadState & SetFromEa then
871 arg1 = .margins
872 elseif LoadState = 0 then
873 'margins' 0 -- reset, maybe delete EPM.MARGINS
874 arg1 = 'DEFAULT'
875 endif
876 elseif SetFromEa = 0 then -- Override only if not already set from EA
877 if LoadState | RefreshDefault | (ModeSettingsApplied <> 1) then
878 .margins = arg1
879 elseif LoadState = 0 then -- User has executed this command
880 'margins NOEA' arg1 -- set EPM.MARGINS
881 endif
882 else
883 --dprintf( 'Margins not set: '.filename)
884 endif
885
886 -- Save the value in an array var, to determine 'DEFAULT' state later
887 -- Process the following not at RefreshDefault
888 if SettingValue <> arg1 & not RefreshDefault then
889 call SetAVar( fid'.'SettingName, arg1)
890 endif
891 -- Refresh titletext or statusline
892 if not RefreshDefault then
893 'RefreshInfoLine' InfolineName
894 endif
895
896; ---------------------------------------------------------------------------
897; Execute this only at defload or -- when file has default setting -- after
898; changing the default value. In that case use the parameter
899; REFRESHDEFAULT <new_default_value>.
900defc SetTabs -- defc tabs exist
901 -- LoadState stores if tabs or margins were already set by the EA's
902 -- EPM.TABS or EPM.MARGINS. Every loaded file reuses it, therefore it can
903 -- only be used at defload.
904 universal LoadState
905 -- fid'.modesettingsapplied' is reset to 0 by 'ResetFileSettings'
906 getfileid fid
907 ModeSettingsApplied = GetAVar(fid'.modesettingsapplied')
908 SettingName = 'tabs'
909 InfolineName = 'TABS'
910
911 getfileid fid
912 SettingValue = GetAVar( fid'.'SettingName)
913 arg1 = upcase(arg(1))
914 wp = wordpos( 'REFRESHDEFAULT', arg1)
915 RefreshDefault = (wp > 0)
916 if RefreshDefault then
917 arg1 = delword( arg1, wp, 1) -- remove 'REFRESHDEFAULT' from arg1
918 endif
919
920 SetFromEa = 0
921 -- Search EPM.TABS in .eaarea
922 Found = find_ea( 'EPM.TABS', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen)
923 if Found & ea_valuelen <> 0 then
924 SetFromEa = 1
925 endif
926
927 -- Process the following at RefreshDefault only if setting has default value
928 if RefreshDefault & not (SettingValue = '' | SettingValue = 'DEFAULT') then
929 return
930 endif
931
932 if arg1 = 'DEFAULT' | arg1 = 0 then
933 if LoadState & SetFromEa then
934 arg1 = .tabs
935 elseif LoadState = 0 then
936 'tabs' 0 -- reset, maybe delete EPM.TABS
937 arg1 = 'DEFAULT'
938 endif
939 elseif not SetFromEa then -- Override only if not already set from EA
940 if LoadState | RefreshDefault | (ModeSettingsApplied <> 1) then
941 .tabs = arg1
942 elseif LoadState = 0 then -- User has executed this command
943 'tabs NOEA' arg1 -- set EPM.TABS
944 endif
945 else
946 --dprintf( 'Tabs not set: '.filename)
947 endif
948
949 -- Save the value in an array var, to determine 'DEFAULT' state later
950 -- Process the following not at RefreshDefault
951 if SettingValue <> arg1 & not RefreshDefault then
952 call SetAVar( fid'.'SettingName, arg1)
953 endif
954 -- Refresh titletext or statusline
955 if not RefreshDefault then
956 'RefreshInfoLine' InfolineName
957 endif
958
959; ---------------------------------------------------------------------------
960; Execute this only at defload.
961defc SetDynaSpell -- defc dynaspell exists and is used here
962 universal LoadState
963 universal activeaccel
964 arg1 = upcase(arg(1))
965 if arg1 = '' | arg1 = 'DEFAULT' then
966 on = 0
967 elseif wordpos( arg1, '0 OFF') then
968 on = 0
969 else
970 on = 1
971 endif
972 old = (activeaccel = 'spell')
973 if on <> old then
974 'DynaSpell' -- toggle
975 endif
976 -- Save the value in an array var, to determine 'DEFAULT' state later
977 getfileid fid
978 call SetAVar( fid'.dynaspell', arg(1))
979 if LoadState = 0 then
980 'RefreshInfoline KEYS'
981 endif
982
983; ---------------------------------------------------------------------------
984defc SetToolbar
985 universal toolbar_loaded
986 universal current_toolbar
987 arg1 = upcase(arg(1))
988 if current_toolbar = '' then
989 current_toolbar = toolbar_loaded
990 endif
991 if upcase(current_toolbar) <> arg1 then
992 if arg1 = '' | arg1 = 'DEFAULT' then
993 --def_toolbar = queryprofile( app_hini, appname, INI_DEF_TOOLBAR)
994 def_toolbar = GetDefaultToolbar()
995 if def_toolbar <> '' then
996 'postme LoadToolbar NOSAVE' def_toolbar
997 current_toolbar = def_toolbar
998 endif
999 elseif arg1 = \1 | wordpos( arg1, 'BUILTIN STANDARD') then
1000 'postme LoadStandardToolbar' -- built-in toolbar, NOSAVE not required
1001 current_toolbar = 'STANDARD'
1002 else
1003 'postme LoadToolbar NOSAVE' arg(1)
1004 current_toolbar = arg(1)
1005 endif
1006 endif
1007 -- Save the value in an array var, because no field var exists
1008 call UseSetting( 'ToolBar', arg(1))
1009
1010; ---------------------------------------------------------------------------
1011defc SetKeyset
1012 universal LoadState
1013 parse arg Keyset SubKeysets
1014 --getfileid fid
1015 --dprintf( 'SetKeyset 'Keyset SubKeysets' called, mode = 'GetMode()', .filename = '.filename', fid = 'fid)
1016 Keyset = lowcase( strip( Keyset))
1017 -- Default accel table name = 'std' (standard EPM uses 'defaccel')
1018 if Keyset = '' | Keyset = 'default' then
1019 Keyset = 'std'
1020 endif
1021 SubKeysets = lowcase( strip( SubKeysets))
1022
1023 -- SetKeyset2 (defined in KEYS.E) does the keyset switching
1024 'SetKeyset2' Keyset SubKeysets
1025
1026 -- Save the value in an array var, because no field var exists
1027 call UseSetting( 'Keyset', Keyset)
1028 'RefreshInfoLine KEYSET'
1029
1030; ---------------------------------------------------------------------------
1031defc SetExpand -- defc expand exists
1032 universal LoadState
1033 universal expand_on
1034 arg1 = upcase(arg(1))
1035 if arg1 = '' | arg1 = 'DEFAULT' then
1036 KeyPath = '\NEPMD\User\SyntaxExpansion'
1037 on = QueryConfigKey( KeyPath)
1038 if on then
1039 ExpandMode = GetMode()
1040 else
1041 ExpandMode = ''
1042 endif
1043 elseif wordpos( arg1, '0 OFF') then
1044 on = 0
1045 ExpandMode = ''
1046 elseif wordpos( arg1, '1 ON') then
1047 on = 1
1048 ExpandMode = GetMode()
1049 else
1050 on = 1
1051 ExpandMode = arg1
1052 endif
1053 -- Set universal var
1054 expand_on = on
1055 -- Save the value in an array var, because no field var exists
1056 --call UseSetting( 'Expand', arg(1))
1057 call UseSetting( 'Expand', ExpandMode)
1058 'RefreshInfoLine EXPAND'
1059
1060; ---------------------------------------------------------------------------
1061defc SetIndent
1062 universal indent
1063 arg1 = upcase(arg(1))
1064 if arg1 = '' | arg1 = 'DEFAULT' then
1065 new = word( .tabs, 1)
1066 else
1067 new = arg(1)
1068 endif
1069 -- Set universal var
1070 indent = new
1071 -- Save the value in an array var, because no field var exists
1072 call UseSetting( 'Indent', arg(1))
1073
1074; ---------------------------------------------------------------------------
1075defc SetMatchTab -- defc matchtab exists
1076 universal LoadState
1077 universal matchtab_on
1078 arg1 = upcase(arg(1))
1079 if arg1 = '' | arg1 = 'DEFAULT' then
1080 KeyPath = '\NEPMD\User\SpecialKeys\Tab\MatchWordsAbove'
1081 on = QueryConfigKey( KeyPath)
1082 elseif wordpos( arg1, '0 OFF') then
1083 on = 0
1084 else
1085 on = 1
1086 endif
1087 -- Set universal var
1088 matchtab_on = on
1089 -- Save the value in an array var, because no field var exists
1090 call UseSetting( 'MatchTab', arg(1))
1091 'RefreshInfoLine MATCHTAB'
1092
1093; ---------------------------------------------------------------------------
1094; doesn't work (because just executed at defload, not at edit)
1095; Must be executed at defmain, before executing doscommand.
1096; Problem: Mode is not determined at this time. That will be done at
1097; defload, to assure that a fileid exists. It's required for the
1098; array var, used to save the mode of the current file.
1099defc SetEditOptions
1100 universal default_edit_options
1101 arg1 = upcase(arg(1))
1102 if arg1 = '' | arg1 = 'DEFAULT' then
1103 KeyPath = '\NEPMD\User\Edit\DefaultOptions'
1104 new = QueryConfigKey( KeyPath)
1105 else
1106 new = arg(1)
1107 endif
1108 -- Set universal var
1109 default_edit_options = new
1110 -- Save the value in an array var, because no field var exists
1111 call UseSetting( 'EditOptions', arg(1))
1112
1113; ---------------------------------------------------------------------------
1114defc SetSaveOptions
1115 universal default_save_options
1116 arg1 = upcase(arg(1))
1117 if arg1 = '' | arg1 = 'DEFAULT' then
1118 KeyPath = '\NEPMD\User\Save\DefaultOptions'
1119 new = QueryConfigKey( KeyPath)
1120 else
1121 new = arg(1)
1122 endif
1123 -- Set universal var
1124 default_save_options = new
1125 -- Save the value in an array var, because no field var exists
1126 call UseSetting( 'SaveOptions', arg(1))
1127
1128; ---------------------------------------------------------------------------
1129defc SetSearchOptions
1130 universal default_search_options
1131 arg1 = upcase(arg(1))
1132 if arg1 = '' | arg1 = 'DEFAULT' then
1133 KeyPath = '\NEPMD\User\Search\DefaultOptions'
1134 new = QueryConfigKey( KeyPath)
1135 else
1136 new = arg(1)
1137 endif
1138 -- Set universal var
1139 default_search_options = new
1140 -- Save the value in an array var, because no field var exists
1141 call UseSetting( 'SearchOptions', arg(1))
1142
1143; ---------------------------------------------------------------------------
1144defc SetStreamMode
1145 universal LoadState
1146 universal stream_mode
1147 universal default_stream_mode
1148 arg1 = upcase(arg(1))
1149 if arg1 = '' | arg1 = 'DEFAULT' then
1150 on = default_stream_mode
1151 elseif wordpos( arg1, '0 OFF') then
1152 on = 0
1153 else
1154 on = 1
1155 endif
1156 -- Set universal var and process setting
1157 stream_mode = on
1158 'togglecontrol 24' stream_mode
1159 -- Save the value in an array var, because no field var exists
1160 call UseSetting( 'StreamMode', arg(1))
1161 'RefreshInfoLine STREAMMODE'
1162
1163; ---------------------------------------------------------------------------
1164defc SetInsertMode
1165 arg1 = upcase(arg(1))
1166 if arg1 = '' | arg1 = 'DEFAULT' then
1167 on = 1
1168 elseif wordpos( arg1, '0 OFF') then
1169 on = 0
1170 else
1171 on = 1
1172 endif
1173 --sayerror 'arg1 = 'arg1', new = 'new', old = 'old', .filename = '.filename
1174 if on <> insertstate() then
1175 inserttoggle
1176 --'postme inserttoggle'
1177 endif
1178 -- Save the value in an array var, because no field var exists
1179 call UseSetting( 'InsertMode', arg(1))
1180 -- Update of infoline field is handled internally
1181
1182; ---------------------------------------------------------------------------
1183; Syntax: SetTextFont <size>[.<name>[.<attrib1>[ <attrib2>]]] or
1184; SetTextFont <name>.<size>[.<attrib[ <attrib2>]]
1185; Any following specifications, separated by a period are ignored.
1186defc SetTextFont
1187 universal lastfont
1188 arg1 = upcase(arg(1))
1189 if arg1 = '' | arg1 = 'DEFAULT' then
1190 --new = queryprofile( app_hini, appname, 'FONT')
1191 --if new = '' then
1192 -- new = '12.System VIO'
1193 --endif
1194 KeyPath = '\NEPMD\User\Fonts\Text'
1195 new = QueryConfigKey( KeyPath)
1196 else
1197 new = arg(1)
1198 parse value new with size '.' rest
1199 if not isnum( size) then
1200 sayerror 'Unknown font specification "'arg1'"'
1201 return
1202 endif
1203 if rest = '' then
1204 parse value queryfont(.font) with fontname '.' fontsize '.' fontsel
1205 new = size'.'fontname
1206 if fontsel > 0 then
1207 new = size'.'fontname'.'fontsel
1208 endif
1209 endif
1210 endif
1211 if new <> lastfont then
1212 lastfont = new -- save it in a universal var, because .font holds only an id
1213 -- It would be much better to avoid the processfontrequest
1214 -- and execute simply: .font = <font_id>. Therefore the
1215 -- font_id would have been saved, after it was registered:
1216 -- .font = registerfont(fontname, fontsize, fontsel)
1217 new = ConvertToEFont( new)
1218 'processfontrequest' new
1219 --'postme processfontrequest' new -- must be posted (why?) -- apparently not!
1220 endif
1221 -- Save the value in an array var, because no field var exists
1222 call UseSetting( 'TextFont', arg(1))
1223
1224; ---------------------------------------------------------------------------
1225defc SetTextColor
1226 --universal appname
1227 --universal app_hini
1228 arg1 = upcase(arg(1))
1229 if arg1 = '' | arg1 = 'DEFAULT' then
1230 --colors = queryprofile( app_hini, appname, 'STUFF')
1231 --if colors = '' then
1232 -- new = 120
1233 --else
1234 -- new = subword( colors, 1, 1)
1235 --endif
1236 KeyPath = '\NEPMD\User\Colors\Text'
1237 new = ColorNameToNum( QueryConfigKey( KeyPath))
1238 else
1239 new = ColorNameToNum( arg(1))
1240 if rc <> 0 then
1241 return rc
1242 endif
1243 endif
1244 if new = '' then
1245 return
1246 elseif new <> .textcolor then -- the color is set but needs activation
1247 .textcolor = new
1248 endif
1249 -- Save the value in an array var, to determine 'DEFAULT' state later
1250 call UseSetting( 'TextColor', arg(1))
1251
1252; ---------------------------------------------------------------------------
1253defc SetMarkColor
1254 --universal appname
1255 --universal app_hini
1256 arg1 = upcase(arg(1))
1257 if arg1 = '' | arg1 = 'DEFAULT' then
1258 --colors = queryprofile( app_hini, appname, 'STUFF')
1259 --if colors = '' then
1260 -- new = 113
1261 --else
1262 -- new = subword( colors, 2, 1)
1263 --endif
1264 KeyPath = '\NEPMD\User\Colors\Mark'
1265 new = ColorNameToNum( QueryConfigKey( KeyPath))
1266 else
1267 new = ColorNameToNum( arg(1))
1268 if rc <> 0 then
1269 return
1270 endif
1271 endif
1272 if new = '' then
1273 return
1274 elseif new <> .markcolor then -- the color is set but needs activation
1275 .markcolor = new
1276 endif
1277 -- Save the value in an array var, to determine 'DEFAULT' state later
1278 call UseSetting( 'MarkColor', arg(1))
1279
1280; ---------------------------------------------------------------------------
1281; Common Set* commands for syntax expansion
1282; For these commands a DEFINEDEFAULT parameter exists, as long as the
1283; default value is not configurable via the menu or a settings dialog.
1284; DEFINEDEFAULT is added by ModeExecute, when it is called with the DEFAULT
1285; pseudo mode.
1286; Syntax:
1287; <set_cmd> <value> to set a <value> for <set_cmd>
1288; <set_cmd> DEFINEDEFAULT <value> to set the default <value>, that is
1289; used if no <set_cmd> exists for a mode
1290; or a file
1291; ---------------------------------------------------------------------------
1292; Used in: CKEYS.E, REXXKEYS.E
1293defc SetHeaderStyle
1294 universal header_style
1295 universal default_header_style
1296 ValidArgs = '1 2'
1297 arg1 = strip( upcase( arg(1)))
1298 parse value arg1 with next rest
1299 if next = 'DEFINEDEFAULT' then
1300 if header_style = default_header_style then
1301 header_style = rest -- init
1302 endif
1303 default_header_style = rest
1304 else
1305 if not wordpos( arg1, ValidArgs) then
1306 if default_header_style = '' then
1307 default_header_style = 1
1308 endif
1309 arg1 = default_header_style
1310 endif
1311 header_style = arg1
1312 -- Save the value in an array var, because no field var exists
1313 call UseSetting( 'HeaderStyle', arg(1))
1314 endif
1315
1316; ---------------------------------------------------------------------------
1317; Used in: CKEYS.E, REXXKEYS.E
1318defc SetHeaderLength
1319 universal header_length
1320 universal default_header_length
1321 arg1 = strip( upcase( arg(1)))
1322 parse value arg1 with next rest
1323 if next = 'DEFINEDEFAULT' then
1324 if header_length = default_header_length then
1325 header_length = rest -- init
1326 endif
1327 default_header_length = rest
1328 else
1329 if not IsNum( arg1) then
1330 if default_header_length = '' then
1331 default_header_length = 77
1332 endif
1333 arg1 = default_header_length
1334 endif
1335 header_length = arg1
1336 -- Save the value in an array var, because no field var exists
1337 call UseSetting( 'HeaderLength', arg(1))
1338 endif
1339
1340; ---------------------------------------------------------------------------
1341; Used in: CKEYS.E, REXXKEYS.E
1342; Auto-comment an 'end' statement
1343defc SetEndCommented
1344 universal END_commented
1345 universal default_END_commented
1346 ValidArgs = '0 1'
1347 arg1 = strip( upcase( arg(1)))
1348 parse value arg1 with next rest
1349 if next = 'DEFINEDEFAULT' then
1350 if END_commented = default_END_commented then
1351 END_commented = rest -- init
1352 endif
1353 default_END_commented = rest
1354 else
1355 if not wordpos( arg1, ValidArgs) then
1356 if default_END_commented = '' then
1357 default_END_commented = 0
1358 endif
1359 arg1 = default_END_commented
1360 endif
1361 END_commented = arg1
1362 -- Save the value in an array var, because no field var exists
1363 call UseSetting( 'EndCommented', arg(1))
1364 endif
1365
1366; ---------------------------------------------------------------------------
1367; Used in: STDKEYS.E/KEYS.E
1368; Define pairs of matching chars.
1369; o The closing char is added while typing the opening char.
1370; o The opening char is highlighted while typing the closing char.
1371; o If closingbraceautoindent is 1, typing a } on a separate line
1372; also sets the indent to match the indent of the opening {.
1373defc SetMatchChars
1374 universal match_chars
1375 universal default_match_chars
1376 arg1 = strip( upcase( arg(1)))
1377 parse value arg1 with next rest
1378 if next = 'DEFINEDEFAULT' then
1379 if match_chars = default_match_chars then
1380 match_chars = rest -- init
1381 endif
1382 default_match_chars = rest
1383 else
1384 if arg1 = '' | arg1 = 'DEFAULT' then
1385 if default_match_chars = '' then
1386 default_match_chars = ''
1387 endif
1388 arg1 = default_match_chars
1389 endif
1390 match_chars = arg1
1391 -- Save the value in an array var, because no field var exists
1392 call UseSetting( 'MatchChars', arg(1))
1393 endif
1394
1395; ---------------------------------------------------------------------------
1396; Used in: CKEYS.E, REXXKEYS.E
1397; Append "*/" automatically if comment was opened on current line
1398defc SetCommentAutoTerminate
1399 universal comment_auto_terminate
1400 universal default_comment_auto_terminate
1401 ValidArgs = '0 1'
1402 arg1 = strip( upcase( arg(1)))
1403 parse value arg1 with next rest
1404 if next = 'DEFINEDEFAULT' then
1405 if comment_auto_terminate = default_comment_auto_terminate then
1406 comment_auto_terminate = rest -- init
1407 endif
1408 default_comment_auto_terminate = rest
1409 else
1410 if not wordpos( arg1, ValidArgs) then
1411 if default_comment_auto_terminate = '' then
1412 default_comment_auto_terminate = 0
1413 endif
1414 arg1 = default_comment_auto_terminate
1415 endif
1416 comment_auto_terminate = arg1
1417 -- Save the value in an array var, because no field var exists
1418 call UseSetting( 'CommentAutoTerminate', arg(1))
1419 endif
1420
1421; ---------------------------------------------------------------------------
1422; Used in: CKEYS.E
1423; Spaces at Start/Comma/End of parameter list
1424defc SetFunctionSpacing
1425 universal function_spacing
1426 universal default_function_spacing
1427 ValidArgs = 'NSCE' -- No spaces, space at Start/Comma/End of parameter list
1428 arg1 = strip( upcase( arg(1)))
1429 parse value arg1 with next rest
1430 if next = 'DEFINEDEFAULT' then
1431 if function_spacing = default_function_spacing then
1432 function_spacing = rest -- init
1433 endif
1434 default_function_spacing = rest
1435 else
1436 function_spacing = ''
1437 len = length( arg1)
1438 do p = 1 to len
1439 if p > len then
1440 leave
1441 endif
1442 next = substr( arg1, p, 1)
1443 if not pos( next, ValidArgs) then
1444 iterate
1445 endif
1446 if pos( next, function_spacing) > 0 then
1447 iterate
1448 endif
1449 function_spacing = function_spacing''next
1450 enddo
1451 if default_function_spacing = '' then
1452 default_function_spacing = 'C'
1453 endif
1454 if function_spacing = '' then
1455 function_spacing = default_function_spacing
1456 endif
1457 -- Save the value in an array var, because no field var exists
1458 call UseSetting( 'FunctionSpacing', function_spacing)
1459 endif
1460
1461; ---------------------------------------------------------------------------
1462; Used in: CKEYS.E
1463; (Un)indent line with "}" to the indent of "{"
1464defc SetClosingBraceAutoIndent
1465 universal closing_brace_auto_indent
1466 universal default_closing_brace_auto_indent
1467 ValidArgs = '0 1'
1468 arg1 = strip( upcase( arg(1)))
1469 parse value arg1 with next rest
1470 if next = 'DEFINEDEFAULT' then
1471 if closing_brace_auto_indent = default_closing_brace_auto_indent then
1472 closing_brace_auto_indent = rest -- init
1473 endif
1474 default_closing_brace_auto_indent = rest
1475 else
1476 if not wordpos( arg1, ValidArgs) then
1477 if default_closing_brace_auto_indent = '' then
1478 default_closing_brace_auto_indent = 0
1479 endif
1480 arg1 = default_closing_brace_auto_indent
1481 endif
1482 closing_brace_auto_indent = arg1
1483 -- Save the value in an array var, because no field var exists
1484 call UseSetting( 'ClosingBraceAutoIndent', arg(1))
1485 endif
1486
1487; ---------------------------------------------------------------------------
1488; Commands for coding styles
1489; ---------------------------------------------------------------------------
1490; Delete all coding style hooks
1491; Syntax: DelAllCodingStyles
1492defc DelAllCodingStyles
1493 CodingStyles = GetAVar( 'CodingStyles')
1494 -- Remove definitions for all coding style names
1495 do c = 1 to words( CodingStyles)
1496 ThisCodingStyle = word( CodingStyles, c)
1497 'HookDelAll codingstyle.'ThisCodingStyle
1498 enddo
1499 -- Remove list of coding style names
1500 call DropAVar( 'CodingStyles')
1501
1502; ---------------------------------------------------------------------------
1503; Delete the hook (to be executed before overwriting an entire hook instead
1504; of changing the values).
1505; Syntax: DelCodingStyle <name>
1506defc DelCodingStyle
1507 parse arg name
1508 name = lowcase( name)
1509 'HookDelAll codingstyle.'name
1510 call DelAVar( 'CodingStyles', name)
1511
1512; ---------------------------------------------------------------------------
1513; Add a command to the hook. Command should be a Set* command, defined in
1514; this file. If command was already added to the hook, it is removed first,
1515; so that a command is present only once.
1516; Syntax: AddCodingStyle <name> <command>
1517defc AddCodingStyle
1518 parse arg name command
1519 name = lowcase( name)
1520 'HookChange codingstyle.'name command
1521 call AddAVar( 'CodingStyles', name)
1522
1523; ---------------------------------------------------------------------------
1524; Syntax: ModeExecute <mode> SetCodingStyle <name>
1525; or: SetCodingStyle <name> (for file specific settings)
1526; This defc is only executed when used as a file setting. When used by
1527; a ModeExecute command, it is resolved directly by ModeExecute.
1528defc SetCodingStyle
1529 call ExecuteCodingStyle( 0, arg(1))
1530 if isadefproc( 'MenuText_selectcodingstyle') then
1531 MenuText_selectcodingstyle()
1532 endif
1533
1534; ---------------------------------------------------------------------------
1535; Apply the coding style by executing the hook.
1536; Syntax:
1537; ExecuteCodingStyle( <mode>, <name>)
1538; If called with <mode> = 0, then it is handled as a file setting, otherwise
1539; as a mode setting.
1540; Because the SetCodingStyle command is executed/resolved immediately, it
1541; doesn't need to be added to the loadsettingslist, selectsettingslist or
1542; lastusedsettings.
1543defproc ExecuteCodingStyle
1544 universal LoadState
1545 Mode = arg(1)
1546 Name = arg(2)
1547 Name = lowcase( Name)
1548 if Name = 'off' then
1549 Name = 0
1550 endif
1551 Prefix = 'hook.'
1552 HookName = 'codingstyle.'Name
1553 -- Execute the hook, maybe with "'ModeExecute' Mode" prepended
1554 imax = GetAVar( prefix''HookName'.0')
1555 if IsNum( imax) then
1556 do i = 1 to imax
1557 Cmd = GetAVar( prefix''HookName'.'i)
1558 if Mode = 0 then
1559 -- Execute the file setting
1560 Cmd
1561 -- Save the value in an array var, to query current value later
1562 getfileid fid
1563 if Name = 0 then
1564 call DelAVar( fid'.codingstyle')
1565 else
1566 call SetAVar( fid'.codingstyle', Name)
1567 endif
1568 if LoadState = 0 then
1569 'RefreshInfoLine FILE'
1570 endif
1571 else
1572 -- Execute the mode setting
1573 if Name = 0 then
1574 call DelAVar( 'modecodingstyle.'mode)
1575 else
1576 call SetAVar( 'modecodingstyle.'mode, Name)
1577 endif
1578 'ModeExecute' Mode Cmd
1579 endif
1580 enddo
1581 endif
1582 return
1583
1584; ---------------------------------------------------------------------------
1585; Query current coding style
1586defproc GetCodingStyle
1587 getfileid fid
1588 CurCodingStyle = GetAVar( fid'.codingstyle')
1589 return CurCodingStyle
1590
1591defc ShowCodingStyle
1592 getfileid fid
1593 CurCodingStyle = GetAVar( fid'.codingstyle')
1594 sayerror 'fid = 'fid', CodingStyle = 'CurCodingStyle
1595
1596; ---------------------------------------------------------------------------
1597; Open a listbox to select a coding style for the current or specified mode.
1598; A line activating the selected style for the mode is appended to
1599; PROFILE.ERX, while an old line with "ModeExec <mode> SetCodingStyle" for
1600; <mode> = current mode is deleted.
1601; After that, PROFILE.ERX is activated and the new line is executed take
1602; effect immediately for the current and all later-loaded files.
1603; For a beginner it's much easier to edit PROFILE.ERX automatically, so
1604; this was added because the selection of a coding style is an essential
1605; feature to use syntax expansion at all.
1606defc SelectCodingStyle
1607 None = '-none-'
1608
1609 Mode = arg(1)
1610 if Mode = '' then
1611 Mode = GetMode()
1612 endif
1613
1614 -- Query current coding style
1615 getfileid fid
1616 CurCodingStyle = GetAVar( fid'.codingstyle')
1617
1618 -- Open listbox to select settings
1619 CodingStyles = GetAVar( 'CodingStyles')
1620 -- Append description to coding style names, if defined
1621 Rest = CodingStyles
1622 DefaultItem = ''
1623 Sep = '/'
1624 Entries = Sep
1625 Entries = Entries''None''Sep
1626 DefaultItem = 1
1627 do w = 2 to words( Rest)
1628 Next = word( Rest, w)
1629 if Next = CurCodingStyle then
1630 DefaultItem = w
1631 endif
1632 Prefix = 'hook.'
1633 HookName = 'codingstyle.'Next
1634 imax = GetAVar( prefix''HookName'.0')
1635 Description = ''
1636 if IsNum( imax) then
1637 do i = 1 to imax
1638 Cmd = GetAVar( prefix''HookName'.'i)
1639 if upcase( leftstr( Cmd, 3)) = 'SET' then
1640 Cmd = substr( Cmd, 4)
1641 endif
1642 if Description = '' then
1643 Description = Cmd
1644 else
1645 Description = Description', 'Cmd
1646 endif
1647 enddo
1648 endif
1649 -- Tab chars are not expanded in a list box, so use some spaces
1650 Entries = Entries''Next' ('Description')'Sep
1651 enddo
1652
1653 DefaultButton = 1
1654 HelpId = 0
1655 Title = 'Select a coding style for mode 'Mode''copies( ' ', 40)
1656 Text = 'Applies on current and next-loaded files only.'
1657 Text = Text' Coding style for current file: 'CurCodingStyle
1658
1659 refresh
1660 NewCodingStyle = ''
1661 Result = listbox( Title,
1662 Entries,
1663 '/~Set/Edit ~PROFILE.ERX/~Edit MODECFG.E/Cancel', -- buttons
1664 0, 0, --5, 5, -- top, left,
1665 min( words(CodingStyles), 15), 100, -- height, width
1666 gethwnd(APP_HANDLE) || atoi(DefaultItem) ||
1667 atoi(DefaultButton) || atoi(HelpId) ||
1668 Text\0 )
1669 refresh
1670
1671 -- Check result
1672 Button = asc( leftstr( Result, 1))
1673 EOS = pos( \0, Result, 2) -- CHR(0) signifies End Of String
1674
1675 NewCodingStyle = substr( Result, 2, EOS - 2)
1676 NewCodingStyle = word( NewCodingStyle, 1) -- strip optional description
1677
1678 if Button = 1 then -- Set
1679 if NewCodingStyle = '' then
1680 return 1
1681 elseif NewCodingStyle = None then
1682 NewCodingStyle = 0
1683 endif
1684
1685 -- Change profile
1686 'SelectCSChangeProfile' Mode NewCodingStyle
1687
1688 elseif Button = 2 then -- Edit PROFILE.ERX
1689 ProfileName = 'profile.erx'
1690 Profile = Get_Env('NEPMD_USERDIR')'\bin\'ProfileName
1691
1692 -- Add PROFILE.ERX and search line with "ModeExec <mode> (Add|Set)CodingStyle"
1693 -- for the current mode in it
1694 'e' Profile
1695
1696 if not wordpos( rc, '0 -282') then -- no error or new file
1697 return rc
1698 endif
1699
1700 if NewCodingStyle = None then
1701 elseif NewCodingStyle = '' then
1702 else
1703 Search = '(ADD|SET)CODINGSTYLE:w'NewCodingStyle
1704 display -8
1705 'postme mc !xcom l /'Search'/xt+fac!CenterLine!Refresh!postme display 8'
1706 endif
1707
1708 elseif Button = 3 then -- Edit MODECFG.E
1709 'EditCreateUserMacro modecfg.e'
1710 if NewCodingStyle = None then
1711 elseif NewCodingStyle = '' then
1712 else
1713 Search = '(ADD|SET)CODINGSTYLE:w'NewCodingStyle
1714 display -8
1715 'postme postme mc !xcom l /'Search'/xt+fac!CenterLine!Refresh!postme display 8'
1716 endif
1717
1718 else -- Cancel
1719 return 1
1720 endif
1721
1722; ---------------------------------------------------------------------------
1723defc SelectCSChangeProfile
1724 universal rexx_profile
1725 universal app_hini
1726 universal appname
1727 parse arg Mode NewCodingStyle
1728 if NewCodingStyle = '' then
1729 return
1730 endif
1731
1732 ProfileName = 'profile.erx'
1733 Profile = Get_Env('NEPMD_USERDIR')'\bin\'ProfileName
1734
1735 Cmd = 'ModeExecute 'Mode' SetCodingStyle 'NewCodingStyle
1736 Cmd2 = 'SetCodingStyle 'NewCodingStyle
1737
1738 -- Read PROFILE.ERX and delete line(s) with "ModeExec <mode> SetCodingStyle"
1739 -- for the current mode in it
1740 display -3
1741 'xcom e /d' Profile
1742
1743 if not wordpos( rc, '0 -282') then -- no error or new file
1744 display 3
1745 return rc
1746 endif
1747
1748 getfileid profid
1749 .visible = 0
1750
1751 if rc = -282 then -- if a new file
1752 deleteline
1753 else
1754 c = 0 -- counter for open comments
1755 lmax = .last
1756 l = 1
1757 do forever
1758 .line = l
1759 .col = 1
1760 fDeleted = 0
1761 Line = strip( translate( textline(l), ' ', \9))
1762
1763 -- Ignore comments in Line or when already in comment
1764 rest = Line
1765 Line = ''
1766 do while length( rest) > 0
1767 p1 = pos( '/*', rest)
1768 p2 = pos( '*/', rest)
1769 if p1 > 0 & (p1 < p2 | p2 = 0) then
1770 parse value rest with next'/*'rest
1771 if c = 0 then
1772 Line = Line''next
1773 endif
1774 c = c + 1
1775 elseif p2 > 0 & (p2 < p1 | p1 = 0) then
1776 c = c - 1
1777 if c < 0 then
1778 sayerror 'Error: Unmatched ending comment in line 'l', column 'p2' of PROFILE.ERX.'
1779 'xcom quit'
1780 display 3
1781 return
1782 endif
1783 parse value rest with next'*/'rest
1784 else
1785 next = rest
1786 rest = ''
1787 if c = 0 then
1788 Line = Line''next
1789 endif
1790 endif
1791 enddo
1792
1793 if strip( Line) <> '' then
1794 -- Find ModeExec[ute] <mode> SetCodingStyle <style_name> for current mode
1795 -- (Surrounding quotes or doublequotes are omitted here just for simpleness.)
1796 Search = '(MODEEXEC|MODEEXECUTE):w'Mode':wSETCODINGSTYLE'
1797 p = pos( Search, upcase(Line), 1, 'x') -- using the egrep option for pos
1798 if p > 0 then
1799 deleteline l
1800 --sayerror 'Line 'l' of PROFILE.ERX deleted: 'Line
1801 fDeleted = 1
1802 endif
1803 endif
1804
1805 if .line = .last then
1806 leave
1807 elseif not fDeleted then
1808 l = l + 1
1809 endif
1810 enddo
1811 endif
1812
1813 if NewCodingStyle <> 0 then
1814 -- Append line with new setting
1815 insertline "'"Cmd"'", .last + 1
1816 endif
1817 -- Save and quit
1818 'xcom s'
1819 'xcom q'
1820 display 3
1821
1822 -- Execute setting for this and newly loaded files of that mode
1823 Cmd
1824 Cmd2
1825 if NewCodingStyle = 0 then
1826 sayerror "Removed coding style for mode "Mode" from PROFILE.ERX."
1827 'Restart'
1828 else
1829 sayerror "Appended '"Cmd"' to PROFILE.ERX and applied setting."
1830 endif
1831
Note: See TracBrowser for help on using the repository browser.