Вопрос

I am new to EmacsLisp. I have been using emacs for the last 18 months, but never made any customizations of my own. In order to learn to do that however, I am trying to solve the following problem:
Given a line of characters that form an equation of the form
(some characters A)=(some characters B),
I want to swap the two expressions A and B.

I identified the function that seems to be tailor-made for this- transpose-regions start1 end1 start2 end2 &optional leave-markers.
I have the following questions-

  1. How do I specify start1 end1 with a regular expression? It seems that positions are counted from the beginning of the buffer!
  2. What if I want to solve a more generalized problem where I keep the cursor/marker over the central = and want to do the swap? How do I specify the start end values there?

This is a learning exercise for me. Please do not post complete solutions. I will put that in as an edit for people who end up here looking for a solution. Any advice regarding coding style in emacs lisp would be appreciated!

Это было полезно?

Решение

Since you don't want a complete solution, I'll just give you a list of functions that achieve it: transpose-regions, point, line-beginning-position, line-end-position.

That is all you need assuming that you've navigated to = by hand. move-beginning-of-line and re-search-forward if you want to navigate to = in code.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top