Skip to content

Commit

Permalink
new features: text direction, directional macro calls ↑→↓←
Browse files Browse the repository at this point in the history
  • Loading branch information
c committed Nov 9, 2024
1 parent 03cb4f2 commit 4885403
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 24 deletions.
81 changes: 81 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,87 @@ move surrounding characters.
and killed rectangles, =killed-rectangle=. So, a rectangle can be killed
one way, and yanked another way.

* Text direction
Usually, inserting text in a buffer moves the cursor to the right. (And
sometimes to the left for some locales). Any of the 4 directions can be
selected under Uniline. Just type any of:

#+begin_example
INS C-<up>
INS C-<right>
INS C-<down>
INS C-<left>
#+end_example

The current direction is reflected in the mode-line, just before the
word "uniline".

* Macros
Uniline adds directional macros to the Emacs standard macros.

Record a macro as usual with =C-x (= … =C-x )=.

Then call it with the usual =C-x e=. But then, instead of executing
the macro, a menu is offered to execute it in any of the 4 directions.

When a macro is executed in a direction other than the one it was
recorded, it is twisted in that direction. This means that recorded
hits on the 4 keyboard arrows are rotated. It happens also for shift
and control variations of those keys. Direction of text insertion is
also rotated.

There is still the classical =e= option to call the last recorded
macro. So instead of the usual =C-x e=, type =C-x e e=. And of course,
the usual repetition typing repeatedly =e= is available.

Why are directional macros useful? To create fancy lines. For
instance, if we want a doted line instead of the continuous one, we
record a macro for one step:

#+begin_example
C-x ( ;; begin recording
INS o ;; insert a small dot
<right> <right> ;; draw a line over 2 characters
C-x ) ;; stop recording
#+end_example

Then we call this macro repeatedly in any of the 4 directions:

[[file:images/macro-doted-line.png]]

#+begin_src

·─·─·─·─· ╷ ·──·
│ │ │ │
· · · ·
│ │ │ │
· ·─·─·─· ·
│ │
·─·─·─·─·─·─·

#+end_src

We can draw complex shapes by just drawing one step. Hereafter, we
call a macro in 4 directions, closing a square:

[[file:images/macro-fancy-squares.png]]

#+begin_example

╭╮╭╮╭╮╭╮╭╮╭╮ △ △ △ △ △ △ ╭─╮ ╭─╮ ╭─╮ ╭─╮ ╭─╮ ╭─╮ ╭─╮ ╭─╮
╭─╯╰╯╰╯╰╯╰╯╰╯│ ╶╯╶╯╶╯╶╯╶╯╶╯╷ ╭──╯∙╰─╯∙╰─╯∙╰─╯∙│ ▷┤□├▷┤□├▷┤□├▷┤□├▽
╰╮ ╰╮ ◁╮ ╰▷ │∙ │ ╭┴┼─╯ ╰─╯ ╰─╯ ╰─┼┴╮
╭╯ ╭╯ ╵ ╷ ╰╮ ╰╮ │□│ │□│
╰╮ ╰╮ ◁╮ ╰▷ │ ∙│ ╰┬╯ ╰┬╯
╭╯ ╭╯ ╵ ╷ ╭╯ ╭╯ △ ▽
╰╮ ╰╮ ◁╮ ╰▷ │∙ │ ╭┴╮ ╭┴╮
╭╯ ╭╯ ╵ ╷ ╰╮ ╰╮ │□│ │□│
╰╮ ╰╮ ◁╮ ╰▷ │ ∙│ ╰┬┼─╮ ╭─╮ ╭─╮ ╭─┼┬╯
│╭╮╭╮╭╮╭╮╭╮╭─╯ ╵╭╴╭╴╭╴╭╴╭╴╭╴ │∙╭─╮∙╭─╮∙╭─╮∙╭──╯ △┤□├◁┤□├◁┤□├◁┤□├◁
╰╯╰╯╰╯╰╯╰╯╰╯ ▽ ▽ ▽ ▽ ▽ ▽ ╰─╯ ╰─╯ ╰─╯ ╰─╯ ╰─╯ ╰─╯ ╰─╯ ╰─╯

#+end_example

* Which fonts?
A monospace character font must be used. It must also support UNICODE.

Expand Down
Binary file added images/macro-doted-line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/macro-fancy-squares.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions tests/bench10.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;;; uniline.el --- Draw lines, boxes, & arrows with the keyboard -*- coding:utf-8; lexical-binding: t; -*-

;; Copyright (C) 2024 Thierry Banel

;; Author: Thierry Banel tbanelwebmin at free dot fr
;; Version: 1.0
;; URL: https://github.com/tbanel/uniline

;; Uniline 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 3 of the License, or
;; (at your option) any later version.

;; Uniline 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, see <http://www.gnu.org/licenses/>.

;; a macro cannot be defined inside another macro,
;; so this macro is defined outside
(setq last-kbd-macro (kbd "<kp-subtract> <right> C-<up> C-<right> <down>"))

(uniline-bench
"<return> <down> <down> <right> <right> a a a a a a a a a a a a a a a a a a a a C-a C-k C-y C-a <down> C-y C-a <down> C-y C-a <up> <up> <up> <up> <down> <up> <right> <down> C-x e e e e <right> <right> <right> <down> <down> <down> <left> <left> <left> <left> <left> <up> <up> <up> <return>"
"\
╭╮╭╮╭╮╭╮╭╮╭╮
╶┼┴╯╰╯╰╯╰╯╰╯│
╰╴aaaaaaaaa╶╮aaaaaaa
╭aaaaaaaaaaa╯aaaaaaa
╰╴aaaaaaaaa╶╮aaaaaaa
╭╯ ╭╯
╰╮ ╰╮
│╭╮╭╮╭╮╭╮╭─╯
╰╯╰╯╰╯╰╯╰╯
")
2 changes: 1 addition & 1 deletion tests/uniline-bench.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RESULT is a string representing the expected result."
(ignore-errors (kill-buffer "*uniline-interactive*"))
(switch-to-buffer "*uniline-interactive*")
(uniline-mode 1)
(eval `(,(kmacro commands)))
(execute-kbd-macro (kbd commands))

(setq uniline-bench-result
(string-equal
Expand Down
Loading

0 comments on commit 4885403

Please sign in to comment.