Copy all necessary files from gtkedit.

* Makefile.in (EDITLINKS): Merge with EDITSRC, remove all
references.
This commit is contained in:
Pavel Roskin 2001-08-24 18:23:17 +00:00
parent 52091c422d
commit b44a4e19c6
14 changed files with 12374 additions and 10 deletions

342
edit/ChangeLog Normal file
View File

@ -0,0 +1,342 @@
2001-08-24 Pavel Roskin <proski@gnu.org>
Copy all necessary files from gtkedit.
* Makefile.in (EDITLINKS): Merge with EDITSRC, remove all
references.
2001-08-24 Pavel Roskin <proski@gnu.org>
* syntax.c (syntax_text): Fix recognizing pdksh and zsh scripts.
2001-08-23 Pavel Roskin <proski@gnu.org>
* editcmd.c (edit_block_process_cmd): Use execute(), not
my_system() to relieve interactive scripts, such as spell
checker, from saving and restoring the terminal.
2001-08-19 Pavel Roskin <proski@gnu.org>
* gtkedit.c: Include <sys/param.h> if present - it should always
be included before <glib.h> to avoid redefining MIN and MAX.
* editcmd.c [!MIDNIGHT]: Undefine B_ENTER and B_CANCEL before
redefining them.
* edit.h: Include <sys/param.h> if present. Include Gtk+
headers as system headers.
* gtkedit.c: Include Gtk+ headers as system headers.
2001-08-18 Pavel Roskin <proski@gnu.org>
* syntax.c (syntax_text): Highlight *.pot as PO files.
* edit.h [GTK]: Fix definition of edit_message_dialog().
* gtkedit.c (gtk_edit_dialog_message): Use "OK" button, not
"Cancel", for consistency with the text edition.
2001-08-17 Pavel Roskin <proski@gnu.org>
* syntax.c (syntax_text): Add support for PO files.
2001-08-12 Pavel Roskin <proski@gnu.org>
* edit.c: Handle CK_Shell.
* editcmddef.h: Define CK_Shell.
* editmenu.c (FileMenu): Remove C-o from the "Open file..."
item.
(FileMenuEmacs): Likewise.
2001-08-06 Andrew V. Samoilov <kai@cmail.ru>
* editcmd.c (edit_replace_prompt): Fix menu location calculation.
2001-08-01 Pavel Roskin <proski@gnu.org>
* editcmd.c (edit_save_file): Temporarily disable safe save
and backups on remote VFS because it doesn't work. Use
mc_mkstemps() instead of tempnam().
2001-07-29 Pavel Roskin <proski@gnu.org>
* syntax.c (syntax_text): Add support for S-Lang.
2001-07-28 Pavel Roskin <proski@gnu.org>
* editcmd.c (menu_save_mode_cmd): Resurrect i18n code lost in
the last resync with Cooledit.
Reported by David Martin <dmartina@excite.es>
* gtkedit.c (gtk_edit_delete_cb): Handler for "delete_event".
(edit): Connect it.
2001-07-27 Pavel Roskin <proski@gnu.org>
* edit.c: Fix include.
2001-07-20 Pavel Roskin <proski@gnu.org>
* syntax.c (open_include_file) [GTK]: Use mc_home instead of
LIBDIR.
2001-07-19 Pavel Roskin <proski@gnu.org>
* editcmd.c (edit_canonicalize_pathname): Don't ever use
getwd(), use g_get_current_dir() instead.
* editoptions.c (edit_options_dialog): Call edit_load_syntax()
if user turned syntax highlighting off to unload the rules.
2001-07-17 Pavel Roskin <proski@gnu.org>
* edit.h [MIDNIGHT]: Declare wedit.
* editmenu.c: Remove wedit declaration.
* editoptions.c (edit_options_dialog): Load syntax rules if user
turned syntax highlighting on.
* syntax.c (edit_load_syntax): Don't load rules if syntax
highlighting is disabled.
2001-07-13 Pavel Roskin <proski@gnu.org>
* editoptions.c (edit_options_dialog): Allow numbers for tab
spacing. Reported by mharris@redhat.com.
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=34852
* editcmd.c (menu_save_mode_cmd): Give meaningful names to the
input fields instead of "i" so that they have separate history.
* editoptions.c (edit_options_dialog): Likewise.
2001-07-11 Pavel Roskin <proski@gnu.org>
* editdraw.c (status_string): Use g_snprintf() instead of
snprintf().
From Libor Motyèka <l_motycka@ortex.cz>
2001-07-10 Pavel Roskin <proski@gnu.org>
* gtkeditkey.c (edit_translate_key): When processing bindings
with Alt check that Shift is not pressed - it's handled later.
2001-07-05 Pavel Roskin <proski@gnu.org>
* editdraw.c: Comment fixes.
2001-06-26 Pavel Roskin <proski@gnu.org>
* edit-widget.h (editor_widget): Rename `stat' to `stat1' to
avoid problems on Solaris with 64-bit file access, when `stat'
is a macro. All users adjusted.
Reported by Maksym Polyakov <polyama@yahoo.com>.
2001-06-25 Pavel Roskin <proski@gnu.org>
* gtkedit.c: Remove home_dir - it's declared in main.c.
2001-06-15 Pavel Roskin <proski@gnu.org>
* editcmd.c (canonicalize_pathname) [GTK]: Rename to ...
(edit_canonicalize_pathname): ... this to avoid namespace clash.
* edit.h [MIDNIGHT]: Include "src/cmd.h" and "src/user.h".
Remove declarations duplicating "src/user.h".
[GTK]: Include "src/dialog.h" and "src/util.h".
* editmenu.c (edit_wrap_cmd): Fix declaration.
(edit_about_cmd): Likewise.
* editwidget.c (get_key_state): Likewise.
* editcmd.c (edit_quit_cmd): Don't use strcmp on the result of
gtk_dialog_cauldron() since it's NULL if the dialog has been
closed without using buttons.
* edit.c (edit_execute_cmd): Put time format to a variable to
avoid gcc warning about Y2K issues with %c in strftime().
2001-06-14 Pavel Roskin <proski@gnu.org>
* edit.c: Declare cmd_F* static. Comment out cmd_F9.
* edit.c: Use indented #error for compatibility with old C
compilers.
2001-06-13 Pavel Roskin <proski@gnu.org>
* edit.c (edit_execute_cmd) [GTK]: Disable user menu - it
doesn't work.
(user_menu) [GTK]: Disable.
* gtkedit.c (tb_items): Use complete words. Disable pull-down
menu.
2001-06-09 Pavel Roskin <proski@gnu.org>
* editcmd.c (catstrs): Use interactive_display() without
specifying the help file.
From Andrew V. Samoilov.
2001-06-08 Andrew V. Samoilov <sav@bcs.zp.ua>
* editcmd.c [HAVE_CHARSET]: Really include charset.h.
* editmenu.c (edit_wrap_cmd): Memory leaking fixed.
2001-06-05 Pavel Roskin <proski@gnu.org>
* edit.c [HAVE_CHARSET]: Include charsets.h and selcodepage.h.
* editcmd.c [HAVE_CHARSET]: Add charset conversion support.
* editdraw.c [HAVE_CHARSET]: Likewise.
From Walery Studennikov <hqsoftware@mail.ru>.
2001-06-01 Pavel Roskin <proski@gnu.org>
* gtkedit.h: Warning fix - use stricter declarations for
destroy_me and destroy_me_user_data.
2001-05-31 Pavel Roskin <proski@gnu.org>
* Makefile.in: Define HAVE_X and HAVE_GNOME, not just GTK -
header files are using them.
* editdraw.c (edit_render) [GTK]: Revert previous patch, it
broke compilation.
2001-05-31 Andrew V. Samoilov <sav@bcs.zp.ua>
* editdraw.c (edit_status): Use strcpy (s, ) instead of
sprintf (s, "%s", ).
(set_color) [MIDNIGHT]: Became a macro.
(render_edit_text) [defined(MIDNIGHT) || defined(GTK)]: Warning fix.
(edit_render) [GTK]: Eliminate win variable.
(key_pending) [!GTK]: Warning fix.
2001-05-30 Pavel Roskin <proski@gnu.org>
* editdraw.c (status_string): Use is_printable(). Declare
static. Eliminate intermediate buffer. Use memset() for filling.
Print byte as unsigned. Use C notation for hex numbers.
* editdraw.c (status_string): Don't print non-printable chars.
Better formatting. Print "<EOF>" at the end of file instead of
-1. Use snprintf instead of sprintf.
2001-05-30 Andrew V. Samoilov <sav@bcs.zp.ua>
* syntax.c (open_include_file) [MIDNIGHT]: Don't hardcode location
of syntax file(s) with LIBDIR, use mc_home instead.
From Ludovic Drolez <ludovic.drolez@freealter.com>.
(syntax_text): Use perl.syntax to highlight perl modules (.pm).
2001-05-18 Pavel Roskin <proski@gnu.org>
* editcmd.c (edit_replace_prompt): Warning fix.
2001-02-26 Pavel Roskin <proski@gnu.org>
* editcmd.c (edit_delete_macro_cmd) [MIDNIGHT]: Don't use
CK_Macro on the argument to edit_delete_macro().
* edit.c (edit_init_file): Remove, it's useless. All the
necessary files should be created when needed.
* edit.h: Remove declaration of edit_init_file().
2000-11-01 Andrew V. Samoilov <sav@bcs.zp.ua>
* editcmd.c (canonicalize_pathname) [GTK]: memory leaking fixed
2000-10-30 Pavel Roskin <proski@gnu.org>
* editcmd.c (canonicalize_pathname) [GTK]: Make the argument
constant.
(edit_split_filename) [GTK]: Make the second argument constant
to match the declaration.
2000-10-30 Andrew V. Samoilov <sav@bcs.zp.ua>
* editcmd.c (edit_save_file): better error handling on writting
(edit_sort_cmd): saved sort options proposed in dialog
edit.h, editcmd.c: declaration for edit_save_block () added
(edit_split_filename): f constified
* edit.c (edit_init) [ENABLE_NLS]: option_whole_chars_search
expanded by national letters using current locale on first call
(edit_file_is_open) [MIDNIGHT]: all occurences and related code
are commented
(edit_execute_cmd): typo in error message fixed
2000-09-30 Pavel Roskin <proski@gnu.org>
* libgettext.h: Removed, shouldn't be here.
* Makefile.in: Adjusted to remove libgettext.h
2000-09-15 Andrew V. Samoilov <sav@bcs.zp.ua>
* editcmd.c (edit_delete_macro, edit_(load|save)_macro_cmd): don't
translate keywords written to macro file or macro don't work, at least
for Cyrillic. Made this as separate commit, so, if it seriously breaks
compatibility it's easy to revert it.
2000-09-15 Andrew V. Samoilov <sav@bcs.zp.ua>
* editcmd.c (edit_save_file): fopen()+fwrite()+fclose() replaced
by open()+write()+close() to restore possibility to edit files
over Midnight Commander's VFSes
(edit_replace_cmd) [MIDNIGHT]: some more right algorithm to calculate
menu coordinates used. I don't like if menu hides replaced text.
(edit_goto_cmd): Memory leaking fixed when f is empty string
2000-09-07 Andrew V. Samoilov <sav@bcs.zp.ua>
* edit.c (check_file_access) [MIDNIGHT,GTK]: error message localized;
some cosmetics changes to avoid annoying warnings
* editcmd.c (edit_save_file): pclose returns 0 on success,
file fclose()d when fwrite fails
(pipe_mail): malloc () + sprintf () replaced by g_strdup_printf ()
* syntax.c (syntax_text): Makefile replaced by [Mm]akefile to cover
makefile and GNUmakefile
(upgrade_syntax_file): infinitive loop fixed when rule file
is outdated but it cannot be unlinked/overwritten
2000-08-30 Pavel Roskin <proski@gnu.org>
* editwidget.c [!MIDNIGHT]: include xdnd.h
* Makefile.in: distribute xdnd.h
2000-08-18 Pavel Roskin <proski@gnu.org>
* Makefile.in: adjusted list of distributed files.
Added rule for rebuilding Makefile
2000-08-08 Pavel Roskin <proski@gnu.org>
* gtkedit.c [GTK]: don't include mousemark.h
* gtkedit.h [GTK]: likewise
2000-08-03 Pavel Roskin <proski@gnu.org>
* mousemark.c, mousemark.h: removed
* Makefile.in: don't distribute mousemark.h
* gtkedit.c [MIDNIGHT]: don't include mousemark.h
* gtkedit.h [MIDNIGHT]: likewise
2000-07-20 Andrew V. Samoilov <sav@bcs.zp.ua>
* gtkedit/editcmd.c (edit_save_file): check fclose()s return value
to prevent loss of data
(edit_block_process_cmd): don't translate empty string
* gtkedit/edit.h (edit_get_write_filter, edit_write_stream,
edit_init_file): added declarations
* edit.c (edit_filters): constified
(edit_get_write_filter): filename constified
(user_menu): don't translate empty string
* syntax.c (syntax_text): constified
(upgrade_syntax_file): syntax_line constified, f closed after use

View File

@ -21,10 +21,9 @@ AR = @AR@
# Distribution variables
#
EDITSRC = edit_key_translator.c
EDITLINKS = edit.c editcmd.c editwidget.c editdraw.c editmenu.c wordproc.c \
syntax.c editoptions.c bookmark.c
EDITSRC = edit_key_translator.c edit.c editcmd.c editwidget.c \
editdraw.c editmenu.c wordproc.c syntax.c editoptions.c \
bookmark.c
EDITOBJS = edit.o editcmd.o editwidget.o editdraw.o editmenu.o wordproc.o \
syntax.o editoptions.o bookmark.o
@ -44,11 +43,6 @@ edit.o: edit_key_translator.c
check:
@echo no tests are supplied.
$(EDITLINKS):
for i in $(EDITLINKS); do \
$(LN_S) $(top_srcdir)/gtkedit/$$i . || exit 1; \
done
libedit.a: $(EDITOBJS)
rm -f libedit.a
$(AR) cr libedit.a $(EDITOBJS)
@ -68,7 +62,6 @@ clean: mostlyclean
rm -f libedit.a
distclean: clean
rm -f $(EDITLINKS)
rm -f TAGS
rm -f *~
rm -f Makefile

251
edit/bookmark.c Normal file
View File

@ -0,0 +1,251 @@
/* editor book mark handling
Copyright (C) 1996, 1997 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#include <config.h>
#include "edit.h"
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
/* note, if there is more than one bookmark on a line, then they are
appended after each other and the last one is always the one found
by book_mark_found() i.e. last in is the one seen */
static inline struct _book_mark *double_marks (WEdit * edit, struct _book_mark *p)
{
if (p->next)
while (p->next->line == p->line)
p = p->next;
return p;
}
/* returns the first bookmark on or before this line */
struct _book_mark *book_mark_find (WEdit * edit, int line)
{
struct _book_mark *p;
if (!edit->book_mark) {
/* must have an imaginary top bookmark at line -1 to make things less complicated */
edit->book_mark = malloc (sizeof (struct _book_mark));
memset (edit->book_mark, 0, sizeof (struct _book_mark));
edit->book_mark->line = -1;
return edit->book_mark;
}
for (p = edit->book_mark; p; p = p->next) {
if (p->line > line)
break; /* gone past it going downward */
if (p->line <= line) {
if (p->next) {
if (p->next->line > line) {
edit->book_mark = p;
return double_marks (edit, p);
}
} else {
edit->book_mark = p;
return double_marks (edit, p);
}
}
}
for (p = edit->book_mark; p; p = p->prev) {
if (p->next)
if (p->next->line <= line)
break; /* gone past it going upward */
if (p->line <= line) {
if (p->next) {
if (p->next->line > line) {
edit->book_mark = p;
return double_marks (edit, p);
}
} else {
edit->book_mark = p;
return double_marks (edit, p);
}
}
}
return 0; /* can't get here */
}
/* returns true if a bookmark exists at this line of colour c */
int book_mark_query_color (WEdit * edit, int line, int c)
{
struct _book_mark *p;
if (!edit->book_mark)
return 0;
for (p = book_mark_find (edit, line); p; p = p->prev) {
if (p->line != line)
return 0;
if (p->c == c)
return 1;
}
return 0;
}
/* returns the number of bookmarks at this line and a list of their colours in c
up to a maximum of 8 colours */
int book_mark_query_all (WEdit * edit, int line, int *c)
{
int i;
struct _book_mark *p;
if (!edit->book_mark)
return 0;
for (i = 0, p = book_mark_find (edit, line); p && i < 8; p = p->prev, i++) {
if (p->line != line)
return i;
c[i] = p->c;
}
return i;
}
/* insert a bookmark at this line */
void book_mark_insert (WEdit * edit, int line, int c)
{
struct _book_mark *p, *q;
p = book_mark_find (edit, line);
#if 0
if (p->line == line) { /* already exists, so just change the colour */
if (p->c != c) {
edit->force |= REDRAW_LINE;
p->c = c;
}
return;
}
#endif
edit->force |= REDRAW_LINE;
/* create list entry */
q = malloc (sizeof (struct _book_mark));
memset (q, 0, sizeof (struct _book_mark));
q->line = line;
q->c = c;
q->next = p->next;
/* insert into list */
q->prev = p;
if (p->next)
p->next->prev = q;
p->next = q;
#if !defined (GTK) && !defined (MIDNIGHT)
render_scrollbar (edit->widget->vert_scrollbar);
#endif
}
/* remove a bookmark if there is one at this line matching this colour - c of -1 clear all */
/* returns non-zero on not-found */
int book_mark_clear (WEdit * edit, int line, int c)
{
struct _book_mark *p, *q;
int r = 1;
int rend = 0;
if (!edit->book_mark)
return r;
for (p = book_mark_find (edit, line); p; p = q) {
q = p->prev;
if (p->line == line && (p->c == c || c == -1)) {
r = 0;
edit->force |= REDRAW_LINE;
edit->book_mark = p->prev;
p->prev->next = p->next;
if (p->next)
p->next->prev = p->prev;
rend = 1;
free (p);
break;
}
}
/* if there is only our dummy book mark left, clear it for speed */
if (edit->book_mark->line == -1 && !edit->book_mark->next) {
free (edit->book_mark);
edit->book_mark = 0;
}
#if !defined (GTK) && !defined (MIDNIGHT)
if (rend)
render_scrollbar (edit->widget->vert_scrollbar);
#endif
return r;
}
/* clear all bookmarks matching this colour, if c is -1 clears all */
void book_mark_flush (WEdit * edit, int c)
{
struct _book_mark *p, *q;
int rend = 0;
if (!edit->book_mark)
return;
edit->force |= REDRAW_PAGE;
while (edit->book_mark->prev)
edit->book_mark = edit->book_mark->prev;
for (q = edit->book_mark->next; q; q = p) {
p = q->next;
if (q->c == c || c == -1) {
q->prev->next = q->next;
if (p)
p->prev = q->prev;
rend = 1;
free (q);
}
}
if (!edit->book_mark->next) {
free (edit->book_mark);
edit->book_mark = 0;
}
#if !defined (GTK) && !defined (MIDNIGHT)
if (rend)
render_scrollbar (edit->widget->vert_scrollbar);
#endif
}
/* shift down bookmarks after this line */
void book_mark_inc (WEdit * edit, int line)
{
int rend = 0;
if (edit->book_mark) {
struct _book_mark *p;
p = book_mark_find (edit, line);
for (p = p->next; p; p = p->next) {
p->line++;
rend = 1;
}
}
#if !defined (GTK) && !defined (MIDNIGHT)
if (rend)
render_scrollbar (edit->widget->vert_scrollbar);
#endif
}
/* shift up bookmarks after this line */
void book_mark_dec (WEdit * edit, int line)
{
int rend = 0;
if (edit->book_mark) {
struct _book_mark *p;
p = book_mark_find (edit, line);
for (p = p->next; p; p = p->next) {
p->line--;
rend = 1;
}
}
#if !defined (GTK) && !defined (MIDNIGHT)
if (rend)
render_scrollbar (edit->widget->vert_scrollbar);
#endif
}

144
edit/edit-widget.h Normal file
View File

@ -0,0 +1,144 @@
#ifndef __EDIT_WIDGET_H
#define __EDIT_WIDGET_H
struct macro {
short command;
short ch;
};
struct syntax_rule {
unsigned short keyword;
unsigned char end;
unsigned char context;
unsigned char _context;
#define RULE_ON_LEFT_BORDER 1
#define RULE_ON_RIGHT_BORDER 2
unsigned char border;
};
/*there are a maximum of ... */
#define MAXBUFF 1024
#define MAX_MACRO_LENGTH 1024
struct _syntax_marker {
long offset;
struct syntax_rule rule;
struct _syntax_marker *next;
};
struct _book_mark {
int line; /* line number */
/* #define BOOK_MARK_COLOR ((0 << 8) | 26) */ /* black on white */
#define BOOK_MARK_COLOR ((25 << 8) | 5)
#define BOOK_MARK_FOUND_COLOR ((26 << 8) | 4)
int c; /* colour */
struct _book_mark *next;
struct _book_mark *prev;
};
struct editor_widget {
#ifdef MIDNIGHT
Widget widget;
#elif defined(GTK)
GtkEdit *widget;
#else
struct cool_widget *widget;
#endif
#define from_here num_widget_lines
int num_widget_lines;
int num_widget_columns;
#ifdef MIDNIGHT
int have_frame;
#else
int stopped;
#endif
char *filename; /* Name of the file */
char *dir; /* current directory */
/* dynamic buffers and cursor position for editor: */
long curs1; /*position of the cursor from the beginning of the file. */
long curs2; /*position from the end of the file */
unsigned char *buffers1[MAXBUFF + 1]; /*all data up to curs1 */
unsigned char *buffers2[MAXBUFF + 1]; /*all data from end of file down to curs2 */
/* search variables */
long search_start; /* First character to start searching from */
int found_len; /* Length of found string or 0 if none was found */
long found_start; /* the found word from a search - start position */
/* display information */
long last_byte; /* Last byte of file */
long start_display; /* First char displayed */
long start_col; /* First displayed column, negative */
long max_column; /* The maximum cursor position ever reached used to calc hori scroll bar */
long curs_row; /*row position of cursor on the screen */
long curs_col; /*column position on screen */
int force; /* how much of the screen do we redraw? */
unsigned char overwrite;
unsigned char modified; /*has the file been changed?: 1 if char inserted or
deleted at all since last load or save */
unsigned char screen_modified; /* has the file been changed since the last screen draw? */
#if defined(MIDNIGHT) || defined(GTK)
int delete_file; /* has the file been created in edit_load_file? Delete
it at end of editing when it hasn't been modified
or saved */
#endif
unsigned char highlight;
long prev_col; /*recent column position of the cursor - used when moving
up or down past lines that are shorter than the current line */
long curs_line; /*line number of the cursor. */
long start_line; /*line nummber of the top of the page */
/* file info */
long total_lines; /*total lines in the file */
long mark1; /*position of highlight start */
long mark2; /*position of highlight end */
int column1; /*position of column highlight start */
int column2; /*position of column highlight end */
long bracket; /*position of a matching bracket */
/* cache speedup for line lookups */
#define N_LINE_CACHES 32
int caches_valid;
int line_numbers[N_LINE_CACHES];
long line_offsets[N_LINE_CACHES];
struct _book_mark *book_mark;
/* undo stack and pointers */
unsigned long stack_pointer;
long *undo_stack;
unsigned long stack_size;
unsigned long stack_size_mask;
unsigned long stack_bottom;
struct stat stat1;
/* syntax higlighting */
struct _syntax_marker *syntax_marker;
struct context_rule **rules;
long last_get_rule;
struct syntax_rule rule;
char *syntax_type; /* description of syntax highlighting type being used */
int explicit_syntax; /* have we forced the syntax hi. type in spite of the filename? */
int to_here; /* dummy marker */
/* macro stuff */
int macro_i; /* -1 if not recording index to macro[] otherwise */
struct macro macro[MAX_MACRO_LENGTH];
};
typedef struct editor_widget WEdit;
#define EDIT_DIR "/.cedit"
#define SYNTAX_FILE "/.cedit/Syntax"
#define CLIP_FILE "/.cedit/cooledit.clip"
#define MACRO_FILE "/.cedit/cooledit.macros"
#define BLOCK_FILE "/.cedit/cooledit.block"
#define ERROR_FILE "/.cedit/cooledit.error"
#define TEMP_FILE "/.cedit/cooledit.temp"
#endif

2812
edit/edit.c Normal file

File diff suppressed because it is too large Load Diff

789
edit/edit.h Normal file
View File

@ -0,0 +1,789 @@
/* edit.h - main include file
Copyright (C) 1996, 1997 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#ifndef __EDIT_H
#define __EDIT_H
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef MIDNIGHT
#ifdef HAVE_SLANG
#define HAVE_SYNTAXH 1
#endif
# include <stdio.h>
# include <stdarg.h>
# include <sys/types.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
# include <string.h>
# include <ctype.h>
# include <errno.h>
# include "src/tty.h"
# include <sys/stat.h>
# include <errno.h>
# include <fcntl.h>
# include <stdlib.h>
# if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
# include <malloc.h>
# endif
#else /* ! MIDNIGHT */
# include "global.h"
# include <stdio.h>
# include <stdarg.h>
# include <sys/types.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
#ifdef GTK
# include <string.h>
#else
# include <my_string.h>
#endif
# include <ctype.h>
# include <errno.h>
# include <sys/stat.h>
# ifdef HAVE_FCNTL_H
# include <fcntl.h>
# endif
# include <stdlib.h>
# include <stdarg.h>
# if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
# include "regex.h"
#endif
#ifndef MIDNIGHT
# include <signal.h>
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# include <X11/Xresource.h>
# include "lkeysym.h"
#ifndef GTK
# include "coolwidget.h"
# include "app_glob.c"
# include "coollocal.h"
# include "stringtools.h"
#else
# include <gtk/gtk.h>
# include <gdk/gdkprivate.h>
# include <gdk/gdk.h>
# include "gtkedit.h"
# include "editcmddef.h"
# ifndef _
# define _(x) x
# define N_(x) x
# endif
#endif
#else
# include "src/global.h"
# include "src/main.h" /* for char *shell */
# include "src/mad.h"
# include "src/dlg.h"
# include "src/widget.h"
# include "src/color.h"
# include "src/dialog.h"
# include "src/mouse.h"
# include "src/help.h"
# include "src/key.h"
# include "src/wtools.h" /* for QuickWidgets */
# include "src/cmd.h" /* for menu_edit_cmd */
# include "src/win.h"
# include "vfs/vfs.h"
# include "src/menu.h"
# include <regex.h>
# define WANT_WIDGETS
# define WIDGET_COMMAND (WIDGET_USER + 10)
# define N_menus 5
#endif
#ifdef GTK
/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
#if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
# include <dirent.h>
# define NLENGTH(dirent) (strlen ((dirent)->d_name))
#else
# define dirent direct
# define NLENGTH(dirent) ((dirent)->d_namlen)
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif /* HAVE_NDIR_H */
#endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
# ifndef _
# define _(x) x
# define N_(x) x
# endif
#include "vfs/vfs.h"
#include "src/dialog.h" /* for input_dialog() */
#include "src/util.h" /* for is_printable() */
# define CDisplay gdk_display
# define CRoot gdk_root_parent
# define Window GtkEdit *
#endif
#define SEARCH_DIALOG_OPTION_NO_SCANF 1
#define SEARCH_DIALOG_OPTION_NO_REGEX 2
#define SEARCH_DIALOG_OPTION_NO_CASE 4
#define SEARCH_DIALOG_OPTION_BACKWARDS 8
#define SEARCH_DIALOG_OPTION_BOOKMARK 16
#define EDIT_KEY_EMULATION_NORMAL 0
#define EDIT_KEY_EMULATION_EMACS 1
#define REDRAW_LINE (1 << 0)
#define REDRAW_LINE_ABOVE (1 << 1)
#define REDRAW_LINE_BELOW (1 << 2)
#define REDRAW_AFTER_CURSOR (1 << 3)
#define REDRAW_BEFORE_CURSOR (1 << 4)
#define REDRAW_PAGE (1 << 5)
#define REDRAW_IN_BOUNDS (1 << 6)
#define REDRAW_CHAR_ONLY (1 << 7)
#define REDRAW_COMPLETELY (1 << 8)
#define MOD_ABNORMAL (1 << 0)
#define MOD_UNDERLINED (1 << 1)
#define MOD_BOLD (1 << 2)
#define MOD_HIGHLIGHTED (1 << 3)
#define MOD_MARKED (1 << 4)
#define MOD_ITALIC (1 << 5)
#define MOD_CURSOR (1 << 6)
#define MOD_INVERSE (1 << 7)
#ifndef MIDNIGHT
# ifdef GTK
# define EDIT_TEXT_HORIZONTAL_OFFSET 0
# define EDIT_TEXT_VERTICAL_OFFSET 0
# else
# define EDIT_TEXT_HORIZONTAL_OFFSET 4
# define EDIT_TEXT_VERTICAL_OFFSET 3
# endif
#else
# define EDIT_TEXT_HORIZONTAL_OFFSET 0
# define EDIT_TEXT_VERTICAL_OFFSET 1
# define FONT_OFFSET_X 0
# define FONT_OFFSET_Y 0
#endif
#define EDIT_RIGHT_EXTREME option_edit_right_extreme
#define EDIT_LEFT_EXTREME option_edit_left_extreme
#define EDIT_TOP_EXTREME option_edit_top_extreme
#define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
/*there are a maximum of ... */
/*... edit buffers, each of which is ... */
#define EDIT_BUF_SIZE 0x10000
/* ...bytes in size. */
/*x / EDIT_BUF_SIZE equals x >> ... */
#define S_EDIT_BUF_SIZE 16
/* x % EDIT_BUF_SIZE is equal to x && ... */
#define M_EDIT_BUF_SIZE 0xFFFF
#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
/* Note a 16k stack is 64k of data and enough to hold (usually) around 10
pages of undo info. */
/* undo stack */
#define START_STACK_SIZE 32
/*some codes that may be pushed onto or returned from the undo stack: */
#define CURS_LEFT 601
#define CURS_RIGHT 602
#define DELETE 603
#define BACKSPACE 604
#define STACK_BOTTOM 605
#define CURS_LEFT_LOTS 606
#define CURS_RIGHT_LOTS 607
#define COLUMN_ON 608
#define COLUMN_OFF 609
#define MARK_1 1000
#define MARK_2 700000000
#define KEY_PRESS 1400000000
/*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
#define TAB_SIZE option_tab_spacing
#define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
struct selection {
unsigned char * text;
int len;
};
#define MAX_WORDS_PER_CONTEXT 1024
#define MAX_CONTEXTS 128
struct key_word {
char *keyword;
unsigned char first;
char *whole_word_chars_left;
char *whole_word_chars_right;
time_t time;
#define NO_COLOR 0x7FFFFFFF
#define SPELLING_ERROR 0x7EFEFEFE
int line_start;
int bg;
int fg;
};
struct context_rule {
char *left;
unsigned char first_left;
char *right;
unsigned char first_right;
char line_start_left;
char line_start_right;
int single_char;
int between_delimiters;
char *whole_word_chars_left;
char *whole_word_chars_right;
char *keyword_first_chars;
int spelling;
/* first word is word[1] */
struct key_word **keyword;
};
#include "edit-widget.h"
#ifndef MIDNIGHT
void edit_render_expose (WEdit * edit, XExposeEvent * xexpose);
#ifndef GTK
void edit_render_tidbits (struct cool_widget *w);
int eh_editor (CWidget * w, XEvent * xevent, CEvent * cwevent);
#endif
void edit_draw_menus (Window parent, int x, int y);
void edit_run_make (void);
void edit_change_directory (void);
int edit_man_page_cmd (WEdit * edit);
void edit_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, char *heading, int option);
void edit_search_dialog (WEdit * edit, char **search_text);
long edit_find (long search_start, unsigned char *expr, int *len, long last_byte, int (*get_byte) (void *, long), void *data, void *d);
void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic);
void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted);
void edit_set_cursor_color (unsigned long c);
void draw_options_dialog (Window parent, int x, int y);
void CRefreshEditor (WEdit * edit);
void edit_set_user_command (void (*func) (WEdit *, int));
void edit_draw_this_line_proportional (WEdit * edit, long b, int curs_row, int start_column, int end_column);
unsigned char get_international_character (unsigned char key_press);
void edit_set_user_key_function (int (*user_def_key_func) (unsigned int, unsigned int, KeySym keysym));
#else
int edit_drop_hotkey_menu (WEdit * e, int key);
void edit_menu_cmd (WEdit * e);
void edit_init_menu_emacs (void);
void edit_init_menu_normal (void);
void edit_done_menu (void);
int edit_raw_key_query (char *heading, char *query, int cancel);
char *strcasechr (const unsigned char *s, int c);
int edit (const char *_file, int line);
int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
#endif
#ifndef NO_INLINE_GETBYTE
int edit_get_byte (WEdit * edit, long byte_index);
#else
static inline int edit_get_byte (WEdit * edit, long byte_index)
{
unsigned long p;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
return '\n';
if (byte_index >= edit->curs1) {
p = edit->curs1 + edit->curs2 - byte_index - 1;
return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
} else {
return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
}
}
#endif
char *edit_get_buffer_as_text (WEdit * edit);
int edit_count_lines (WEdit * edit, long current, int upto);
long edit_move_forward (WEdit * edit, long current, int lines, long upto);
long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
long edit_move_backward (WEdit * edit, long current, int lines);
void edit_scroll_screen_over_cursor (WEdit * edit);
void edit_render_keypress (WEdit * edit);
void edit_scroll_upward (WEdit * edit, unsigned long i);
void edit_scroll_downward (WEdit * edit, int i);
void edit_scroll_right (WEdit * edit, int i);
void edit_scroll_left (WEdit * edit, int i);
int edit_get_col (WEdit * edit);
long edit_bol (WEdit * edit, long current);
long edit_eol (WEdit * edit, long current);
void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit);
void edit_block_copy_cmd (WEdit * edit);
void edit_block_move_cmd (WEdit * edit);
int edit_block_delete_cmd (WEdit * edit);
int edit_block_delete (WEdit * edit);
void edit_delete_line (WEdit * edit);
int edit_delete (WEdit * edit);
void edit_insert (WEdit * edit, int c);
int edit_cursor_move (WEdit * edit, long increment);
void edit_push_action (WEdit * edit, long c,...);
void edit_push_key_press (WEdit * edit);
void edit_insert_ahead (WEdit * edit, int c);
int edit_save_file (WEdit * edit, const char *filename);
long edit_write_stream (WEdit * edit, FILE * f);
char *edit_get_write_filter (char *writename, const char *filename);
int edit_save_cmd (WEdit * edit);
int edit_save_confirm_cmd (WEdit * edit);
int edit_save_as_cmd (WEdit * edit);
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
int edit_clean (WEdit * edit);
int edit_renew (WEdit * edit);
int edit_new_cmd (WEdit * edit);
int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
int edit_load_cmd (WEdit * edit);
void edit_mark_cmd (WEdit * edit, int unmark);
void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
void edit_push_markers (WEdit * edit);
void edit_quit_cmd (WEdit * edit);
void edit_replace_cmd (WEdit * edit, int again);
void edit_search_cmd (WEdit * edit, int again);
int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
int edit_save_block_cmd (WEdit * edit);
int edit_insert_file_cmd (WEdit * edit);
int edit_insert_file (WEdit * edit, const char *filename);
void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
char *catstrs (const char *first,...);
void edit_refresh_cmd (WEdit * edit);
void edit_date_cmd (WEdit * edit);
void edit_goto_cmd (WEdit * edit);
int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
void edit_status (WEdit * edit);
int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
void edit_update_screen (WEdit * edit);
int edit_printf (WEdit * e, const char *fmt,...);
int edit_print_string (WEdit * e, const char *s);
void edit_move_to_line (WEdit * e, long line);
void edit_move_display (WEdit * e, long line);
void edit_word_wrap (WEdit * edit);
unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
int edit_sort_cmd (WEdit * edit);
void edit_help_cmd (WEdit * edit);
void edit_left_word_move (WEdit * edit, int s);
void edit_right_word_move (WEdit * edit, int s);
void edit_get_selection (WEdit * edit);
int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
void edit_delete_macro_cmd (WEdit * edit);
int edit_copy_to_X_buf_cmd (WEdit * edit);
int edit_cut_to_X_buf_cmd (WEdit * edit);
void edit_paste_from_X_buf_cmd (WEdit * edit);
void edit_paste_from_history (WEdit *edit);
void edit_split_filename (WEdit * edit, const char *name);
#ifdef MIDNIGHT
#define CWidget Widget
#elif defined(GTK)
#define CWidget GtkEdit
#endif
void edit_set_syntax_change_callback (void (*callback) (CWidget *));
void edit_load_syntax (WEdit * edit, char **names, char *type);
void edit_free_syntax_rules (WEdit * edit);
void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
int edit_check_spelling (WEdit * edit);
void book_mark_insert (WEdit * edit, int line, int c);
int book_mark_query_color (WEdit * edit, int line, int c);
int book_mark_query_all (WEdit * edit, int line, int *c);
struct _book_mark *book_mark_find (WEdit * edit, int line);
int book_mark_clear (WEdit * edit, int line, int c);
void book_mark_flush (WEdit * edit, int c);
void book_mark_inc (WEdit * edit, int line);
void book_mark_dec (WEdit * edit, int line);
void user_menu (WEdit *edit);
#ifdef MIDNIGHT
#include "src/user.h" /* for user_menu_cmd, must be after edit-widget.h */
#define CPushFont(x,y)
#define CPopFont()
#define FIXED_FONT 1
/* put OS2/NT/WIN95 defines here */
# ifdef USE_O_TEXT
# define MY_O_TEXT O_TEXT
# else
# define MY_O_TEXT 0
# endif
# define FONT_PIX_PER_LINE 1
# define FONT_MEAN_WIDTH 1
# define get_sys_error(s) (s)
# define open mc_open
# define close(f) mc_close(f)
# define read(f,b,c) mc_read(f,b,c)
# define write(f,b,c) mc_write(f,b,c)
# define stat(f,s) mc_stat(f,s)
# define mkdir(s,m) mc_mkdir(s,m)
# define itoa MY_itoa
# define edit_get_load_file(d,f,h) input_dialog (h, " Enter file name: ", f)
# define edit_get_save_file(d,f,h) input_dialog (h, " Enter file name: ", f)
# define CMalloc(x) malloc(x)
# define set_error_msg(s) edit_init_error_msg = strdup(s)
# ifdef _EDIT_C
# define edit_error_dialog(h,s) set_error_msg(s)
char *edit_init_error_msg = NULL;
# else /* ! _EDIT_C */
# define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
# define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
extern char *edit_init_error_msg;
# endif /* ! _EDIT_C */
# define get_error_msg(s) edit_init_error_msg
# define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
# define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
# define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
#else /* ! MIDNIGHT */
# ifdef GTK
# define CPushFont(x,y)
# define CPopFont()
# define FIXED_FONT gtk_edit_fixed_font
# define get_sys_error(s) (s)
# define open mc_open
# define close(f) mc_close(f)
# define read(f,b,c) mc_read(f,b,c)
# define write(f,b,c) mc_write(f,b,c)
# define stat(f,s) mc_stat(f,s)
# define mkdir(s,m) mc_mkdir(s,m)
# define itoa MY_itoa
# define CMalloc(x) malloc(x)
# define EDITOR_NO_FILE (1<<3)
# define EDITOR_NO_SCROLL (1<<4)
# define EDITOR_NO_TEXT (1<<5)
# define EDITOR_HORIZ_SCROLL (1<<6)
#include <gdk/gdkprivate.h>
# define CWindowOf(w) (w)
# define CHeightOf(w) ((w)->editable.widget.allocation.height)
# define CWidthOf(w) ((w)->editable.widget.allocation.width)
# define COptionsOf(w) ((w)->options)
# define cache_type unsigned int
/* font dimensions */
# define FONT_OVERHEAD gtk_edit_option_text_line_spacing
# define FONT_BASE_LINE (FONT_OVERHEAD + gtk_edit_option_font_ascent)
# define FONT_HEIGHT (gtk_edit_option_font_ascent + gtk_edit_option_font_descent)
# define FONT_PIX_PER_LINE (FONT_OVERHEAD + FONT_HEIGHT)
# define FONT_MEAN_WIDTH gtk_edit_option_font_mean_width
# define EDIT_FRAME_H 3
# define EDIT_FRAME_W 3
# define FONT_OFFSET_X 0
# define FONT_OFFSET_Y FONT_BASE_LINE
# define FONT_PER_CHAR gtk_edit_font_width_per_char
# ifndef _GTK_EDIT_C
extern guchar gtk_edit_font_width_per_char[256];
extern int gtk_edit_option_text_line_spacing;
extern int gtk_edit_option_font_ascent;
extern int gtk_edit_option_font_descent;
extern int gtk_edit_option_font_mean_width;
extern int gtk_edit_fixed_font;
# endif
/* start temporary */
# define COLOR_BLACK 0
# define COLOR_WHITE 1
# define CURSOR_TYPE_EDITOR 0
# define WIN_MESSAGES GTK_WINDOW_TOPLEVEL, 20, 20
# define option_text_line_spacing 1
# define fixed_font 0
#define color_palette(x) win->color[x].pixel
#define DndNotDnd -1
#define DndUnknown 0
#define DndRawData 1
#define DndFile 2
#define DndFiles 3
#define DndText 4
#define DndDir 5
#define DndLink 6
#define DndExe 7
#define DndURL 8
#define DndMIME 9
#define DndEND 10
#define dnd_null_term_type(d) \
((d) == DndFile || (d) == DndText || (d) == DndDir || \
(d) == DndLink || (d) == DndExe || (d) == DndURL)
/* end temporary */
# else
# define WIN_MESSAGES edit->widget ? edit->widget->mainid : CRoot, 20, 20
# endif
# define MY_O_TEXT 0
# ifdef GTK
# ifndef min
# define min(x,y) (((x) < (y)) ? (x) : (y))
# endif
# ifndef max
# define max(x,y) (((x) > (y)) ? (x) : (y))
# endif
/*
extern Display *gdk_display;
extern Window gdk_root_window;
*/
# define edit_get_load_file(d,f,h) gtk_edit_dialog_get_load_file(d,f,h)
# define edit_get_save_file(d,f,h) gtk_edit_dialog_get_save_file(d,f,h)
# define edit_error_dialog(h,t) gtk_edit_dialog_error(h,"%s",t)
# define edit_message_dialog(h,t) gtk_edit_dialog_message(h,"%s",t)
# define edit_query_dialog2(h,t,a,b) gtk_edit_dialog_query(h,t,a,b,0)
# define edit_query_dialog3(h,t,a,b,c) gtk_edit_dialog_query(h,t,a,b,c,0)
# define edit_query_dialog4(h,t,a,b,c,d) gtk_edit_dialog_query(h,t,a,b,c,d,0)
# define CError(x) printf("Error: %s\n",x)
# define CIsDropAcknowledge(a,b) DndNotDnd
# define CGetDrop(e,d,s,x,y) DndNotDnd
# define CDropAcknowledge(x)
/* # define edit_get_syntax_color(e,i,f,b) */
# define get_international_character(k) 0
# define compose_key_pressed 0
# else
# define edit_get_load_file(d,f,h) CGetLoadFile(WIN_MESSAGES,d,f,h)
# define edit_get_save_file(d,f,h) CGetSaveFile(WIN_MESSAGES,d,f,h)
# define edit_error_dialog(h,t) CErrorDialog(WIN_MESSAGES,h,"%s",t)
# define edit_message_dialog(h,t) CMessageDialog(WIN_MESSAGES,0,h,"%s",t)
# define edit_query_dialog2(h,t,a,b) CQueryDialog(WIN_MESSAGES,h,t,a,b,0)
# define edit_query_dialog3(h,t,a,b,c) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,0)
# define edit_query_dialog4(h,t,a,b,c,d) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,d,0)
# endif
#endif /* ! MIDNIGHT */
extern char *home_dir;
#define NUM_SELECTION_HISTORY 64
#ifndef MAX_PATH_LEN
#ifdef PATH_MAX
#define MAX_PATH_LEN PATH_MAX
#else
#define MAX_PATH_LEN 1024
#endif
#endif
#ifdef _EDIT_C
struct selection selection =
{0, 0};
int current_selection = 0;
/* Note: selection.text = selection_history[current_selection].text */
struct selection selection_history[NUM_SELECTION_HISTORY] =
{
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
};
#ifdef MIDNIGHT
/*
what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
or EDIT_KEY_EMULATION_EMACS
*/
int edit_key_emulation = EDIT_KEY_EMULATION_NORMAL;
#endif /* ! MIDNIGHT */
int option_word_wrap_line_length = 72;
int option_typewriter_wrap = 0;
int option_auto_para_formatting = 0;
int option_international_characters = 0;
int option_tab_spacing = 8;
int option_fill_tabs_with_spaces = 0;
int option_return_does_auto_indent = 1;
int option_backspace_through_tabs = 0;
int option_fake_half_tabs = 1;
int option_save_mode = 0;
int option_backup_ext_int = -1;
int option_find_bracket = 1;
int option_max_undo = 32768;
int option_editor_fg_normal = 26;
int option_editor_fg_bold = 8;
int option_editor_fg_italic = 10;
int option_edit_right_extreme = 0;
int option_edit_left_extreme = 0;
int option_edit_top_extreme = 0;
int option_edit_bottom_extreme = 0;
int option_editor_bg_normal = 1;
int option_editor_bg_abnormal = 0;
int option_editor_bg_marked = 2;
int option_editor_bg_marked_abnormal = 9;
int option_editor_bg_highlighted = 12;
int option_editor_fg_cursor = 18;
char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_";
char *option_chars_move_whole_word = "!=&|<>^~ !:;, !'!`!.?!\"!( !) !Aa0 !+-*/= |<> ![ !] !\\#! ";
char *option_backup_ext = "~";
#else /* ! _EDIT_C */
extern struct selection selection;
extern struct selection selection_history[];
extern int current_selection;
#ifdef MIDNIGHT
/*
what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
or EDIT_KEY_EMULATION_EMACS
*/
extern int edit_key_emulation;
extern WEdit *wedit;
#endif /* ! MIDNIGHT */
extern int option_word_wrap_line_length;
extern int option_typewriter_wrap;
extern int option_auto_para_formatting;
extern int option_international_characters;
extern int option_tab_spacing;
extern int option_fill_tabs_with_spaces;
extern int option_return_does_auto_indent;
extern int option_backspace_through_tabs;
extern int option_fake_half_tabs;
extern int option_save_mode;
extern int option_backup_ext_int;
extern int option_find_bracket;
extern int option_max_undo;
extern int option_editor_fg_normal;
extern int option_editor_fg_bold;
extern int option_editor_fg_italic;
extern int option_edit_right_extreme;
extern int option_edit_left_extreme;
extern int option_edit_top_extreme;
extern int option_edit_bottom_extreme;
extern int option_editor_bg_normal;
extern int option_editor_bg_abnormal;
extern int option_editor_bg_marked;
extern int option_editor_bg_marked_abnormal;
extern int option_editor_bg_highlighted;
extern int option_editor_fg_cursor;
extern char *option_whole_chars_search;
extern char *option_chars_move_whole_word;
extern char *option_backup_ext;
extern int edit_confirm_save;
#endif /* ! _EDIT_C */
#endif /* __EDIT_H */

3146
edit/editcmd.c Normal file

File diff suppressed because it is too large Load Diff

169
edit/editcmddef.h Normal file
View File

@ -0,0 +1,169 @@
#ifndef __EDIT_CMD_DEF_H
#define __EDIT_CMD_DEF_H
/* in the distant future, keyboards will be invented with a
seperate key for each one of these commands *sigh* */
/* cursor movements */
#define CK_No_Command -1
#define CK_BackSpace 1
#define CK_Delete 2
#define CK_Enter 3
#define CK_Page_Up 4
#define CK_Page_Down 5
#define CK_Left 6
#define CK_Right 7
#define CK_Word_Left 8
#define CK_Word_Right 9
#define CK_Up 10
#define CK_Down 11
#define CK_Home 12
#define CK_End 13
#define CK_Tab 14
#define CK_Undo 15
#define CK_Beginning_Of_Text 16
#define CK_End_Of_Text 17
#define CK_Scroll_Up 18
#define CK_Scroll_Down 19
#define CK_Return 20
#define CK_Begin_Page 21
#define CK_End_Page 22
#define CK_Delete_Word_Left 23
#define CK_Delete_Word_Right 24
#define CK_Paragraph_Up 25
#define CK_Paragraph_Down 26
/* file commands */
#define CK_Save 101
#define CK_Load 102
#define CK_New 103
#define CK_Save_As 104
/* block commands */
#define CK_Mark 201
#define CK_Copy 202
#define CK_Move 203
#define CK_Remove 204
#define CK_Unmark 206
#define CK_Save_Block 207
#define CK_Column_Mark 208
/* search and replace */
#define CK_Find 301
#define CK_Find_Again 302
#define CK_Replace 303
#define CK_Replace_Again 304
/* debugger commands */
#define CK_Debug_Start 350
#define CK_Debug_Stop 351
#define CK_Debug_Toggle_Break 352
#define CK_Debug_Clear 353
#define CK_Debug_Next 354
#define CK_Debug_Step 355
#define CK_Debug_Back_Trace 356
#define CK_Debug_Continue 357
#define CK_Debug_Enter_Command 358
#define CK_Debug_Until_Curser 359
/* misc */
#define CK_Insert_File 401
#define CK_Exit 402
#define CK_Toggle_Insert 403
#define CK_Help 404
#define CK_Date 405
#define CK_Refresh 406
#define CK_Goto 407
#define CK_Delete_Line 408
#define CK_Delete_To_Line_End 409
#define CK_Delete_To_Line_Begin 410
#define CK_Man_Page 411
#define CK_Sort 412
#define CK_Mail 413
#define CK_Cancel 414
#define CK_Complete 415
#define CK_Paragraph_Format 416
#define CK_Util 417
#define CK_Type_Load_Python 418
#define CK_Find_File 419
#define CK_Ctags 420
#define CK_Match_Bracket 421
#define CK_Terminal 422
#define CK_Terminal_App 423
#define CK_User_Menu 425
/* application control */
#define CK_Save_Desktop 451
#define CK_New_Window 452
#define CK_Cycle 453
#define CK_Menu 454
#define CK_Save_And_Quit 455
#define CK_Run_Another 456
#define CK_Check_Save_And_Quit 457
#define CK_Maximize 458
/* macro */
#define CK_Begin_Record_Macro 501
#define CK_End_Record_Macro 502
#define CK_Delete_Macro 503
/* book mark */
#define CK_Toggle_Bookmark 550
#define CK_Flush_Bookmarks 551
#define CK_Next_Bookmark 552
#define CK_Prev_Bookmark 553
/* highlight commands */
#define CK_Page_Up_Highlight 604
#define CK_Page_Down_Highlight 605
#define CK_Left_Highlight 606
#define CK_Right_Highlight 607
#define CK_Word_Left_Highlight 608
#define CK_Word_Right_Highlight 609
#define CK_Up_Highlight 610
#define CK_Down_Highlight 611
#define CK_Home_Highlight 612
#define CK_End_Highlight 613
#define CK_Beginning_Of_Text_Highlight 614
#define CK_End_Of_Text_Highlight 615
#define CK_Begin_Page_Highlight 616
#define CK_End_Page_Highlight 617
#define CK_Scroll_Up_Highlight 618
#define CK_Scroll_Down_Highlight 619
#define CK_Paragraph_Up_Highlight 620
#define CK_Paragraph_Down_Highlight 621
/* X clipboard operations */
#define CK_XStore 701
#define CK_XCut 702
#define CK_XPaste 703
#define CK_Selection_History 704
#ifdef MIDNIGHT /* cooledit now has its own full-featured script editor and executor */
#define CK_Shell 801
/*
Process a block through a shell command: CK_Pipe_Block(i) executes shell_cmd[i].
shell_cmd[i] must process the file ~/cooledit.block and output ~/cooledit.block
which is then inserted into the text in place of the original block. shell_cmd[i] must
also produce a file homedir/cooledit.error . If this file is not empty an error will
have been assumed to have occured, and the block will not be replaced.
TODO: bring up a viewer to display the error message instead of inserting
it into the text, which is annoying.
*/
#define CK_Pipe_Block(i) (1000+(i))
#define SHELL_COMMANDS_i {"/edit.indent.rc", "/edit.spell.rc", /* and so on */ 0};
#define CK_Macro(i) (2000+(i))
#define CK_Last_Macro CK_Macro(0x7FFF)
#else
#define CK_User_Command(i) ((i) | (1 << 16))
#define IS_USER_COMMAND(i) ((i) & (1 << 16))
#define CK_Macro(i) ((i) | (1 << 17))
#define IS_MACRO_COMMAND(i) ((i) & (1 << 17))
#endif
#endif

