diff --git a/.gitignore b/.gitignore index 66f1def..5833845 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o atto debug.out - +*~ +.redo/* diff --git a/CHANGE.LOG.md b/CHANGE.LOG.md index f3d44b9..48d2f11 100644 --- a/CHANGE.LOG.md +++ b/CHANGE.LOG.md @@ -1,5 +1,9 @@ # Atto Emacs Change Log +# Atto v1.22f1 19 Jul 2022 +* Add C-z command to suspend the editor. +* Load all files on command line and optionally jump to a specified line. + ## Atto v1.22 06 Dec 2020 * fixed some color issues when running on Arch, needed to set color in modeline and msg line diff --git a/README.md b/README.md index d409b25..b2f5196 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # Atto Emacs +This is Atto v1.22f1 with a small set of additions be Georg Lehner + The smallest functional Emacs in less than 2000 lines of C. Atto Emacs is inspired by MicroEmacs, Nano, Pico and my earlier project known as Perfect Emacs [1]. - ![Atto screenshot](https://github.com/hughbarney/atto/blob/master/screenshots/atto.png) @@ -71,6 +72,7 @@ Atto is based on the public domain code of Anthony Howe's editor (commonly known C-W Kill Region (Cut) C-X CTRL-X command prefix C-Y Yank (Paste) + C-Y Suspend the Atto process (Run 'fg' at the shell to resume it) M-< Start of file M-> End of file diff --git a/atto.equivs b/atto.equivs new file mode 100644 index 0000000..0c804f8 --- /dev/null +++ b/atto.equivs @@ -0,0 +1,24 @@ +# leg20220722: atto Debian packaging +Package: atto +Version: 1.22f-1.0 +Priority: optional +Section: editors +Maintainer: Georg Lehner +Homepage: https://github.com/jorge-leon/atto +Tag: implemented-in::c, interface::text-mode, role::program, + scope::application, uitoolkit::ncurses, use::editing, + works-with::text, works-with::unicode +Description: The smallest functional Emacs in less than 2000 lines of C. + Atto is a small, multi buffer, multi window text editor for the console + with UTF-8 support and Emacs key bindings. + +Architecture: any +Standards-Version: 3.9.2 +Copyright: debian/public_domain +Readme: debian/README.Debian +Changelog: debian/changelog.Debian +Extra-Files: README.md +Files: atto /usr/bin/ + +Postinst: debian/postinst +Prerm: debian/prerm diff --git a/clean.do b/clean.do new file mode 100755 index 0000000..eed21b0 --- /dev/null +++ b/clean.do @@ -0,0 +1,6 @@ +#!/bin/sh +exec >&2 + +make clean + +rm -f atto_*.buildinfo atto_*.changes atto*.deb diff --git a/command.c b/command.c index edbc2d9..1adc870 100644 --- a/command.c +++ b/command.c @@ -354,3 +354,5 @@ void showpos() curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap))); } } + +void suspend() { raise(SIGTSTP); } diff --git a/deb.do b/deb.do new file mode 100755 index 0000000..c5b6b13 --- /dev/null +++ b/deb.do @@ -0,0 +1,5 @@ +#!/bin/sh +exec >&2 + +make atto +equivs-build atto.equivs diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..0b36aad --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,13 @@ +atto for Debian is built with equivs. + +Installation instructions: + +sudo apt install libncurses-dev equivs build-essential +git clone https://github.com/jorge-leon/atto +cd atto +sh deb.do +sudo dpkg -i atto_*.deb + +Set up atto as default editor: + +sudo update-alternatives --set editor /usr/bin/atto diff --git a/debian/changelog.Debian b/debian/changelog.Debian new file mode 100644 index 0000000..69c4a38 --- /dev/null +++ b/debian/changelog.Debian @@ -0,0 +1,5 @@ +atto (1.22f-1.0) stable; urgency=low + + * Initial Debian packaging + + -- Georg Lehner Sat, 23 Jul 2022 09:40:24 +0200 diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..3ab1f93 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +update-alternatives --install /usr/bin/editor editor /usr/bin/atto 30 diff --git a/debian/prerm b/debian/prerm new file mode 100755 index 0000000..8d2e0dc --- /dev/null +++ b/debian/prerm @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +if [ "$1" != "upgrade" ] +then + update-alternatives --remove editor /usr/bin/atto +fi + + diff --git a/debian/public_domain b/debian/public_domain new file mode 100644 index 0000000..a883365 --- /dev/null +++ b/debian/public_domain @@ -0,0 +1,2 @@ +Atto code is released to the public domain. +hughbarney AT gmail.com 2017 diff --git a/gap.c b/gap.c index c17b055..f10a22e 100644 --- a/gap.c +++ b/gap.c @@ -87,7 +87,7 @@ point_t pos(buffer_t *bp, register char_t *cp) int posix_file(char *fn) { - if (fn[0] == '_') + if (fn[0] == '-') return (FALSE); for (; *fn != '\0'; ++fn) { diff --git a/header.h b/header.h index 06d71fd..5da81bd 100644 --- a/header.h +++ b/header.h @@ -12,9 +12,10 @@ #include #include #include +#include int mkstemp(char *); -#define VERSION "Atto 1.22, Public Domain, Dec 2020, by Hugh Barney, No warranty." +#define VERSION "Atto 1.22f1, Public Domain, Dec 2020, by Hugh Barney, No warranty." #define PROG_NAME "atto" #define B_MODIFIED 0x01 /* modified buffer */ #define B_OVERWRITE 0x02 /* overwite mode */ @@ -155,6 +156,7 @@ extern void left(void); extern void lnbegin(void); extern void lnend(void); extern void paste(void); +extern void suspend(void); extern void pgdown(void); extern void pgup(void); extern void quit(void); @@ -206,3 +208,4 @@ extern void set_parse_state(buffer_t *, point_t); extern void set_parse_state2(buffer_t *, point_t); extern int parse_text(buffer_t *, point_t); extern void resize_terminal(); +extern void arguments(int argc, char **argv); diff --git a/key.c b/key.c index a4b76ca..aa2db42 100644 --- a/key.c +++ b/key.c @@ -19,6 +19,7 @@ keymap_t keymap[] = { {"C-v forward-page ", "\x16", pgdown }, {"C-w kill-region ", "\x17", cut}, {"C-y yank ", "\x19", paste}, + {"C-z suspend ", "\x1A", suspend}, {"C-space set-mark ", "\x00", iblock }, /* ctrl-space */ {"C-x 1 delete-other-window", "\x18\x31", delete_other_windows }, {"C-x 2 split-window ", "\x18\x32", split_window }, diff --git a/main.c b/main.c index 933b07b..269ad1a 100644 --- a/main.c +++ b/main.c @@ -37,17 +37,11 @@ int main(int argc, char **argv) init_pair(ID_LINE_COMMENT, COLOR_GREEN, COLOR_BLACK); /* line comments */ init_pair(ID_SINGLE_STRING, COLOR_YELLOW, COLOR_BLACK); /* single quoted strings */ init_pair(ID_DOUBLE_STRING, COLOR_YELLOW, COLOR_BLACK); /* double quoted strings */ - - if (1 < argc) { - curbp = find_buffer(argv[1], TRUE); - (void) insert_file(argv[1], FALSE); - /* Save filename irregardless of load() success. */ - strncpy(curbp->b_fname, argv[1], NAME_MAX); - curbp->b_fname[NAME_MAX] = '\0'; /* force truncation */ - } else { - curbp = find_buffer("*scratch*", TRUE); - strncpy(curbp->b_bname, "*scratch*", STRBUF_S); - } + + curbp = find_buffer("*scratch*", TRUE); + strncpy(curbp->b_bname, "*scratch*", STRBUF_S); + + arguments(argc, argv); wheadp = curwp = new_window(); one_window(curwp); @@ -66,7 +60,7 @@ int main(int argc, char **argv) /* allow TAB and NEWLINE, otherwise any Control Char is 'Not bound' */ if (*input > 31 || *input == 10 || *input == 9) insert(); - else { + else { flushinp(); /* discard without writing in buffer */ msg("Not bound"); } @@ -81,6 +75,35 @@ int main(int argc, char **argv) return 0; } +void arguments(int argc, char **argv) +{ + int i, ln = 0, opts = 1; + point_t p; + + for (i=1; i < argc; i++) { + if (!strcmp(argv[i], "--")) { + opts = 0; + continue; + } + if (opts && argv[i][0] == '+') { + ln = atoi(argv[i]+1); + continue; + } + + curbp = find_buffer(argv[i], TRUE); + (void) insert_file(argv[i], FALSE); + /* Save filename irregardless of load() success. */ + strncpy(curbp->b_fname, argv[i], NAME_MAX); + curbp->b_fname[NAME_MAX] = '\0'; /* force truncation */ + + if (ln > 0) { + p = line_to_point(ln); + if (p != -1) curbp->b_point = p; + ln = 0; + } + } +} + void fatal(char *msg) { if (curscr != NULL) { diff --git a/makefile b/makefile index 20e81a0..a4591a7 100644 --- a/makefile +++ b/makefile @@ -6,6 +6,10 @@ # Public Domain 1991, 1993 by Anthony Howe. No warranty. # +BINDIR = /usr/local/bin +DOCDIR = /usr/local/share/doc/atto +DESTDIR = + CC = cc CFLAGS = -O -Wall @@ -16,6 +20,7 @@ LIBS = -lncursesw CP = cp MV = mv RM = rm +MKDIR = mkdir E = O = .o @@ -59,8 +64,19 @@ main$(O): main.c header.h $(CC) $(CFLAGS) -c main.c clean: - -$(RM) $(OBJ) atto$(E) + -$(RM) -f $(OBJ) atto$(E) + +install: atto$(E) + $(MKDIR) -p $(DESTDIR)$(BINDIR) + $(CP) atto$(E) $(DESTDIR)$(BINDIR) + +uninstall: + -$(RM) $(DESTDIR)$(BINDIR)/atto$(E) + @echo not removing $(DESTDIR)$(BINDIR) -install: - -$(MV) atto$(E) /usr/local/bin/ +install-doc: + $(MKDIR) -p $(DESTDIR)$(DOCDIR) + $(CP) README.md $(DESTDIR)$(DOCDIR)/ +uninstall-doc: + $(RM) -rf $(DESTDIR)$(DOCDIR)