1
1

* edit/choosesyntax.c: Create file. Menu option to override syntax

highlighting.
* edit/Makefile.am: Add choosesyntax.c.
* edit/edit.c (edit_init): Set option_auto_syntax to 1 on every invokation
of the editor.
* edit/edit.h: Pass char*** to edit_load_syntax(). Add parameters for
syntax dialog and override.
* edit/editmenu.c (menu_options): Add menu option to override syntax
hightlighting.
* edit/editoptions.c (edit_options_dialog): Pass option_syntax_type to
edit_load_syntax().
* edit/syntax.c (edit_read_syntax_file): Dynamically allocate and fill
syntax list pnames.
* edit/syntax.c (edit_load_syntax): Use char*** for syntax list.
* src/wtools.h: #include "widget.h" and remove redundant declarations
of Dlg_head and WListbox.
Этот коммит содержится в:
Leonard den Ottolander 2005-07-24 13:37:58 +00:00
родитель 9ad35c9daa
Коммит f21564b9e6
11 изменённых файлов: 161 добавлений и 15 удалений

Просмотреть файл

@ -1,3 +1,20 @@
2005-07-27 Leonard den Ottolander <leonard den ottolander nl>
* choosesyntax.c: Create file. Menu option to override syntax
highlighting.
* Makefile.am: Add choosesyntax.c..
* edit.c (edit_init): Set option_auto_syntax to 1 on every invokation
of the editor.
* edit.h: Pass char*** to edit_load_syntax(). Add parameters for
syntax dialog and override.
* editmenu.c (menu_options): Add menu option to override syntax
highlighting.
* editoptions.c (edit_options_dialog): Pass option_syntax_type to
edit_load_syntax().
* syntax.c (edit_read_syntax_file): Dynamically allocate and fill
syntax list pnames.
* syntax.c (edit_load_syntax): Use char*** for syntax list.
2005-05-21 Pavel Roskin <proski@gnu.org>
* Makefile.am: Add usermap.h to the sources.

Просмотреть файл

@ -9,6 +9,7 @@ endif
libedit_a_SOURCES = \
bookmark.c edit.c editcmd.c editwidget.c editdraw.c editkeys.c \
editmenu.c editoptions.c editcmddef.h edit.h edit-widget.h \
editlock.c editlock.h syntax.c usermap.h usermap.c wordproc.c
editlock.c editlock.h syntax.c usermap.h usermap.c wordproc.c \
choosesyntax.c
EXTRA_DIST = ChangeLog

95
edit/choosesyntax.c Обычный файл
Просмотреть файл

@ -0,0 +1,95 @@
/* User interface for syntax selection.
Copyright (C) 2005 Leonard den Ottolander <leonard den ottolander nl>
This program 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 program 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 this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include "edit.h"
#include "../src/global.h"
#include "../src/wtools.h"
#define MAX_ENTRY_LEN 40
#define LIST_LINES 14
#define N_DFLT_ENTRIES 1
int
exec_edit_syntax_dialog (const char **names) {
int i;
Listbox *syntaxlist = create_listbox_window (MAX_ENTRY_LEN, LIST_LINES,
N_(" Choose syntax highlighting "), NULL);
LISTBOX_APPEND_TEXT (syntaxlist, 'A', N_("< Auto >"), NULL);
for (i = 0; names[i]; i++) {
LISTBOX_APPEND_TEXT (syntaxlist, 0, names[i], NULL);
if (! option_auto_syntax && option_syntax_type &&
(strcmp (names[i], option_syntax_type) == 0))
listbox_select_by_number (syntaxlist->list, i + N_DFLT_ENTRIES);
}
return run_listbox (syntaxlist);
}
void
edit_syntax_dialog (void) {
char *old_syntax_type;
int old_auto_syntax, syntax;
char **names;
int i;
names = (char**) g_malloc (sizeof (char*));
names[0] = NULL;
/* We fill the list of syntax files every time the editor is invoked.
Instead we could save the list to a file and update it once the syntax
file gets updated (either by testing or by explicit user command). */
edit_load_syntax (NULL, &names, NULL);
if ((syntax = exec_edit_syntax_dialog ((const char**) names)) < 0) {
for (i = 0; names[i]; i++) {
g_free (names[i]);
}
g_free (names);
return;
}
old_auto_syntax = option_auto_syntax;
old_syntax_type = g_strdup (option_syntax_type);
/* Using a switch as we might want to define more specific commands, f.e.
"Refill syntax list" (compare N_DFLT_ENTRIES). */
switch (syntax) {
case 0: /* auto syntax */
option_auto_syntax = 1;
break;
default:
option_auto_syntax = 0;
g_free (option_syntax_type);
option_syntax_type = g_strdup (names[syntax - N_DFLT_ENTRIES]);
}
/* Load or unload syntax rules if the option has changed */
if (option_auto_syntax && !old_auto_syntax || old_auto_syntax ||
old_syntax_type && option_syntax_type &&
(strcmp (old_syntax_type, option_syntax_type) != 0))
edit_load_syntax (wedit, NULL, option_syntax_type);
for (i = 0; names[i]; i++) {
g_free (names[i]);
}
g_free (names);
g_free (old_syntax_type);
}

Просмотреть файл

