📄 preferences.c
字号:
static const char CVSID[] = "$Id: preferences.c,v 1.98.2.5 2003/08/15 21:58:46 n8gray Exp $";/******************************************************************************** ** preferences.c -- Nirvana Editor preferences processing ** ** Copyright (C) 1999 Mark Edel ** ** This is free software; you can redistribute it and/or modify it under the ** terms of the GNU General Public License as published by the Free Software ** Foundation; either version 2 of the License, or (at your option) any later ** version. ** ** This software is distributed in the hope that it will be useful, but WITHOUT ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ** for more details. ** ** You should have received a copy of the GNU General Public License along with ** software; if not, write to the Free Software Foundation, Inc., 59 Temple ** Place, Suite 330, Boston, MA 02111-1307 USA ** ** Nirvana Text Editor ** April 20, 1993 ** ** Written by Mark Edel ** ********************************************************************************/#ifdef HAVE_CONFIG_H#include "../config.h"#endif#include "preferences.h"#include "textBuf.h"#include "nedit.h"#include "text.h"#include "search.h"#include "window.h"#include "userCmds.h"#include "highlight.h"#include "highlightData.h"#include "help.h"#include "regularExp.h"#include "smartIndent.h"#include "windowTitle.h"#include "server.h"#include "tags.h"#include "../util/prefFile.h"#include "../util/misc.h"#include "../util/DialogF.h"#include "../util/managedList.h"#include "../util/fontsel.h"#include "../util/fileUtils.h"#include "../util/utils.h"#include <stdlib.h>#include <string.h>#include <stdio.h>#include <ctype.h>#ifdef VMS#include "../util/VMSparam.h"#else#ifndef __MVS__#include <sys/param.h>#endif#include "../util/clearcase.h"#endif /*VMS*/#include <Xm/Xm.h>#include <Xm/SelectioB.h>#include <Xm/Form.h>#include <Xm/List.h>#include <Xm/SeparatoG.h>#include <Xm/LabelG.h>#include <Xm/Label.h>#include <Xm/PushBG.h>#include <Xm/PushB.h>#include <Xm/ToggleBG.h>#include <Xm/ToggleB.h>#include <Xm/RowColumn.h>#include <Xm/CascadeBG.h>#include <Xm/Frame.h>#include <Xm/Text.h>#ifdef HAVE_DEBUG_H#include "../debug.h"#endif#define PREF_FILE_VERSION "5.4"/* New styles added in 5.2 for auto-upgrade */#define ADD_5_2_STYLES " Pointer:#660000:Bold\nRegex:#009944:Bold\nWarning:brown2:Italic"/* maximum number of word delimiters allowed (256 allows whole character set) */#define MAX_WORD_DELIMITERS 256/* maximum number of file extensions allowed in a language mode */#define MAX_FILE_EXTENSIONS 20/* Return values for checkFontStatus */enum fontStatus {GOOD_FONT, BAD_PRIMARY, BAD_FONT, BAD_SIZE, BAD_SPACING};/* enumerated type preference strings ** The order of the elements in this array must be exactly the same** as the order of the corresponding integers of the enum SearchType** defined in search.h (!!)*/static char *SearchMethodStrings[] = { "Literal", "CaseSense", "RegExp", "LiteralWord", "CaseSenseWord", "RegExpNoCase", NULL};#ifdef REPLACE_SCOPE/* enumerated default scope for replace dialog if a selection exists when** the dialog is popped up.*/static char *ReplaceDefScopeStrings[] = { "Window", "Selection", "Smart", NULL};#endif#define N_WRAP_STYLES 3static char *AutoWrapTypes[N_WRAP_STYLES+3] = {"None", "Newline", "Continuous", "True", "False", NULL};#define N_INDENT_STYLES 3static char *AutoIndentTypes[N_INDENT_STYLES+3] = {"None", "Auto", "Smart", "True", "False", NULL};#define N_VIRTKEY_OVERRIDE_MODES 3static char *VirtKeyOverrideModes[N_VIRTKEY_OVERRIDE_MODES+1] = { "Never", "Auto", "Always", NULL};#define N_SHOW_MATCHING_STYLES 3/* For backward compatibility, "False" and "True" are still accepted. They are internally converted to "Off" and "Delimiter" respectively. NOTE: N_SHOW_MATCHING_STYLES must correspond to the number of _real_ matching styles, not counting False & True. False and True should also be the last ones in the list. */static char *ShowMatchingTypes[] = {"Off", "Delimiter", "Range", "False", "True", NULL};/* suplement wrap and indent styles w/ a value meaning "use default" for the override fields in the language modes dialog */#define DEFAULT_WRAP -1#define DEFAULT_INDENT -1#define DEFAULT_TAB_DIST -1#define DEFAULT_EM_TAB_DIST -1/* list of available language modes and language specific preferences */static int NLanguageModes = 0;typedef struct { char *name; int nExtensions; char **extensions; char *recognitionExpr; char *defTipsFile; char *delimiters; int wrapStyle; int indentStyle; int tabDist; int emTabDist; } languageModeRec;static languageModeRec *LanguageModes[MAX_LANGUAGE_MODES];/* Language mode dialog information */static struct { Widget shell; Widget nameW; Widget extW; Widget recogW; Widget defTipsW; Widget delimitW; Widget managedListW; Widget tabW; Widget emTabW; Widget defaultIndentW; Widget noIndentW; Widget autoIndentW; Widget smartIndentW; Widget defaultWrapW; Widget noWrapW; Widget newlineWrapW; Widget contWrapW; languageModeRec **languageModeList; int nLanguageModes;} LMDialog = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0};/* Font dialog information */typedef struct { Widget shell; Widget primaryW; Widget fillW; Widget italicW; Widget italicErrW; Widget boldW; Widget boldErrW; Widget boldItalicW; Widget boldItalicErrW; WindowInfo *window; int forWindow;} fontDialog;/* Color dialog information */typedef struct { Widget shell; Widget textFgW; Widget textFgErrW; Widget textBgW; Widget textBgErrW; Widget selectFgW; Widget selectFgErrW; Widget selectBgW; Widget selectBgErrW; Widget hiliteFgW; Widget hiliteFgErrW; Widget hiliteBgW; Widget hiliteBgErrW; Widget lineNoFgW; Widget lineNoFgErrW; Widget cursorFgW; Widget cursorFgErrW; WindowInfo *window;} colorDialog;/* Repository for simple preferences settings */static struct prefData { int wrapStyle; /* what kind of wrapping to do */ int wrapMargin; /* 0=wrap at window width, other=wrap margin */ int autoIndent; /* style for auto-indent */ int autoSave; /* whether automatic backup feature is on */ int saveOldVersion; /* whether to preserve a copy of last version */ int searchDlogs; /* whether to show explanatory search dialogs */ int searchWrapBeep; /* 1=beep when search restarts at begin/end */ int keepSearchDlogs; /* whether to retain find and replace dialogs */ int searchWraps; /* whether to attempt search again if reach bof or eof */ int statsLine; /* whether to show the statistics line */ int iSearchLine; /* whether to show the incremental search line*/ int lineNums; /* whether to show line numbers */ int pathInWindowsMenu; /* whether to show path in windows menu */ int warnFileMods; /* warn user if files externally modified */ int warnRealFileMods; /* only warn if file contents modified */ int warnExit; /* whether to warn on exit */ int searchMethod; /* initial search method as a text string */#ifdef REPLACE_SCOPE int replaceDefScope; /* default replace scope if selection exists */#endif int textRows; /* initial window height in characters */ int textCols; /* initial window width in characters */ int tabDist; /* number of characters between tab stops */ int emTabDist; /* non-zero tab dist. if emulated tabs are on */ int insertTabs; /* whether to use tabs for padding */ int showMatchingStyle; /* how to flash matching parenthesis */ int matchSyntaxBased; /* use syntax info to match parenthesis */ int highlightSyntax; /* whether to highlight syntax by default */ int smartTags; /* look for tag in current window first */ int alwaysCheckRelativeTagsSpecs; /* for every new opened file of session */ int stickyCaseSenseBtn; /* whether Case Word Btn is sticky to Regex Btn */ int prefFileRead; /* detects whether a .nedit existed */ int backlightChars; /* whether to apply character "backlighting" */ char *backlightCharTypes; /* the backlighting color definitions */#ifdef SGI_CUSTOM int shortMenus; /* short menu mode */#endif char fontString[MAX_FONT_LEN]; /* names of fonts for text widget */ char boldFontString[MAX_FONT_LEN]; char italicFontString[MAX_FONT_LEN]; char boldItalicFontString[MAX_FONT_LEN]; XmFontList fontList; /* XmFontLists corresp. to above named fonts */ XFontStruct *boldFontStruct; XFontStruct *italicFontStruct; XFontStruct *boldItalicFontStruct; int repositionDialogs; /* w. to reposition dialogs under the pointer */ int sortOpenPrevMenu; /* whether to sort the "Open Previous" menu */ int appendLF; /* Whether to append LF at the end of each file */ int mapDelete; /* whether to map delete to backspace */ int stdOpenDialog; /* w. to retain redundant text field in Open */ char tagFile[MAXPATHLEN]; /* name of tags file to look for at startup */ int maxPrevOpenFiles; /* limit to size of Open Previous menu */ int typingHidesPointer; /* hide mouse pointer when typing */ char delimiters[MAX_WORD_DELIMITERS]; /* punctuation characters */ char shell[MAXPATHLEN]; /* shell to use for executing commands */ char geometry[MAX_GEOM_STRING_LEN]; /* per-application geometry string, only for the clueless */ char serverName[MAXPATHLEN];/* server name for multiple servers per disp. */ char bgMenuBtn[MAX_ACCEL_LEN]; /* X event description for triggering posting of background menu */ char fileVersion[6]; /* Version of nedit which wrote the .nedit file we're reading */ int findReplaceUsesSelection; /* whether the find replace dialog is automatically loaded with the primary selection */ int virtKeyOverride; /* Override Motif default virtual key bindings never, if invalid, or always */ char titleFormat[MAX_TITLE_FORMAT_LEN]; char helpFontNames[NUM_HELP_FONTS][MAX_FONT_LEN];/* fonts for help system */ char helpLinkColor[MAX_COLOR_LEN]; /* Color for hyperlinks in the help system */ char colorNames[NUM_COLORS][MAX_COLOR_LEN]; int undoModifiesSelection;} PrefData;/* Temporary storage for preferences strings which are discarded after being read */static struct { char *shellCmds; char *macroCmds; char *bgMenuCmds; char *highlight; char *language; char *styles; char *smartIndent; char *smartIndentCommon;} TempStringPrefs;/* preference descriptions for SavePreferences and RestorePreferences. */static PrefDescripRec PrefDescrip[] = { {"fileVersion", "FileVersion" , PREF_STRING, "", PrefData.fileVersion, (void *)sizeof(PrefData.fileVersion), True},#ifndef VMS#ifdef linux {"shellCommands", "ShellCommands", PREF_ALLOC_STRING, "spell:Alt+B:s:EX:\n\ cat>spellTmp; xterm -e ispell -x spellTmp; cat spellTmp; rm spellTmp\n\ wc::w:ED:\nwc | awk '{print $1 \" lines, \" $2 \" words, \" $3 \" characters\"}'\n\ sort::o:EX:\nsort\nnumber lines::n:AW:\nnl -ba\nmake:Alt+Z:m:W:\nmake\n\ expand::p:EX:\nexpand\nunexpand::u:EX:\nunexpand\n", &TempStringPrefs.shellCmds, NULL, True},#elif __FreeBSD__ {"shellCommands", "ShellCommands", PREF_ALLOC_STRING, "spell:Alt+B:s:EX:\n\ cat>spellTmp; xterm -e ispell -x spellTmp; cat spellTmp; rm spellTmp\n\ wc::w:ED:\nwc | awk '{print $2 \" lines, \" $1 \" words, \" $3 \" characters\"}'\n\ sort::o:EX:\nsort\nnumber lines::n:AW:\npr -tn\nmake:Alt+Z:m:W:\nmake\n\ expand::p:EX:\nexpand\nunexpand::u:EX:\nunexpand\n", &TempStringPrefs.shellCmds, NULL, True},#else {"shellCommands", "ShellCommands", PREF_ALLOC_STRING, "spell:Alt+B:s:ED:\n\ (cat;echo \"\") | spell\nwc::w:ED:\nwc | awk '{print $1 \" lines, \" $2 \" words, \" $3 \" characters\"}'\n\ \nsort::o:EX:\nsort\nnumber lines::n:AW:\nnl -ba\nmake:Alt+Z:m:W:\nmake\n\ expand::p:EX:\nexpand\nunexpand::u:EX:\nunexpand\n", &TempStringPrefs.shellCmds, NULL, True},#endif /* linux, __FreeBSD__ */#endif /* VMS */ {"macroCommands", "MacroCommands", PREF_ALLOC_STRING, "Complete Word:Alt+D::: {\n\ # Tuning parameters\n\ ScanDistance = 200\n\ \n\ # Search back to a word boundary to find the word to complete\n\ startScan = max(0, $cursor - ScanDistance)\n\ endScan = min($text_length, $cursor + ScanDistance)\n\ scanString = get_range(startScan, endScan)\n\ keyEnd = $cursor-startScan\n\ keyStart = search_string(scanString, \"<\", keyEnd, \"backward\", \"regex\")\n\ if (keyStart == -1)\n\ return\n\ keyString = \"<\" substring(scanString, keyStart, keyEnd)\n\ \n\ # search both forward and backward from the cursor position. Note that\n\ # using a regex search can lead to incorrect results if any of the special\n\ # regex characters is encountered, which is not considered a delimiter\n\ backwardSearchResult = search_string(scanString, keyString, keyStart-1, \\\n\ \"backward\", \"regex\")\n\ forwardSearchResult = search_string(scanString, keyString, keyEnd, \"regex\")\n\ if (backwardSearchResult == -1 && forwardSearchResult == -1) {\n\ beep()\n\ return\n\ }\n\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -