--- a/joe/main.c
+++ b/joe/main.c
@@ -84,6 +84,8 @@
 	}
 }
 
+MACRO *type_backtick;
+
 int edloop(int flg)
 {
 	int term = 0;
@@ -99,6 +101,8 @@
 		MACRO *m;
 		BW *bw;
 		int c;
+		int auto_off = 0;
+		int word_off = 0;
 
 		if (exmsg && !flg) {
 			vsrm(exmsg);
@@ -116,12 +120,28 @@
 		if (!ahead && c == 10)
 			c = 13;
 
+		more_no_auto:
+
 		/* Use special kbd if we're handing data to a shell window */
 		bw = (BW *)maint->curwin->object;
 		if ((maint->curwin->watom->what & TYPETW) && bw->b->pid && bw->cursor->byte == bw->b->vt->vtcur->byte)
 			m = dokey(bw->b->vt->kbd, c);
 		else
 			m = dokey(maint->curwin->kbd, c);
+
+		/* leading part of backtick hack... */
+		if (m && m->cmd && m->cmd->func == uquote && ttcheck()) {
+			m = type_backtick;
+		}
+
+		/* disable autoindent if it looks like a mouse paste... */
+		if (m && m->cmd && (m->cmd->func == utype || m->cmd->func == urtn) && (maint->curwin->watom->what & TYPETW) && (bw->o.autoindent || bw->o.wordwrap) && ttcheck()) {
+			auto_off = bw->o.autoindent;
+			bw->o.autoindent = 0;
+			word_off = bw->o.wordwrap;
+			bw->o.wordwrap = 0;
+		}
+
 		if (maint->curwin->main && maint->curwin->main != maint->curwin) {
 			int x = maint->curwin->kbd->x;
 
@@ -131,6 +151,29 @@
 		}
 		if (m)
 			ret = exemac(m);
+
+		/* trailing part of backtick hack... */
+		while (!leave && (!flg || !term) && m && (m == type_backtick || m->cmd && (m->cmd->func == utype || m->cmd->func == urtn)) && ttcheck() && havec == '`') {
+			ttgetc();
+			ret = exemac(type_backtick);
+		}
+
+		/* trailing part of disabled autoindent */
+		if (!leave && (!flg || !term) && m && (m == type_backtick || m->cmd && (m->cmd->func == utype || m->cmd->func == urtn)) && ttcheck()) {
+			c = ttgetc();
+			goto more_no_auto;
+		}
+
+		if (auto_off) {
+			auto_off = 0;
+			bw->o.autoindent = 1;
+		}
+
+		if (word_off) {
+			word_off = 0;
+			bw->o.wordwrap = 1;
+		}
+
 	}
 
 	if (term == -1)
@@ -373,6 +416,12 @@
 		return 1;
 	}
 
+	{
+		unsigned char buf[10];
+		int x;
+		zcpy(buf, USTR "\"`\"	`  ");
+		type_backtick = mparse(0, buf, &x);
+	}
 
 	if (!isatty(fileno(stdin)))
 		idleout = 0;