862
edit/editdraw.c Normal file
View File

@ -0,0 +1,862 @@
/* editor text drawing.
Copyright (C) 1996, 1997 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
$Id$
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#include <config.h>
#include "edit.h"
#define MAX_LINE_LEN 1024
#if ! defined (MIDNIGHT) && ! defined (GTK)
#include "app_glob.c"
#include "coollocal.h"
#include "mad.h"
#endif
#ifdef HAVE_CHARSET
#include "../src/charsets.h"
#endif
extern int column_highlighting;
#if defined (MIDNIGHT) || defined (GTK)
static void status_string (WEdit * edit, char *s, int w, int fill, int font_width)
{
char byte_str[16];
/*
* If we are at the end of file, print <EOF>,
* otherwise print the current character as is (if printable),
* as decimal and as hex.
*/
if (edit->curs1 < edit->last_byte) {
unsigned char cur_byte = edit_get_byte (edit, edit->curs1);
g_snprintf (byte_str, sizeof(byte_str), "%c %3d 0x%02X",
is_printable(cur_byte) ? cur_byte : '.',
cur_byte,
cur_byte);
} else {
strcpy(byte_str, "<EOF>");
}
/* The field lengths just prevent the status line from shortening too much */
g_snprintf (s, w,
"[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s",
edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-',
edit->modified ? 'M' : '-',
edit->macro_i < 0 ? '-' : 'R',
edit->overwrite == 0 ? '-' : 'O',
edit->curs_col / font_width,
edit->start_line + 1,
edit->curs_row,
edit->curs_line + 1,
edit->total_lines + 1,
edit->curs1,
edit->last_byte,
byte_str);
}
#endif /* MIDNIGHT || GTK */
#ifdef MIDNIGHT
/* how to get as much onto the status line as is numerically possible :) */
void edit_status (WEdit * edit)
{
int w, i, t;
char *s;
w = edit->widget.cols - (edit->have_frame * 2);
s = malloc (w + 15);
if (w < 4)
w = 4;
memset (s, ' ', w);
attrset (SELECTED_COLOR);
if (w > 4) {
widget_move (edit, edit->have_frame, edit->have_frame);
i = w > 24 ? 18 : w - 6;
i = i < 13 ? 13 : i;
strcpy (s, (char *) name_trunc (edit->filename ? edit->filename : "", i));
i = strlen (s);
s[i] = ' ';
t = w - 20;
if (t < 0)
t = 0;
status_string (edit, s + 20, t, ' ', 1);
}
s[w] = 0;
printw ("%-*s", w, s);
attrset (NORMAL_COLOR);
free (s);
}
#else
void render_status (CWidget * wdt, int expose);
#ifdef GTK
void edit_status (WEdit *edit)
{
GtkEntry *entry;
int w, i, t;
char s[160];
w = edit->num_widget_columns - 1;
if (w > 150)
w = 150;
if (w < 0)
w = 0;
memset (s, 0, w);
if (w > 1) {
i = w > 24 ? 18 : w - 6;
i = i < 13 ? 13 : i;
strcpy (s, (char *) name_trunc (edit->filename ? edit->filename : "", i));
i = strlen (s);
s[i] = ' ';
s[i + 1] = ' ';
t = w - i - 2;
if (t < 0)
t = 0;
status_string (edit, s + i + 2, t, 0, FONT_MEAN_WIDTH);
}
s[w] = 0;
entry = GTK_ENTRY (edit->widget->status);
if (strcmp (s, gtk_entry_get_text (entry)))
gtk_entry_set_text (entry, s);
}
#else
void edit_status (WEdit * edit)
{
long start_mark, end_mark;
CWidget *wdt;
mode_t m;
char *p;
char id[33];
char s[256];
if (eval_marks (edit, &start_mark, &end_mark))
end_mark = start_mark = 0;
if ((COptionsOf (edit->widget) & EDITOR_NO_TEXT))
return;
CPushFont ("editor", 0);
m = edit->stat.st_mode;
p = edit->filename ? edit->filename : "";
sprintf (s, "\034%c%s\033\035 \034-%c%c%c%c%c%c%c%c%c\035 \034%s%s%s%c\035 \034\030%02ld\033\035 \034%-4ld+%2ld=\030%4ld\033/%3ld\035 \034*%-5ld/%5ldb=%c%3d\035%c \034\001%ld\033\035",
*p ? '\033' : '\003', *p ? (char *) name_trunc (p, max (edit->num_widget_lines / 3, 16)) : _ ("<unnamed>"),
m & S_IRUSR ? 'r' : '-',
m & S_IWUSR ? 'w' : '-',
m & S_IXUSR ? 'x' : '-',
m & S_IRGRP ? 'r' : '-',
m & S_IWGRP ? 'w' : '-',
m & S_IXGRP ? 'x' : '-',
m & S_IROTH ? 'r' : '-',
m & S_IWOTH ? 'w' : '-',
m & S_IXOTH ? 'x' : '-',
end_mark - start_mark || (edit->mark2 == -1 && !edit->highlight) ? (column_highlighting ? "\032C\033" : "\001B\033") : "-",
edit->modified ? "\012M\033" : "-", edit->macro_i < 0 ? "-" : "\023R\033",
edit->overwrite == 0 ? '-' : 'O',
edit->curs_col / FONT_MEAN_WIDTH, edit->start_line + 1, edit->curs_row,
edit->curs_line + 1, edit->total_lines + 1, edit->curs1,
edit->last_byte, edit->curs1 == edit->last_byte ? '\014' : '\033', edit->curs1 < edit->last_byte
? edit_get_byte (edit, edit->curs1) : -1,
end_mark - start_mark && !column_highlighting ? ' ' : '\0',
end_mark - start_mark);
strcpy (id, CIdentOf (edit->widget));
strcat (id, ".text");
wdt = CIdent (id);
free (wdt->text);
wdt->text = (char *) strdup (s);
CSetWidgetSize (id, CWidthOf (edit->widget), CHeightOf (wdt));
render_status (wdt, 0);
CPopFont ();
}
#endif /* GTK */
#endif /* !MIDNIGHT */
/* result is boolean */
int cursor_in_screen (WEdit * edit, long row)
{
if (row < 0 || row >= edit->num_widget_lines)
return 0;
else
return 1;
}
/* returns rows from the first displayed line to the cursor */
int cursor_from_display_top (WEdit * edit)
{
if (edit->curs1 < edit->start_display)
return -edit_move_forward (edit, edit->curs1, 0, edit->start_display);
else
return edit_move_forward (edit, edit->start_display, 0, edit->curs1);
}
/* returns how far the cursor is out of the screen */
int cursor_out_of_screen (WEdit * edit)
{
int row = cursor_from_display_top (edit);
if (row >= edit->num_widget_lines)
return row - edit->num_widget_lines + 1;
if (row < 0)
return row;
return 0;
}
#ifndef MIDNIGHT
int edit_width_of_long_printable (int c);
#endif
/* this scrolls the text so that cursor is on the screen */
void edit_scroll_screen_over_cursor (WEdit * edit)
{
int p;
int outby;
int b_extreme, t_extreme, l_extreme, r_extreme;
r_extreme = EDIT_RIGHT_EXTREME;
l_extreme = EDIT_LEFT_EXTREME;
b_extreme = EDIT_BOTTOM_EXTREME;
t_extreme = EDIT_TOP_EXTREME;
if (edit->found_len) {
b_extreme = max (edit->num_widget_lines / 4, b_extreme);
t_extreme = max (edit->num_widget_lines / 4, t_extreme);
}
if (b_extreme + t_extreme + 1 > edit->num_widget_lines) {
int n;
n = b_extreme + t_extreme;
b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n;
t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n;
}
if (l_extreme + r_extreme + 1 > edit->num_widget_columns) {
int n;
n = l_extreme + t_extreme;
l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
}
p = edit_get_col (edit);
edit_update_curs_row (edit);
#ifdef MIDNIGHT
outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
#else
outby = p + edit->start_col - CWidthOf (edit->widget) + 7 + (r_extreme + edit->found_len) * FONT_MEAN_WIDTH + edit_width_of_long_printable (edit_get_byte (edit, edit->curs1));
#endif
if (outby > 0)
edit_scroll_right (edit, outby);
#ifdef MIDNIGHT
outby = l_extreme - p - edit->start_col;
#else
outby = l_extreme * FONT_MEAN_WIDTH - p - edit->start_col;
#endif
if (outby > 0)
edit_scroll_left (edit, outby);
p = edit->curs_row;
outby = p - edit->num_widget_lines + 1 + b_extreme;
if (outby > 0)
edit_scroll_downward (edit, outby);
outby = t_extreme - p;
if (outby > 0)
edit_scroll_upward (edit, outby);
edit_update_curs_row (edit);
}
#ifndef MIDNIGHT
#define CACHE_WIDTH 256
#define CACHE_HEIGHT 128
int EditExposeRedraw = 0;
int EditClear = 0;
/*
* background colors: marked is refers to mouse highlighting,
* highlighted refers to a found string.
*/
unsigned long edit_abnormal_color, edit_marked_abnormal_color;
unsigned long edit_highlighted_color, edit_marked_color;
unsigned long edit_normal_background_color;
/* foreground colors */
unsigned long edit_normal_foreground_color, edit_bold_color;
unsigned long edit_italic_color;
/* cursor color */
unsigned long edit_cursor_color;
void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic)
{
edit_normal_foreground_color = normal;
edit_bold_color = bold;
edit_italic_color = italic;
}
void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted)
{
edit_abnormal_color = abnormal;
edit_marked_abnormal_color = marked_abnormal;
edit_marked_color = marked;
edit_highlighted_color = highlighted;
edit_normal_background_color = normal;
}
void edit_set_cursor_color (unsigned long c)
{
edit_cursor_color = c;
}
#else
#define set_color(font) attrset (font)
#define edit_move(x,y) widget_move(edit, y, x);
static void print_to_widget (WEdit * edit, long row, int start_col, float start_col_real, long end_col, unsigned int line[])
{
int x = (float) start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
int y = row + EDIT_TEXT_VERTICAL_OFFSET;
set_color (EDITOR_NORMAL_COLOR);
edit_move (x1, y);
hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
edit_move (x + FONT_OFFSET_X, y + FONT_OFFSET_Y);
{
unsigned int *p = line;
int textchar = ' ';
long style;
while (*p) {
style = *p >> 8;
textchar = *p & 0xFF;
#ifdef HAVE_SYNTAXH
if (!(style & (0xFF - MOD_ABNORMAL - MOD_CURSOR)))
SLsmg_set_color ((*p & 0x007F0000) >> 16);
#endif
if (style & MOD_ABNORMAL)
textchar = '.';
if (style & MOD_HIGHLIGHTED) {
set_color (EDITOR_BOLD_COLOR);
} else if (style & MOD_MARKED) {
set_color (EDITOR_MARKED_COLOR);
}
if (style & MOD_UNDERLINED) {
set_color (EDITOR_UNDERLINED_COLOR);
}
if (style & MOD_BOLD) {
set_color (EDITOR_BOLD_COLOR);
}
addch (textchar);
p++;
}
}
}
/* b is a pointer to the beginning of the line */
static void edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
{
static unsigned int line[MAX_LINE_LEN];
unsigned int *p = line;
long m1 = 0, m2 = 0, q, c1, c2;
int col, start_col_real;
unsigned int c;
int fg, bg;
int i, book_mark = -1;
#if 0
if (!book_mark_query (edit, edit->start_line + row, &book_mark))
book_mark = -1;
#endif
edit_get_syntax_color (edit, b - 1, &fg, &bg);
q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
c1 = min (edit->column1, edit->column2);
c2 = max (edit->column1, edit->column2);
if (col + 16 > -edit->start_col) {
eval_marks (edit, &m1, &m2);
if (row <= edit->total_lines - edit->start_line) {
while (col <= end_col - edit->start_col) {
*p = 0;
if (q == edit->curs1)
*p |= MOD_CURSOR * 256;
if (q >= m1 && q < m2) {
if (column_highlighting) {
int x;
x = edit_move_forward3 (edit, b, 0, q);
if (x >= c1 && x < c2)
*p |= MOD_MARKED * 256;
} else
*p |= MOD_MARKED * 256;
}
if (q == edit->bracket)
*p |= MOD_BOLD * 256;
if (q >= edit->found_start && q < edit->found_start + edit->found_len)
*p |= MOD_HIGHLIGHTED * 256;
c = edit_get_byte (edit, q);
/* we don't use bg for mc - fg contains both */
if (book_mark == -1) {
edit_get_syntax_color (edit, q, &fg, &bg);
*p |= fg << 16;
} else {
*p |= book_mark << 16;
}
q++;
switch (c) {
case '\n':
col = end_col - edit->start_col + 1; /* quit */
*(p++) |= ' ';
break;
case '\t':
i = TAB_SIZE - ((int) col % TAB_SIZE);
*p |= ' ';
c = *(p++) & (0xFFFFFFFF - MOD_CURSOR * 256);
col += i;
while (--i)
*(p++) = c;
break;
case '\r':
break;
default:
#ifdef HAVE_CHARSET
if (c >= 0 && c <= 255)
c = conv_displ[ c ];
#endif
if (is_printable (c)) {
*(p++) |= c;
} else {
*(p++) = '.';
*p |= (256 * MOD_ABNORMAL);
}
col++;
break;
}
}
}
} else {
start_col_real = start_col = 0;
}
*p = 0;
print_to_widget (edit, row, start_col, start_col_real, end_col, line);
}
#endif
#ifdef MIDNIGHT
#define key_pending(x) (!is_idle())
#else
#define edit_draw_this_line edit_draw_this_line_proportional
int option_smooth_scrolling = 0;
static int key_pending (WEdit * edit)
{
#ifdef GTK
/* ******* */
#else
static int flush = 0, line = 0;
if (!edit) {
flush = line = 0;
} else if (!(edit->force & REDRAW_COMPLETELY) && !EditExposeRedraw && !option_smooth_scrolling) {
/* this flushes the display in logarithmic intervals - so both fast and
slow machines will get good performance vs nice-refreshing */
if ((1 << flush) == ++line) {
flush++;
return CKeyPending ();
}
}
#endif
return 0;
}
#endif
static void edit_draw_this_char (WEdit * edit, long curs, long row)
{
int b = edit_bol (edit, curs);
#ifdef MIDNIGHT
edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
#else
edit_draw_this_line (edit, b, row, 0, CWidthOf (edit->widget));
#endif
}
/* cursor must be in screen for other than REDRAW_PAGE passed in force */
void render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
long end_column)
{
long row = 0, curs_row;
static int prev_curs_row = 0;
static int prev_start_col = 0;
static long prev_curs = 0;
static long prev_start = -1;
#ifndef MIDNIGHT
static unsigned long prev_win = 0;
#endif
int force = edit->force;
long b;
CPushFont ("editor", 0);
#ifndef MIDNIGHT
key_pending (0);
#endif
/*
* If the position of the page has not moved then we can draw the cursor
* character only. This will prevent line flicker when using arrow keys.
*/
if ((!(force & REDRAW_CHAR_ONLY)) || (force & REDRAW_PAGE)
#ifndef MIDNIGHT
#ifdef GTK
|| prev_win != ((GdkWindowPrivate *) CWindowOf (edit->widget)->text_area)->xwindow
#else
|| prev_win != CWindowOf (edit->widget)
#endif
#endif
) {
#if !defined(MIDNIGHT) && !defined(GTK)
int time_division = 5;
#if 0
if (CPending ())
time_division--;
#endif
if (prev_start < 0)
prev_start = edit->start_line;
if (option_smooth_scrolling && prev_win == CWindowOf (edit->widget) && !edit->screen_modified) {
int i, t;
int pos1, pos2;
i = edit->start_line - prev_start;
if (i <= time_division && i > 0) {
edit_draw_proportional (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
for (pos2 = 0, t = 0; t < time_division; t++) {
int move;
pos1 = FONT_PIX_PER_LINE * i * (t + 1) / time_division;
move = pos1 - pos2;
pos2 += move;
XCopyArea (CDisplay, edit->widget->winid, edit->widget->winid, CGC,
EDIT_TEXT_HORIZONTAL_OFFSET,
EDIT_TEXT_VERTICAL_OFFSET + move,
edit->widget->width - EDIT_FRAME_W,
edit->widget->height - EDIT_FRAME_H - move,
EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET);
XClearArea (CDisplay, edit->widget->winid, EDIT_TEXT_HORIZONTAL_OFFSET,
edit->widget->height - EDIT_FRAME_H +
EDIT_TEXT_VERTICAL_OFFSET - move,
edit->widget->width - EDIT_FRAME_W, move, 0);
XFlush (CDisplay);
pause ();
}
} else if (i >= -time_division && i < 0) {
edit_draw_proportional (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
i = -i;
for (pos2 = 0, t = 0; t < time_division; t++) {
int move;
pos1 = FONT_PIX_PER_LINE * i * (t + 1) / time_division;
move = pos1 - pos2;
pos2 += move;
XCopyArea (CDisplay, edit->widget->winid, edit->widget->winid, CGC,
EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET,
edit->widget->width - EDIT_FRAME_W,
edit->widget->height - EDIT_FRAME_H -
move, EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET + move);
XClearArea (CDisplay, edit->widget->winid, EDIT_TEXT_HORIZONTAL_OFFSET,
EDIT_TEXT_VERTICAL_OFFSET,
edit->widget->width - EDIT_FRAME_W, move, 0);
XFlush (CDisplay);
pause ();
}
}
}
#endif
if (!(force & REDRAW_IN_BOUNDS)) { /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
start_row = 0;
end_row = edit->num_widget_lines - 1;
start_column = 0;
#ifdef MIDNIGHT
end_column = edit->num_widget_columns - 1;
#else
end_column = CWidthOf (edit->widget);
#endif
}
if (force & REDRAW_PAGE) {
row = start_row;
b = edit_move_forward (edit, edit->start_display, start_row, 0);
while (row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
row++;
}
} else {
curs_row = edit->curs_row;
if (force & REDRAW_BEFORE_CURSOR) {
if (start_row < curs_row) {
long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
row = start_row;
b = edit->start_display;
while (row <= upto) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
}
}
}
/* if (force & REDRAW_LINE) ---> default */
b = edit_bol (edit, edit->curs1);
if (curs_row >= start_row && curs_row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, curs_row, start_column, end_column);
}
if (force & REDRAW_AFTER_CURSOR) {
if (end_row > curs_row) {
row = curs_row + 1 < start_row ? start_row : curs_row + 1;
b = edit_move_forward (edit, b, 1, 0);
while (row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
row++;
}
}
}
if (force & REDRAW_LINE_ABOVE && curs_row >= 1) {
row = curs_row - 1;
b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
if (row >= start_row && row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
}
}
if (force & REDRAW_LINE_BELOW && row < edit->num_widget_lines - 1) {
row = curs_row + 1;
b = edit_bol (edit, edit->curs1);
b = edit_move_forward (edit, b, 1, 0);
if (row >= start_row && row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
}
}
}
} else {
if (prev_curs_row < edit->curs_row) { /* with the new text highlighting, we must draw from the top down */
edit_draw_this_char (edit, prev_curs, prev_curs_row);
edit_draw_this_char (edit, edit->curs1, edit->curs_row);
} else {
edit_draw_this_char (edit, edit->curs1, edit->curs_row);
edit_draw_this_char (edit, prev_curs, prev_curs_row);
}
}
edit->force = 0;
prev_curs_row = edit->curs_row;
prev_curs = edit->curs1;
prev_start_col = edit->start_col;
#ifndef MIDNIGHT
#ifdef GTK
prev_win = ((GdkWindowPrivate *) CWindowOf (edit->widget)->text_area)->xwindow;
#else
prev_win = CWindowOf (edit->widget);
#endif
#endif
exit_render:
edit->screen_modified = 0;
prev_start = edit->start_line;
CPopFont ();
return;
}
#ifndef MIDNIGHT
void edit_convert_expose_to_area (XExposeEvent * xexpose, int *row1, int *col1, int *row2, int *col2)
{
*col1 = xexpose->x - EDIT_TEXT_HORIZONTAL_OFFSET;
*row1 = (xexpose->y - EDIT_TEXT_VERTICAL_OFFSET) / FONT_PIX_PER_LINE;
*col2 = xexpose->x + xexpose->width + EDIT_TEXT_HORIZONTAL_OFFSET + 3;
*row2 = (xexpose->y + xexpose->height - EDIT_TEXT_VERTICAL_OFFSET) / FONT_PIX_PER_LINE;
}
#ifdef GTK
void edit_render_tidbits (GtkEdit * edit)
{
gtk_widget_draw_focus (GTK_WIDGET (edit));
}
#else
void edit_render_tidbits (CWidget * wdt)
{
int isfocussed;
int w = wdt->width, h = wdt->height;
Window win;
win = wdt->winid;
isfocussed = (win == CGetFocus ());
CSetColor (COLOR_FLAT);
#ifdef NEXT_LOOK
render_bevel (win, 0, 0, w - 1, h - 1, 1, 1); /*most outer border bevel */
#else
if (isfocussed) {
render_bevel (win, 0, 0, w - 1, h - 1, 3, 1); /*most outer border bevel */
} else {
render_bevel (win, 2, 2, w - 3, h - 3, 1, 1); /*border bevel */
render_bevel (win, 0, 0, w - 1, h - 1, 2, 0); /*most outer border bevel */
}
#endif
}
#endif
void edit_set_space_width (int s);
extern int option_long_whitespace;
#endif
void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
{
int f = 0;
#ifdef GTK
GtkEdit *win;
#endif
if (page) /* if it was an expose event, 'page' would be set */
edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
f = edit->force & (REDRAW_PAGE | REDRAW_COMPLETELY);
#ifdef MIDNIGHT
if (edit->force & REDRAW_COMPLETELY)
redraw_labels (edit->widget.parent, (Widget *) edit);
#else
if (option_long_whitespace)
edit_set_space_width (FONT_PER_CHAR[' '] * 2);
else
edit_set_space_width (FONT_PER_CHAR[' ']);
#ifdef GTK
win = (GtkEdit *) edit->widget;
#endif
edit_set_foreground_colors (
color_palette (option_editor_fg_normal),
color_palette (option_editor_fg_bold),
color_palette (option_editor_fg_italic)
);
edit_set_background_colors (
color_palette (option_editor_bg_normal),
color_palette (option_editor_bg_abnormal),
color_palette (option_editor_bg_marked),
color_palette (option_editor_bg_marked_abnormal),
color_palette (option_editor_bg_highlighted)
);
edit_set_cursor_color (
color_palette (option_editor_fg_cursor)
);
#ifdef GTK
/* *********** */
#else
if (!EditExposeRedraw)
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
#endif
#endif
render_edit_text (edit, row_start, col_start, row_end, col_end);
/*
* edit->force != 0 means a key was pending and the redraw
* was halted, so next time we must redraw everything in case stuff
* was left undrawn from a previous key press.
*/
if (edit->force)
edit->force |= REDRAW_PAGE;
#ifndef MIDNIGHT
if (f) {
edit_render_tidbits (edit->widget);
#ifdef GTK
/* ***************** */
#else
#ifndef NEXT_LOOK
CSetColor (edit_normal_background_color);
CLine (CWindowOf (edit->widget), 3, 3, 3, CHeightOf (edit->widget) - 4);
#endif
#endif
}
#endif
}
#ifndef MIDNIGHT
void edit_render_expose (WEdit * edit, XExposeEvent * xexpose)
{
int row_start, col_start, row_end, col_end;
CPushFont ("editor", 0);
EditExposeRedraw = 1;
edit->num_widget_lines = (CHeightOf (edit->widget) - EDIT_FRAME_H) / FONT_PIX_PER_LINE;
edit->num_widget_columns = (CWidthOf (edit->widget) - EDIT_FRAME_W) / FONT_MEAN_WIDTH;
if (edit->force & (REDRAW_PAGE | REDRAW_COMPLETELY)) {
edit->force |= REDRAW_PAGE | REDRAW_COMPLETELY;
edit_render_keypress (edit);
} else {
edit_convert_expose_to_area (xexpose, &row_start, &col_start, &row_end, &col_end);
edit_render (edit, 1, row_start, col_start, row_end, col_end);
}
CPopFont ();
EditExposeRedraw = 0;
}
void edit_render_keypress (WEdit * edit)
{
CPushFont ("editor", 0);
edit_render (edit, 0, 0, 0, 0, 0);
CPopFont ();
}
#else
void edit_render_keypress (WEdit * edit)
{
edit_render (edit, 0, 0, 0, 0, 0);
}
#endif