@ -493,6 +493,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename,
long line)
{
int to_free = 0;
option_auto_syntax = 1; /* Resetting to auto on every invokation */
if (!edit) {
#ifdef ENABLE_NLS

Просмотреть файл

@ -208,7 +208,7 @@ void edit_paste_from_history (WEdit *edit);
void edit_set_filename (WEdit *edit, const char *name);
void edit_load_syntax (WEdit * edit, char **names, const char *type);
void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
void edit_free_syntax_rules (WEdit * edit);
void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
@ -226,6 +226,7 @@ int line_is_blank (WEdit *edit, long line);
int edit_indent_width (WEdit *edit, long p);
void edit_insert_indent (WEdit *edit, int indent);
void edit_options_dialog (void);
void edit_syntax_dialog (void);
void edit_mail_dialog (WEdit *edit);
void format_paragraph (WEdit *edit, int force);
@ -281,6 +282,8 @@ extern int option_save_position;
extern int option_backup_ext_int;
extern int option_max_undo;
extern int option_syntax_highlighting;
extern int option_auto_syntax;
extern char *option_syntax_type;
extern int editor_option_check_nl_at_eof;
extern int option_edit_right_extreme;

Просмотреть файл

@ -527,7 +527,7 @@ edit_save_as_cmd (WEdit *edit)
edit->modified = 0;
edit->delete_file = 0;
if (different_filename)
edit_load_syntax (edit, 0, 0);
edit_load_syntax (edit, NULL, option_syntax_type);
edit->force |= REDRAW_COMPLETELY;
return 1;
} else {

Просмотреть файл

@ -280,6 +280,13 @@ menu_options (void)
{
edit_options_dialog ();
}
static void
menu_syntax (void)
{
edit_syntax_dialog ();
}
static void
menu_user_menu_cmd (void)
{
@ -402,7 +409,8 @@ static menu_entry OptMenu[] =
{
{' ', N_("&General... "), 'G', menu_options},
{' ', N_("&Save mode..."), 'S', menu_save_mode_cmd},
{' ', N_("learn &Keys..."), 'K', learn_keys}
{' ', N_("Learn &Keys..."), 'K', learn_keys},
{' ', N_("Syntax &Highlighting..."), 'H', menu_syntax}
};
#define OptMenuEmacs OptMenu

Просмотреть файл

@ -221,7 +221,7 @@ edit_options_dialog (void)
/* Load or unload syntax rules if the option has changed */
if (option_syntax_highlighting != old_syntax_hl)
edit_load_syntax (wedit, 0, 0);
edit_load_syntax (wedit, NULL, option_syntax_type);
/* Load usermap if it's needed */
edit_load_user_map (wedit);
}

Просмотреть файл

@ -98,6 +98,8 @@ struct _syntax_marker {
};
int option_syntax_highlighting = 1;
int option_auto_syntax = 1;
char *option_syntax_type = NULL;
#define syntax_g_free(x) do {g_free(x); (x)=0;} while (0)
@ -968,10 +970,13 @@ void edit_free_syntax_rules (WEdit * edit)
/* returns -1 on file error, line number on error in file syntax */
static int
edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
const char *editor_file, const char *first_line,
const char *type)
{
/* Using a low value for NENTRIES for testing purposes. NENTRIES should be set
to a more sensible value (30 - 100) before the release of 4.6.2. (leonardjo) */
#define NENTRIES 3
FILE *f, *g = NULL;
regex_t r;
regmatch_t pmatch[1];
@ -982,6 +987,7 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
int count = 0;
char *lib_file;
int found = 0;
char **tmpnames = NULL;
f = fopen (syntax_file, "r");
if (!f){
@ -1020,10 +1026,18 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
result = line;
break;
}
if (names) {
if (pnames && *pnames) {
/* 1: just collecting a list of names of rule sets */
names[count++] = g_strdup (args[2]);
names[count] = 0;
/* Reallocate the list if required */
if (count % NENTRIES == 0) {
if ((tmpnames = (char**) g_realloc (*pnames, (count + NENTRIES
+ 1) * sizeof (char*))) != NULL)
*pnames = tmpnames;
else
abort ();
}
(*pnames)[count++] = g_strdup (args[2]);
(*pnames)[count] = NULL;
} else if (type) {
/* 2: rule set was explicitly specified by the caller */
if (!strcmp (type, args[2]))
@ -1101,22 +1115,25 @@ static char *get_first_editor_line (WEdit * edit)
}
/*
* Load rules into edit struct. Either edit or names must be NULL. If
* Load rules into edit struct. Either edit or *pnames must be NULL. If
* edit is NULL, a list of types will be stored into names. If type is
* NULL, then the type will be selected according to the filename.
*/
void
edit_load_syntax (WEdit *edit, char **names, const char *type)
edit_load_syntax (WEdit *edit, char ***pnames, const char *type)
{
int r;
char *f = NULL;
if (option_auto_syntax)
type = NULL;
edit_free_syntax_rules (edit);
if (!use_colors)
return;
if (!option_syntax_highlighting)
if (!option_syntax_highlighting && (!pnames || !*pnames))
return;
if (edit) {
@ -1126,7 +1143,7 @@ edit_load_syntax (WEdit *edit, char **names, const char *type)
return;
}
f = concat_dir_and_file (home_dir, SYNTAX_FILE);
r = edit_read_syntax_file (edit, names, f, edit ? edit->filename : 0,
r = edit_read_syntax_file (edit, pnames, f, edit ? edit->filename : 0,
get_first_editor_line (edit), type);
if (r == -1) {
edit_free_syntax_rules (edit);

Просмотреть файл

@ -1,3 +1,8 @@
2005-07-23 Leonard den Ottolander <leonard den ottolander nl>
* wtools.h: #include "widget.h" and remove redundant declarations
of Dlg_head and WListbox;
2005-07-23 Roland Illig <roland.illig@gmx.de>
* util.c (save_file_position): Only save the position if not

Просмотреть файл

@ -1,8 +1,7 @@
#ifndef MC_WTOOLS_H
#define MC_WTOOLS_H
struct Dlg_head;
struct WListbox;
#include "widget.h"
typedef struct {
struct Dlg_head *dlg;