[pgf-tikz] shift matrices in emacs

Henri Menke henrimenke at gmail.com
Wed Jan 15 21:57:09 CET 2020


Dear Tom,

Thanks for sharing the Emacs code.  I myself am not too familiar with
elisp, so I can't really help with improving the code.

The canonical way to redistribute plugins for Emacs is ELPA, but I'm not
sure whether your code matches the requirements.  However, you could
contact the AucTeX developers and ask whether they would want to merge
your code.

Otherwise I can also pop your code into the doc/generic/pgf/ directory,
such that it is distributed with official PGF releases, but users will
have to install it into their Emacs manually then.

Kind regards,
Henri

On 1/15/20 7:54 PM, Tom Hirschowitz wrote:
> Hi all,
> 
> When typing tikz code in emacs, I have a few macros to insert square or triangle templates 
> using node names in m-1-1, m-2-2, etc. So it is often quicker to shift entire parts of 
> matrices than to retype the whole. I did this manually for a while, but finally wrote the 
> code below which does it automatically and defines M-[direction] key bindings.
> 
> That's my first not entirely trivial elisp code, and I wasn't even able to factor out the 
> obvious, but it seems to work. Can anyone more used to elisp improve the code?
> 
> Also, apart from sending it here, is there anything I should do to share it?
> 
> Tom
> 
> 
> 
> (defun tikz-shift-downwards (beginning end)
>   "Shifts tikz matrix coordinates down by 1."
>   (interactive "*r")
>   (setq end (copy-marker end))
>   (save-match-data
>     (save-excursion
>       (goto-char beginning)
>       (while (re-search-forward "-\\([0-9]+\\)-" end t)
>         (replace-match (number-to-string (+ 1 (string-to-number (match-string 1)))) nil nil nil 1))
>       (set-marker end nil))))
> (global-set-key (kbd "M-<down>") 'tikz-shift-downwards)
> 
> (defun tikz-shift-upwards (beginning end)
>   "Shifts tikz matrix coordinates down by 1."
>   (interactive "*r")
>   (setq end (copy-marker end))
>   (save-match-data
>     (save-excursion
>       (goto-char beginning)
>       (while (re-search-forward "-\\([0-9]+\\)-" end t)
>         (replace-match (number-to-string (- (string-to-number (match-string 1)) 1)) nil nil nil 1)) 
>       (set-marker end nil))))
> (global-set-key (kbd "M-<up>") 'tikz-shift-upwards)
> 
> (defun tikz-shift-right (beginning end)
>   "Shifts tikz matrix coordinates down by 1."
>   (interactive "*r")
>   (setq end (copy-marker end))
>   (save-match-data
>     (save-excursion
>       (goto-char beginning)
>       (while (re-search-forward "-\\([0-9]+\\))" end t)
>         (replace-match (number-to-string (+ 1 (string-to-number (match-string 1)))) nil nil nil 1)) 
>       (set-marker end nil))))
> (global-set-key (kbd "M-<right>") 'tikz-shift-right)
> 
> (defun tikz-shift-left (beginning end)
>   "Shifts tikz matrix coordinates down by 1."
>   (interactive "*r")
>   (setq end (copy-marker end))
>   (save-match-data
>     (save-excursion
>       (goto-char beginning)
>       (while (re-search-forward "-\\([0-9]+\\))" end t)
>         (replace-match (number-to-string (- (string-to-number (match-string 1)) 1)) nil nil nil 1))
>       (set-marker end nil))))
> (global-set-key (kbd "M-<left>") 'tikz-shift-left)
> 


More information about the pgf-tikz mailing list.