Skip to content

Commit

Permalink
acme: shift button 3 for reverse search
Browse files Browse the repository at this point in the history
An experiment. Let's see if it's any good.
Also document the Mac conventions in devdraw(3).
  • Loading branch information
rsc committed Jun 15, 2024
1 parent 60ca2be commit 0c79c32
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 99 deletions.
21 changes: 13 additions & 8 deletions man/man1/0intro.1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ conventionally
When programs need to access files in the tree,
they expect the
.B $PLAN9
environment variable
environment variable
to contain the name of the root of the tree.
See
.MR install (1)
Expand Down Expand Up @@ -57,7 +57,7 @@ expect Plan 9 regular expressions
(see
.MR regexp (7) ),
which are closest to what Unix calls extended regular expressions.
Because of these differences, it is not recommended to put
Because of these differences, it is not recommended to put
.B $PLAN9/bin
before the usual system
.B bin
Expand Down Expand Up @@ -99,6 +99,11 @@ The argument is one of
\fL'\fIxmin ymin xmax ymax\fL'\fR,
\fRor
\fIxmin\fL,\fIymin\fL,\fIxmax\fL,\fIymax\fR.
See
.MR devdraw (1)
and
.MR keyboard (7)
for details about typing and clicking in graphical applications.
.PP
The
.MR plumber (4)
Expand Down Expand Up @@ -135,7 +140,7 @@ is an experimental client for acme.
Some programs rely on large databases that would be
cumbersome to include in every release.
Scripts are provided that download these databases separately.
These databases can be downloaded separately.
These databases can be downloaded separately.
See
.B $PLAN9/dict/README
and
Expand All @@ -148,7 +153,7 @@ and
(see
.MR 9c (1) )
provide a simple interface to the underlying system compiler and linker,
similar to the
similar to the
.I 2c
and
.I 2l
Expand Down Expand Up @@ -201,7 +206,7 @@ cannot)
and dump data structures,
but that it is the extent to which they have been developed and exercised.
.SS Porting programs
The vast majority of the familiar Plan 9 programs
The vast majority of the familiar Plan 9 programs
have been ported, including the Unicode-aware
.MR troff (1) .
.PP
Expand All @@ -222,7 +227,7 @@ is in progress; see
.SS Porting to new systems
Porting the tree to new operating systems or architectures
should be straightforward, as system-specific code has been
kept to a minimum.
kept to a minimum.
The largest pieces of system-specific code are
.BR <u.h> ,
which must include the right system files and
Expand All @@ -231,7 +236,7 @@ and
.IR libthread ,
which must implement spin locks, operating system thread
creation, and context switching routines.
Portable implementations of these using
Portable implementations of these using
.B <pthread.h>
and
.B <ucontext.h>
Expand Down Expand Up @@ -259,7 +264,7 @@ so that the Unix
utility can handle it.
Some systems, for example Debian Linux,
deduce the man page locations from the search path, so that
adding
adding
.B $PLAN9/bin
to your path is sufficient to cause
.B $PLAN9/man
Expand Down
5 changes: 5 additions & 0 deletions man/man1/acme.1
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ not just
or
.BR 127 .
(There is an easier way to locate literal text; see below.)
If shift is held down during the selection or click,
any leading regular expression search defaults to
searching backward in the text instead of forward.
.PP
If the text is a file name followed by a colon and an address,
.I acme
Expand All @@ -608,6 +611,8 @@ moved there. Thus, to search for occurrences of a word in a file,
just click button 3 on the word. Because of the rule of using the
selection as the button 3 action, subsequent clicks will find subsequent
occurrences without moving the mouse.
If shift is held down during the selection or click,
the search looks backward in the file.
.PP
In all these actions, the mouse motion is not done if the text is a null string
within a non-null selected string in the tag, so that (for example) complex regular expressions
Expand Down
70 changes: 61 additions & 9 deletions man/man1/devdraw.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,79 @@
.SH NAME
devdraw \- draw device simulator
.SH SYNOPSIS
invoked via
invoked via
.I initdraw
(see
.MR graphics (3) )
.SH DESCRIPTION
.I Devdraw
serves a custom graphics protocol and is the only program
that talks directly to X window servers.
On Macintosh, setting
.BI devdrawretina
to
.BI 1
will cause
.I devdraw
to use all available physical pixels on a retina display.
.PP
.SS "Apple macOS
.PP
On macOS, because a laptop trackpad click only has one button (the trackpad itself)
Option-click is button 2, and Command-click is button 3.
While the main mouse button is held down,
Control, Option, and Command serve as simulated buttons 1, 2, 3 for chording in
.MR acme (4) .
For example, the 1-3 pasting chord in acme can be executed by
highlighting text while holding down the trackpad button
and then, while still holding down the button, pressing the Command key.
.PP
As usual, buttons 4 and 5 represent a scroll wheel.
Two-finger scrolling on the trackpad sends those button events.
.PP
Holding down shift while clicking adds 5 to the button number.
For example, Command-Click is button 3, so Command-Shift-Click is button 8.
Most programs do not respond to those buttons; one notable exception is
.MR acme (1) ,
which interprets button 8 (shifted button 3) as a reverse search.
.PP
Typing Command-F toggles full screen mode.
.PP
.I Devdraw
automatically detects high-resolution (retina) displays.
For debugging, typing Command-R toggles retina mode.
.PP
Other than the special cases mentioned above,
holding down Command while typing a character
.B Kcmd
(0xF100)
plus that character.
Some programs (notably
.IR acme (1))
recognize standard keyboard shortcuts such as
Command-Z (undo), Command-Shift-Z (redo),
Command-X (cut), and Command-V (paste).
.SS "X Windows
.PP
On Unix systems, Control-click is mouse button 2,
and Alt-click is mouse button 3.
While the main mouse button is held down,
Control and Alt serve as simulated buttons 2, 3 for chording in
.MR acme (4) .
For example, the 1-3 pasting chord in acme can be executed by
highlighting text while holding down the trackpad button
and then, while still holding down the button, pressing the Alt key.
.PP
Because the Control and Alt keys have other meanings
(see
.MR keyboard (7)
for the Alt key's meaning)
and there is no third modifier key like on the Mac,
there is no way to type
.B Kcmd
variants,
so there is no access to keyboard shortcuts for
undo, redo, cut, and paste.
.SH SOURCE
.B \*9/src/cmd/devdraw
.SH "SEE ALSO
.MR draw (3) ,
.MR drawfcall (3) ,
.MR graphics (3)
.MR graphics (3) ,
.MR keyboard (7)
.SH BUGS
.I Devdraw
should probably present a standard 9P server
Expand Down
4 changes: 4 additions & 0 deletions man/man4/acme.4
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ for text inserted to the tag,
for a button 3 action in the body,
.B l
for a button 3 action in the tag,
.B R
for a shifted button 3 action in the body,
.B r
for a shifted button 3 action in the tag,
.B X
for a button 2 action in the body, and
.B x
Expand Down
11 changes: 3 additions & 8 deletions man/man7/keyboard.7
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ Any rune can be typed using a compose key followed by several
other keys.
The compose key is also generally near the lower right of the main key area:
the
.B NUM PAD
key on the Gnot, the
.B Alternate
key on the Next, the
.B Compose
key on the SLC, the
.B Option
key on the Magnum, and either
key on the Mac
and the
.B Alt
key on the PC.
key on Unix systems.
To type a single rune with the value specified by
a given four-digit hexadecimal number,
type the compose key,
Expand Down
22 changes: 21 additions & 1 deletion src/cmd/9term/9term.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <u.h>
#include <pwd.h>
#include <signal.h>
#include <libc.h>
#include <ctype.h>
Expand Down Expand Up @@ -56,14 +57,33 @@ threadmaybackground(void)
void
threadmain(int argc, char *argv[])
{
char *p;
char *p, *env;

rfork(RFNOTEG);
font = nil;
_wantfocuschanges = 1;
mainpid = getpid();
messagesize = 8192;

threadmaybackground();

env = getenv("__CFBundleIdentifier");
if(env != nil && strcmp(env, "com.swtch.9term") == 0) {
// Being invoked as $PLAN9/mac/9term.app.
// Set $SHELL and daemonize to let parent exit.
// This makes sure that each click on 9term
// brings up a new window.
extern void _threaddaemonize(void);
struct passwd *pw;

unsetenv("__CFBundleIdentifier");
pw = getpwuid(getuid());
if(pw != nil && pw->pw_shell != nil)
setenv("SHELL", pw->pw_shell, 1);
loginshell = TRUE;
//_threaddaemonize();
}

ARGBEGIN{
default:
usage();
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/acme/acme.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ mousethread(void *v)
Mouse m;
char *act;
enum { MResize, MMouse, MPlumb, MWarnings, NMALT };
enum { Shift = 5 };
static Alt alts[NMALT+1];

USED(v);
Expand Down Expand Up @@ -661,9 +662,9 @@ mousethread(void *v)
}else if(m.buttons & 2){
if(textselect2(t, &q0, &q1, &argt))
execute(t, q0, q1, FALSE, argt);
}else if(m.buttons & 4){
}else if(m.buttons & (4|(4<<Shift))){
if(textselect3(t, &q0, &q1))
look3(t, q0, q1, FALSE);
look3(t, q0, q1, FALSE, (m.buttons&(4<<Shift))!=0);
}
if(w)
winunlock(w);
Expand Down Expand Up @@ -770,7 +771,7 @@ waitthread(void *v)
pids = p;
}
}else{
if(search(t, c->name, c->nname)){
if(search(t, c->name, c->nname, FALSE)){
textdelete(t, t->q0, t->q1, TRUE);
textsetselect(t, 0, 0);
}
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/acme/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ regexp(uint showerr, Text *t, Range lim, Range r, Rune *pat, int dir, int *found
}

Range
address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, int (*getc)(void*, uint), int *evalp, uint *qp)
address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, int (*getc)(void*, uint), int *evalp, uint *qp, int reverse)
{
int dir, size, npat;
int prevc, c, nc, n;
Expand All @@ -183,6 +183,8 @@ address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, i
r = ar;
q = q0;
dir = None;
if(reverse)
dir = Back;
size = Line;
c = 0;
while(q < q1){
Expand All @@ -201,7 +203,7 @@ address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, i
if(q>=q1 && t!=nil && t->file!=nil) /* rhs defaults to $ */
r.q1 = t->file->b.nc;
else{
nr = address(showerr, t, lim, ar, a, q, q1, getc, evalp, &q);
nr = address(showerr, t, lim, ar, a, q, q1, getc, evalp, &q, FALSE);
r.q1 = nr.q1;
}
*qp = q;
Expand Down
1 change: 1 addition & 0 deletions src/cmd/acme/dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ struct Expand
int nname;
char *bname;
int jump;
int reverse;
union{
Text *at;
Rune *ar;
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/acme/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,14 @@ getarg(Text *argt, int doaddr, int dofile, Rune **rp, int *nrp)
Expand e;
char *a;

memset(&e, 0, sizeof e);
*rp = nil;
*nrp = 0;
if(argt == nil)
return nil;
a = nil;
textcommit(argt, TRUE);
if(expand(argt, argt->q0, argt->q1, &e)){
if(expand(argt, argt->q0, argt->q1, &e, FALSE)){
free(e.bname);
if(e.nname && dofile){
e.name = runerealloc(e.name, e.nname+1);
Expand Down Expand Up @@ -1083,7 +1084,7 @@ look(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
if(et && et->w){
t = &et->w->body;
if(narg > 0){
search(t, arg, narg);
search(t, arg, narg, FALSE);
return;
}
getarg(argt, FALSE, FALSE, &r, &n);
Expand All @@ -1092,7 +1093,7 @@ look(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
r = runemalloc(n);
bufread(&t->file->b, t->q0, r, n);
}
search(t, r, n);
search(t, r, n, FALSE);
free(r);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/acme/fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void fontx(Text*, Text*, Text*, int, int, Rune*, int);
#define isalnum acmeisalnum
int isalnum(Rune);
void execute(Text*, uint, uint, int, Text*);
int search(Text*, Rune*, uint);
void look3(Text*, uint, uint, int);
int search(Text*, Rune*, uint, int);
void look3(Text*, uint, uint, int, int);
void editcmd(Text*, Rune*, uint);
uint min(uint, uint);
uint max(uint, uint);
Expand All @@ -85,11 +85,11 @@ int isregexc(int);
void *emalloc(uint);
void *erealloc(void*, uint);
char *estrdup(char*);
Range address(uint, Text*, Range, Range, void*, uint, uint, int (*)(void*, uint), int*, uint*);
Range address(uint, Text*, Range, Range, void*, uint, uint, int (*)(void*, uint), int*, uint*, int);
int rxexecute(Text*, Rune*, uint, uint, Rangeset*);
int rxbexecute(Text*, uint, Rangeset*);
Window* makenewwindow(Text *t);
int expand(Text*, uint, uint, Expand*);
int expand(Text*, uint, uint, Expand*, int);
Rune* skipbl(Rune*, int, int*);
Rune* findbl(Rune*, int, int*);
char* edittext(Window*, int, Rune*, int);
Expand Down
Loading

1 comment on commit 0c79c32

@shoce
Copy link

@shoce shoce commented on 0c79c32 Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huge thanks for this 🔥

Please sign in to comment.