485
edit/editmenu.c Normal file
View File

@ -0,0 +1,485 @@
/* editor menu definitions and initialisation
Copyright (C) 1996 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
$Id$
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#include <config.h>
#include "edit.h"
#include "../src/user.h"
#include "editcmddef.h"
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
#ifdef MIDNIGHT
#include "../src/mad.h"
extern int edit_key_emulation;
extern WButtonBar *edit_bar;
extern Dlg_head *edit_dlg;
extern WMenu *edit_menubar;
#undef edit_message_dialog
#define edit_message_dialog(w,x,y,h,s) query_dialog (h, s, 0, 1, _("&Ok"))
#define CFocus(x)
static void menu_cmd (int i)
{
send_message (wedit->widget.parent, (Widget *) wedit, WIDGET_COMMAND, i);
}
static void menu_key (int i)
{
send_message (wedit->widget.parent, (Widget *) wedit, WIDGET_KEY, i);
}
void edit_wrap_cmd (void)
{
char *f;
char s[12];
sprintf (s, "%d", option_word_wrap_line_length);
f = input_dialog (_(" Word wrap "),
_(" Enter line length, 0 for off: "), s);
if (f) {
if (*f) {
option_word_wrap_line_length = atoi (f);
}
free (f);
}
}
void edit_about_cmd (void)
{
edit_message_dialog (wedit->mainid, 20, 20, _(" About "),
_("\n"
" Cooledit v3.11.5\n"
"\n"
" Copyright (C) 1996 the Free Software Foundation\n"
"\n"
" A user friendly text editor written\n"
" for the Midnight Commander.\n")
);
}
void menu_mail_cmd (void) { menu_cmd (CK_Mail); }
void menu_load_cmd (void) { menu_cmd (CK_Load); }
void menu_new_cmd (void) { menu_cmd (CK_New); }
void menu_save_cmd (void) { menu_cmd (CK_Save); }
void menu_save_as_cmd (void) { menu_cmd (CK_Save_As); }
void menu_insert_file_cmd (void) { menu_cmd (CK_Insert_File); }
void menu_quit_cmd (void) { menu_cmd (CK_Exit); }
void menu_mark_cmd (void) { menu_cmd (CK_Mark); }
void menu_markcol_cmd (void) { menu_cmd (CK_Column_Mark); }
void menu_ins_cmd (void) { menu_cmd (CK_Toggle_Insert); }
void menu_copy_cmd (void) { menu_cmd (CK_Copy); }
void menu_move_cmd (void) { menu_cmd (CK_Move); }
void menu_delete_cmd (void) { menu_cmd (CK_Remove); }
void menu_cut_cmd (void) { menu_cmd (CK_Save_Block); }
void menu_search_cmd (void) { menu_cmd (CK_Find); }
void menu_search_again_cmd (void) { menu_cmd (CK_Find_Again); }
void menu_replace_cmd (void) { menu_cmd (CK_Replace); }
void menu_begin_record_cmd (void) { menu_cmd (CK_Begin_Record_Macro); }
void menu_end_record_cmd (void) { menu_cmd (CK_End_Record_Macro); }
void menu_wrap_cmd (void) { edit_wrap_cmd (); }
void menu_exec_macro_cmd (void) { menu_key (XCTRL ('a')); }
void menu_exec_macro_delete_cmd (void) { menu_cmd (CK_Delete_Macro); }
void menu_c_form_cmd (void) { menu_key (KEY_F (19)); }
void menu_ispell_cmd (void) { menu_cmd (CK_Pipe_Block (1)); }
void menu_sort_cmd (void) { menu_cmd (CK_Sort); }
void menu_date_cmd (void) { menu_cmd (CK_Date); }
void menu_undo_cmd (void) { menu_cmd (CK_Undo); }
void menu_beginning_cmd (void) { menu_cmd (CK_Beginning_Of_Text); }
void menu_end_cmd (void) { menu_cmd (CK_End_Of_Text); }
void menu_refresh_cmd (void) { menu_cmd (CK_Refresh); }
void menu_goto_line (void) { menu_cmd (CK_Goto); }
void menu_goto_bracket (void) { menu_cmd (CK_Match_Bracket); }
void menu_lit_cmd (void) { menu_key (XCTRL ('q')); }
void menu_format_paragraph (void) { menu_cmd (CK_Paragraph_Format); }
void edit_options_dialog (void);
void menu_options (void) { edit_options_dialog (); }
void menu_user_menu_cmd (void) { menu_key (KEY_F (11)); }
void edit_user_menu_cmd (void) { menu_edit_cmd (1); }
static menu_entry FileMenu[] =
{
{' ', N_("&Open file..."), 'O', menu_load_cmd},
{' ', N_("&New C-n"), 'N', menu_new_cmd},
{' ', "", ' ', 0},
{' ', N_("&Save F2"), 'S', menu_save_cmd},
{' ', N_("save &As... F12"), 'A', menu_save_as_cmd},
{' ', "", ' ', 0},
{' ', N_("&Insert file... F15"), 'I', menu_insert_file_cmd},
{' ', N_("copy to &File... C-f"), 'F', menu_cut_cmd},
{' ', "", ' ', 0},
{' ', N_("&User menu... F11"), 'U', menu_user_menu_cmd},
/* {' ', N_("Menu edi&Tor edit "), 'T', edit_user_menu_cmd}, */
{' ', "", ' ', 0},
{' ', N_("a&Bout... "), 'B', edit_about_cmd},
{' ', "", ' ', 0},
{' ', N_("&Quit F10"), 'Q', menu_quit_cmd}
};
static menu_entry FileMenuEmacs[] =
{
{' ', N_("&Open file..."), 'O', menu_load_cmd},
{' ', N_("&New C-x k"), 'N', menu_new_cmd},
{' ', "", ' ', 0},
{' ', N_("&Save F2"), 'S', menu_save_cmd},
{' ', N_("save &As... F12"), 'A', menu_save_as_cmd},
{' ', "", ' ', 0},
{' ', N_("&Insert file... F15"), 'I', menu_insert_file_cmd},
{' ', N_("copy to &File... "), 'F', menu_cut_cmd},
{' ', "", ' ', 0},
{' ', N_("&User menu... F11"), 'U', menu_user_menu_cmd},
/* {' ', N_("Menu edi&Tor edit "), 'T', edit_user_menu_cmd}, */
{' ', "", ' ', 0},
{' ', N_("a&Bout... "), 'B', edit_about_cmd},
{' ', "", ' ', 0},
{' ', N_("&Quit F10"), 'Q', menu_quit_cmd}
};
static menu_entry EditMenu[] =
{
{' ', N_("&Toggle Mark F3"), 'T', menu_mark_cmd},
{' ', N_("&Mark Columns S-F3"), 'T', menu_markcol_cmd},
{' ', "", ' ', 0},
{' ', N_("toggle &Ins/overw Ins"), 'I', menu_ins_cmd},
{' ', "", ' ', 0},
{' ', N_("&Copy F5"), 'C', menu_copy_cmd},
{' ', N_("&Move F6"), 'M', menu_move_cmd},
{' ', N_("&Delete F8"), 'D', menu_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("&Undo C-u"), 'U', menu_undo_cmd},
{' ', "", ' ', 0},
{' ', N_("&Beginning C-PgUp"), 'B', menu_beginning_cmd},
{' ', N_("&End C-PgDn"), 'E', menu_end_cmd}
};
static menu_entry EditMenuEmacs[] =
{
{' ', N_("&Toggle Mark F3"), 'T', menu_mark_cmd},
{' ', N_("&Mark Columns S-F3"), 'T', menu_markcol_cmd},
{' ', "", ' ', 0},
{' ', N_("toggle &Ins/overw Ins"), 'I', menu_ins_cmd},
{' ', "", ' ', 0},
{' ', N_("&Copy F5"), 'C', menu_copy_cmd},
{' ', N_("&Move F6"), 'M', menu_move_cmd},
{' ', N_("&Delete F8"), 'D', menu_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("&Undo C-u"), 'U', menu_undo_cmd},
{' ', "", ' ', 0},
{' ', N_("&Beginning C-PgUp"), 'B', menu_beginning_cmd},
{' ', N_("&End C-PgDn"), 'E', menu_end_cmd}
};
static menu_entry SearReplMenu[] =
{
{' ', N_("&Search... F7"), 'S', menu_search_cmd},
{' ', N_("search &Again F17"), 'A', menu_search_again_cmd},
{' ', N_("&Replace... F4"), 'R', menu_replace_cmd}
};
static menu_entry SearReplMenuEmacs[] =
{
{' ', N_("&Search... F7"), 'S', menu_search_cmd},
{' ', N_("search &Again F17"), 'A', menu_search_again_cmd},
{' ', N_("&Replace... F4"), 'R', menu_replace_cmd}
};
static menu_entry CmdMenu[] =
{
{' ', N_("&Goto line... M-l"), 'G', menu_goto_line},
{' ', N_("goto matching &Bracket M-b"), 'B', menu_goto_bracket},
{' ', "", ' ', 0},
{' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd},
{' ', "", ' ', 0},
{' ', N_("&Refresh screen C-l"), 'R', menu_refresh_cmd},
{' ', "", ' ', 0},
{' ', N_("&Start record macro C-r"), 'S', menu_begin_record_cmd},
{' ', N_("&Finish record macro... C-r"), 'F', menu_end_record_cmd},
{' ', N_("&Execute macro... C-a, KEY"), 'E', menu_exec_macro_cmd},
{' ', N_("delete macr&O... "), 'O', menu_exec_macro_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("insert &Date/time "), 'D', menu_date_cmd},
{' ', "", ' ', 0},
{' ', N_("format p&Aragraph M-p"), 'A', menu_format_paragraph},
{' ', N_("'ispell' s&Pell check C-p"), 'P', menu_ispell_cmd},
{' ', N_("sor&T... M-t"), 'T', menu_sort_cmd},
{' ', N_("E&xternal Formatter F19"), 'C', menu_c_form_cmd},
{' ', N_("&Mail... "), 'M', menu_mail_cmd}
};
static menu_entry CmdMenuEmacs[] =
{
{' ', N_("&Goto line... M-l"), 'G', menu_goto_line},
{' ', N_("goto matching &Bracket M-b"), 'B', menu_goto_bracket},
{' ', "", ' ', 0},
{' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd},
{' ', "", ' ', 0},
{' ', N_("&Refresh screen C-l"), 'R', menu_refresh_cmd},
{' ', "", ' ', 0},
{' ', N_("&Start record macro C-r"), 'S', menu_begin_record_cmd},
{' ', N_("&Finish record macro... C-r"), 'F', menu_end_record_cmd},
{' ', N_("&Execute macro... C-x e, KEY"), 'E', menu_exec_macro_cmd},
{' ', N_("delete macr&O... "), 'o', menu_exec_macro_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("insert &Date/time "), 'D', menu_date_cmd},
{' ', "", ' ', 0},
{' ', N_("format p&Aragraph M-p"), 'a', menu_format_paragraph},
{' ', N_("'ispell' s&Pell check M-$"), 'P', menu_ispell_cmd},
{' ', N_("sor&T... M-t"), 'T', menu_sort_cmd},
{' ', N_("E&xternal Formatter F19"), 'C', menu_c_form_cmd}
};
extern void menu_save_mode_cmd (void);
static menu_entry OptMenu[] =
{
{' ', N_("&General... "), 'G', menu_options},
{' ', N_("&Save mode..."), 'S', menu_save_mode_cmd}
#if 0
{' ', N_("&Layout..."), 'L', menu_layout_cmd}
#endif
};
static menu_entry OptMenuEmacs[] =
{
{' ', N_("&General... "), 'G', menu_options},
{' ', N_("&Save mode..."), 'S', menu_save_mode_cmd}
#if 0
{' ', N_("&Layout..."), 'L', menu_layout_cmd}
#endif
};
#define menu_entries(x) sizeof(x)/sizeof(menu_entry)
Menu EditMenuBar[N_menus];
void edit_init_menu_normal (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu));
EditMenuBar[1] = create_menu (_(" Edit "), EditMenu, menu_entries (EditMenu));
EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenu, menu_entries (SearReplMenu));
EditMenuBar[3] = create_menu (_(" Command "), CmdMenu, menu_entries (CmdMenu));
EditMenuBar[4] = create_menu (_(" Options "), OptMenu, menu_entries (OptMenu));
}
void edit_init_menu_emacs (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs));
EditMenuBar[1] = create_menu (_(" Edit "), EditMenuEmacs, menu_entries (EditMenuEmacs));
EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenuEmacs, menu_entries (SearReplMenuEmacs));
EditMenuBar[3] = create_menu (_(" Command "), CmdMenuEmacs, menu_entries (CmdMenuEmacs));
EditMenuBar[4] = create_menu (_(" Options "), OptMenuEmacs, menu_entries (OptMenuEmacs));
}
void edit_done_menu (void)
{
int i;
for (i = 0; i < N_menus; i++)
destroy_menu (EditMenuBar[i]);
}
void edit_drop_menu_cmd (WEdit * e, int which)
{
if (edit_menubar->active)
return;
edit_menubar->active = 1;
edit_menubar->dropped = drop_menus;
edit_menubar->previous_selection = which >= 0 ? which : dlg_item_number (edit_dlg);
if (which >= 0)
edit_menubar->selected = which;
dlg_select_widget (edit_dlg, edit_menubar);
}
void edit_menu_cmd (WEdit * e)
{
edit_drop_menu_cmd (e, -1);
}
int edit_drop_hotkey_menu (WEdit * e, int key)
{
int m = 0;
switch (key) {
case ALT ('f'):
if (edit_key_emulation == EDIT_KEY_EMULATION_EMACS)
return 0;
m = 0;
break;
case ALT ('e'):
m = 1;
break;
case ALT ('s'):
m = 2;
break;
case ALT ('c'):
m = 3;
break;
case ALT ('o'):
m = 4;
break;
default:
return 0;
}
edit_drop_menu_cmd (e, m);
return 1;
}
#else /* !MIDNIGHT */
extern CWidget *wedit;
void CSetEditMenu (const char *ident)
{
wedit = CIdent (ident);
}
CWidget *CGetEditMenu (void)
{
return wedit;
}
static void menu_cmd (unsigned long i)
{
XEvent e;
if (wedit) {
memset (&e, 0, sizeof (XEvent));
e.type = EditorCommand;
e.xkey.keycode = i;
e.xkey.window = wedit->winid;
CFocus (wedit);
CSendEvent (&e);
}
}
void CEditMenuCommand (int i)
{
menu_cmd ((unsigned long) i);
}
static void menu_key (KeySym i, int state)
{
int cmd, ch;
if (edit_translate_key (0, i, state, &cmd, &ch)) {
if (cmd > 0)
menu_cmd (cmd);
}
}
static void menu_ctrl_key (unsigned long i)
{
menu_key ((KeySym) i, ControlMask);
}
void CDrawEditMenuButtons (const char *ident, Window parent, Window focus_return, int x, int y)
{
int d;
CDrawMenuButton (catstrs (ident, ".filemenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 8,
/* The following are menu options. Do not change the key bindings (eg. C-o) and preserve '\t' */
_(" File "),
_("Open...\tC-o"), '~', menu_cmd, (unsigned long) CK_Load,
_("New\tC-n"), '~', menu_cmd, (unsigned long) CK_New,
"", ' ', (void *) 0, 0L,
_("Save\tF2"), '~', menu_cmd, (unsigned long) CK_Save,
_("Save as...\tF12"), '~', menu_cmd, (unsigned long) CK_Save_As,
"", ' ', (void *) 0, 0L,
_("Insert file...\tF15"), '~', menu_cmd, (unsigned long) CK_Insert_File,
_("Copy to file...\tC-f"), '~', menu_cmd, (unsigned long) CK_Save_Block
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".filemenu", 0), _("Disk operations and file indexing/searching"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".editmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 20,
_(" Edit "),
_("Toggle mark\tF3"), '~', menu_cmd, (unsigned long) CK_Mark,
_("Toggle mark columns\tC-b"), '~', menu_cmd, (unsigned long) CK_Column_Mark,
"", ' ', (void *) 0, 0L,
_("Toggle book mark\tC-M-Ins"), '~', menu_cmd, (unsigned long) CK_Toggle_Bookmark,
_("Previous book mark\tC-M-Up"), '~', menu_cmd, (unsigned long) CK_Prev_Bookmark,
_("Next book mark\tC-M-Down"), '~', menu_cmd, (unsigned long) CK_Next_Bookmark,
_("Flush book marks"), '~', menu_cmd, (unsigned long) CK_Flush_Bookmarks,
"", ' ', (void *) 0, 0L,
_("Toggle insert/overwrite\tIns"), '~', menu_cmd, (unsigned long) CK_Toggle_Insert,
"", ' ', (void *) 0, 0L,
_("Copy block to cursor\tF5"), '~', menu_cmd, (unsigned long) CK_Copy,
_("Move block to cursor\tF6"), '~', menu_cmd, (unsigned long) CK_Move,
_("Delete block\tF8/C-Del"), '~', menu_cmd, (unsigned long) CK_Remove,
"", ' ', (void *) 0, 0L,
_("Copy block to clipbrd\tC-Ins"), '~', menu_cmd, (unsigned long) CK_XStore,
_("Cut block to clipbrd\tS-Del"), '~', menu_cmd, (unsigned long) CK_XCut,
_("Paste block from clipbrd\tS-Ins"), '~', menu_cmd, (unsigned long) CK_XPaste,
_("Selection history\tM-Ins"), '~', menu_cmd, (unsigned long) CK_Selection_History,
"", ' ', (void *) 0, 0L,
_("Undo\tC-BackSpace"), '~', menu_cmd, (unsigned long) CK_Undo
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".editmenu", 0), _("Manipulating blocks of text"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".searchmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 4,
_(" Srch/Replce "),
_("Search...\tF7"), '~', menu_cmd, (unsigned long) CK_Find,
_("Search again\tF17"), '~', menu_cmd, (unsigned long) CK_Find_Again,
_("Replace...\tF4"), '~', menu_cmd, (unsigned long) CK_Replace,
_("Replace again\tF14"), '~', menu_cmd, (unsigned long) CK_Replace_Again
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".searchmenu", 0), _("Search for and replace text"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".commandmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 12,
_(" Command "),
_("Goto line...\tM-l"), '~', menu_cmd, (unsigned long) CK_Goto,
_("Goto matching bracket\tM-b"), '~', menu_cmd, (unsigned long) CK_Match_Bracket,
"", ' ', (void *) 0, 0L,
_("Start record macro\tC-r"), '~', menu_cmd, (unsigned long) CK_Begin_Record_Macro,
_("Finish record macro...\tC-r"), '~', menu_cmd, (unsigned long) CK_End_Record_Macro,
_("Execute macro...\tC-a, KEY"), '~', menu_ctrl_key, (unsigned long) XK_a,
_("Delete macro...\t"), '~', menu_cmd, (unsigned long) CK_Delete_Macro,
"", ' ', (void *) 0, 0L,
_("Insert date/time\tC-d"), '~', menu_cmd, (unsigned long) CK_Date,
_("Format paragraph\tM-p"), '~', menu_cmd, (unsigned long) CK_Paragraph_Format,
"", ' ', (void *) 0, 0L,
_("Refresh display\tC-l"), '~', menu_cmd, (unsigned long) CK_Refresh
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".commandmenu", 0), _("Macros and internal commands"));
}
#endif /* !MIDNIGHT */

209
edit/editoptions.c Normal file
View File

@ -0,0 +1,209 @@
/* editor options dialog box
Copyright (C) 1996, 1997 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#include <config.h>
#include "edit.h"
#define OPT_DLG_H 15
#define OPT_DLG_W 72
#ifndef USE_INTERNAL_EDIT
#define USE_INTERNAL_EDIT 1
#endif
#include "../src/main.h" /* extern int option_this_and_that ... */
char *key_emu_str[] =
{N_("Intuitive"), N_("Emacs"), NULL};
char *wrap_str[] =
{N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL};
extern int option_syntax_highlighting;
void i18n_translate_array (char *array[])
{
while (*array!=NULL) {
*array = _(*array);
array++;
}
}
void edit_options_dialog (void)
{
char wrap_length[32], tab_spacing[32], *p, *q;
int wrap_mode = 0;
int tedit_key_emulation = edit_key_emulation;
int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
int tedit_confirm_save = edit_confirm_save;
int tedit_syntax_highlighting = option_syntax_highlighting;
int toption_return_does_auto_indent = option_return_does_auto_indent;
int toption_backspace_through_tabs = option_backspace_through_tabs;
int toption_fake_half_tabs = option_fake_half_tabs;
QuickWidget quick_widgets[] =
{
/*0 */
{quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), 0, B_CANCEL, 0,
0, NULL},
/*1 */
{quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Ok"), 0, B_ENTER, 0,
0, NULL},
/*2 */
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, N_("Word wrap line length : "), 0, 0,
0, 0, NULL},
/*3 */
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
0, 0, "edit-word-wrap"},
/*4 */
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, N_("Tab spacing : "), 0, 0,
0, 0, NULL},
/*5 */
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
0, 0, "edit-tab-spacing"},
/*6 */
#if !defined(MIDNIGHT) || defined(HAVE_SYNTAXH)
#define OA 1
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("synta&X highlighting"), 8, 0,
0, 0, NULL},
#else
#define OA 0
#endif
/*7 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, N_("confir&M before saving"), 6, 0,
0, 0, NULL},
/*8 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H, N_("fill tabs with &Spaces"), 0, 0,
0, 0, NULL},
/*9 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H, N_("&Return does autoindent"), 0, 0,
0, 0, NULL},
/*10 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, N_("&Backspace through tabs"), 0, 0,
0, 0, NULL},
/*11 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("&Fake half tabs"), 0, 0,
0, 0, NULL},
/*12 */
{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, "", 3, 0,
0, wrap_str, "wrapm"},
/*13 */
{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Wrap mode"), 0, 0,
0, 0, NULL},
/*14 */
{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 2, 0,
0, key_emu_str, "keyemu"},
/*15 */
{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Key emulation"), 0, 0,
0, 0, NULL},
{0}};
static int i18n_flag = 0;
if (!i18n_flag) {
i18n_translate_array (key_emu_str);
i18n_translate_array (wrap_str);
i18n_flag = 1;
}
sprintf (wrap_length, "%d", option_word_wrap_line_length);
sprintf (tab_spacing, "%d", option_tab_spacing);
quick_widgets[3].text = wrap_length;
quick_widgets[3].str_result = &p;
quick_widgets[5].text = tab_spacing;
quick_widgets[5].str_result = &q;
quick_widgets[5 + OA].result = &tedit_syntax_highlighting;
quick_widgets[6 + OA].result = &tedit_confirm_save;
quick_widgets[7 + OA].result = &toption_fill_tabs_with_spaces;
quick_widgets[8 + OA].result = &toption_return_does_auto_indent;
quick_widgets[9 + OA].result = &toption_backspace_through_tabs;
quick_widgets[10 + OA].result = &toption_fake_half_tabs;
if (option_auto_para_formatting)
wrap_mode = 1;
else if (option_typewriter_wrap)
wrap_mode = 2;
else
wrap_mode = 0;
quick_widgets[11 + OA].result = &wrap_mode;
quick_widgets[11 + OA].value = wrap_mode;
quick_widgets[13 + OA].result = &tedit_key_emulation;
quick_widgets[13 + OA].value = tedit_key_emulation;
{
QuickDialog Quick_options =
{OPT_DLG_W, OPT_DLG_H, -1, 0, N_(" Editor options "),
"", "quick_input", 0};
Quick_options.widgets = quick_widgets;
if (quick_dialog (&Quick_options) != B_CANCEL) {
int old_syntax_hl = option_syntax_highlighting;
if (p) {
option_word_wrap_line_length = atoi (p);
free (p);
}
if (q) {
option_tab_spacing = atoi (q);
if (option_tab_spacing < 0)
option_tab_spacing = 2;
#if 0
/* Only allow even numbers */
option_tab_spacing += option_tab_spacing & 1;
#endif
free (q);
}
option_syntax_highlighting = *quick_widgets[5 + OA].result;
edit_confirm_save = *quick_widgets[6 + OA].result;
option_fill_tabs_with_spaces = *quick_widgets[7 + OA].result;
option_return_does_auto_indent = *quick_widgets[8 + OA].result;
option_backspace_through_tabs = *quick_widgets[9 + OA].result;
option_fake_half_tabs = *quick_widgets[10 + OA].result;
if (*quick_widgets[11 + OA].result == 1) {
option_auto_para_formatting = 1;
option_typewriter_wrap = 0;
} else if (*quick_widgets[11 + OA].result == 2) {
option_auto_para_formatting = 0;
option_typewriter_wrap = 1;
} else {
option_auto_para_formatting = 0;
option_typewriter_wrap = 0;
}
edit_key_emulation = *quick_widgets[13 + OA].result;
/* Load or unload syntax rules if the option has changed */
if (option_syntax_highlighting != old_syntax_hl)
edit_load_syntax (wedit, 0, 0);
return;
} else {
return;
}
}
}

1229
edit/editwidget.c Normal file

File diff suppressed because it is too large Load Diff

1575
edit/syntax.c Normal file

File diff suppressed because it is too large Load Diff

358
edit/wordproc.c Normal file
View File

@ -0,0 +1,358 @@
/* wordproc.c - word-processor mode for the editor: does dynamic
paragraph formatting.
Copyright (C) 1996 Paul Sheer
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#include <config.h>
#include "edit.h"
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
#ifdef MIDNIGHT
#define tab_width option_tab_spacing
#endif
int line_is_blank (WEdit * edit, long line);
#define NO_FORMAT_CHARS_START "-+*\\,.;:&>"
static long line_start (WEdit * edit, long line)
{
static long p = -1, l = 0;
int c;
if (p == -1 || abs (l - line) > abs (edit->curs_line - line)) {
l = edit->curs_line;
p = edit->curs1;
}
if (line < l)
p = edit_move_backward (edit, p, l - line);
else if (line > l)
p = edit_move_forward (edit, p, line - l, 0);
l = line;
p = edit_bol (edit, p);
while (strchr ("\t ", c = edit_get_byte (edit, p)))
p++;
return p;
}
static int bad_line_start (WEdit * edit, long p)
{
int c;
c = edit_get_byte (edit, p);
if (c == '.') { /* `...' is acceptable */
if (edit_get_byte (edit, p + 1) == '.')
if (edit_get_byte (edit, p + 2) == '.')
return 0;
return 1;
}
if (c == '-') {
if (edit_get_byte (edit, p + 1) == '-')
if (edit_get_byte (edit, p + 2) == '-')
return 0; /* `---' is acceptable */
return 1;
}
if (strchr (NO_FORMAT_CHARS_START, c))
return 1;
return 0;
}
static long begin_paragraph (WEdit * edit, long p, int force)
{
int i;
for (i = edit->curs_line - 1; i > 0; i--) {
if (line_is_blank (edit, i)) {
i++;
break;
}
if (force) {
if (bad_line_start (edit, line_start (edit, i))) {
i++;
break;
}
}
}
return edit_move_backward (edit, edit_bol (edit, edit->curs1), edit->curs_line - i);
}
static long end_paragraph (WEdit * edit, long p, int force)
{
int i;
for (i = edit->curs_line + 1; i < edit->total_lines; i++) {
if (line_is_blank (edit, i)) {
i--;
break;
}
if (force)
if (bad_line_start (edit, line_start (edit, i))) {
i--;
break;
}
}
return edit_eol (edit, edit_move_forward (edit, edit_bol (edit, edit->curs1), i - edit->curs_line, 0));
}
static unsigned char *get_paragraph (WEdit * edit, long p, long q, int indent, int *size)
{
unsigned char *s, *t;
#if 0
t = malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10);
#else
t = malloc (2 * (q - p) + 100);
#endif
if (!t)
return 0;
for (s = t; p < q; p++, s++) {
if (indent)
if (edit_get_byte (edit, p - 1) == '\n')
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
*s = edit_get_byte (edit, p);
}
*size = (unsigned long) s - (unsigned long) t;
t[*size] = '\n';
return t;
}
static void strip_newlines (unsigned char *t, int size)
{
unsigned char *p = t;
while (size--) {
*p = *p == '\n' ? ' ' : *p;
p++;
}
}
#ifndef MIDNIGHT
int edit_width_of_long_printable (int c);
#endif
/*
This is a copy of the function
int calc_text_pos (WEdit * edit, long b, long *q, int l)
in propfont.c :(
It calculates the number of chars in a line specified to length l in pixels
*/
extern int tab_width;
static inline int next_tab_pos (int x)
{
return x += tab_width - x % tab_width;
}
static int line_pixel_length (unsigned char *t, long b, int l)
{
int x = 0, c, xn = 0;
for (;;) {
c = t[b];
switch (c) {
case '\n':
return b;
case '\t':
xn = next_tab_pos (x);
break;
default:
#ifdef MIDNIGHT
xn = x + 1;
#else
xn = x + edit_width_of_long_printable (c);
#endif
break;
}
if (xn > l)
break;
x = xn;
b++;
}
return b;
}
/* find the start of a word */
static int next_word_start (unsigned char *t, int q, int size)
{
int i;
for (i = q;; i++) {
switch (t[i]) {
case '\n':
return -1;
case '\t':
case ' ':
for (;; i++) {
if (t[i] == '\n')
return -1;
if (t[i] != ' ' && t[i] != '\t')
return i;
}
break;
}
}
}
/* find the start of a word */
static int word_start (unsigned char *t, int q, int size)
{
int i = q;
if (t[q] == ' ' || t[q] == '\t')
return next_word_start (t, q, size);
for (;;) {
int c;
if (!i)
return -1;
c = t[i - 1];
if (c == '\n')
return -1;
if (c == ' ' || c == '\t')
return i;
i--;
}
}
/* replaces ' ' with '\n' to properly format a paragraph */
static void format_this (unsigned char *t, int size, int indent)
{
int q = 0, ww;
strip_newlines (t, size);
ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent;
if (ww < FONT_MEAN_WIDTH * 2)
ww = FONT_MEAN_WIDTH * 2;
for (;;) {
int p;
q = line_pixel_length (t, q, ww);
if (q > size)
break;
if (t[q] == '\n')
break;
p = word_start (t, q, size);
if (p == -1)
q = next_word_start (t, q, size); /* Return the end of the word if the beginning
of the word is at the beginning of a line
(i.e. a very long word) */
else
q = p;
if (q == -1) /* end of paragraph */
break;
if (q)
t[q - 1] = '\n';
}
}
static void replace_at (WEdit * edit, long q, int c)
{
edit_cursor_move (edit, q - edit->curs1);
edit_delete (edit);
edit_insert_ahead (edit, c);
}
void edit_insert_indent (WEdit * edit, int indent);
/* replaces a block of text */
static void put_paragraph (WEdit * edit, unsigned char *t, long p, long q, int indent, int size)
{
long cursor;
int i, c = 0;
cursor = edit->curs1;
if (indent)
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
for (i = 0; i < size; i++, p++) {
if (i && indent) {
if (t[i - 1] == '\n' && c == '\n') {
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
} else if (t[i - 1] == '\n') {
long curs;
edit_cursor_move (edit, p - edit->curs1);
curs = edit->curs1;
edit_insert_indent (edit, indent);
if (cursor >= curs)
cursor += edit->curs1 - p;
p = edit->curs1;
} else if (c == '\n') {
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p))) {
edit_delete (edit);
if (cursor > edit->curs1)
cursor--;
}
p = edit->curs1;
}
}
c = edit_get_byte (edit, p);
if (c != t[i])
replace_at (edit, p, t[i]);
}
edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */
}
int edit_indent_width (WEdit * edit, long p);
static int test_indent (WEdit * edit, long p, long q)
{
int indent;
indent = edit_indent_width (edit, p++);
if (!indent)
return 0;
for (; p < q; p++)
if (edit_get_byte (edit, p - 1) == '\n')
if (indent != edit_indent_width (edit, p))
return 0;
return indent;
}
void format_paragraph (WEdit * edit, int force)
{
long p, q;
int size;
unsigned char *t;
int indent = 0;
if (option_word_wrap_line_length < 2)
return;
if (line_is_blank (edit, edit->curs_line))
return;
p = begin_paragraph (edit, edit->curs1, force);
q = end_paragraph (edit, edit->curs1, force);
indent = test_indent (edit, p, q);
t = get_paragraph (edit, p, q, indent, &size);
if (!t)
return;
if (!force) {
int i;
if (strchr (NO_FORMAT_CHARS_START, *t)) {
free (t);
return;
}
for (i = 0; i < size - 1; i++) {
if (t[i] == '\n') {
if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) {
free (t);
return;
}
}
}
}
format_this (t, q - p, indent);
put_paragraph (edit, t, p, q, indent, size);
free (t);
}