[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs Function to add dashes to leading spaces in a Selected Region
From: |
Christopher Dimech |
Subject: |
Re: Emacs Function to add dashes to leading spaces in a Selected Region |
Date: |
Fri, 30 Oct 2020 04:17:37 +0100 |
I figured that I can use exactly the same function for transposing words,
to transpose sentences.
But currently I am just copying the code and replacing
(transpose-words arg)
with
(transpose-sentences arg)
I need assistance so that I could have just one function that can do both
things.
(defun transpose-words--impl (arg)
---(let ((Wrd-Bounds (bounds-of-thing-at-point 'word)))
------;; ----------------------------------------------------------------
------(when Wrd-Bounds
---------(let*
------------( (Beg (point))
--------------(End (cdr Wrd-Bounds))
--------------(Shift (- Beg End))
--------------;; --------------------------------------------------------
--------------(Cursor-Psn
-----------------(save-excursion
--------------------(goto-char End) ; [#A]
--------------------(if
-----------------------;;
-----------------------(condition-case err
--------------------------(progn ; No error
----------------------------(transpose-words arg)
----------------------------t
--------------------------)
--------------------------(message err)
-----------------------)
-----------------------;;
-----------------------(+ (point) Shift)
-----------------------;;
-----------------------nil
--------------------)
-----------------)
--------------)
--------------;; --------------------------------------------------------
------------)
------------(when Cursor-Psn
---------------(goto-char Cursor-Psn)
------------)
---------)
------)
------;;-----------------------------------------------------------------
---) ; let bounds (start and end locations of word)
)
(defun transpose-wrd-forward ()
(interactive)
(transpose-words--impl 1)
)
(defun transpose-wrd-backward ()
(interactive)
(transpose-words--impl -1)
)
(global-set-key (kbd "M-H-<right>") #'transpose-stc-forward)
(global-set-key (kbd "M-H-<left>") #'transpose-stc-backward)
> Sent: Friday, October 30, 2020 at 3:36 AM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor"
> <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Emacs Function to add dashes to leading spaces in a Selected
> Region
>
> Christopher Dimech wrote:
>
> > I need an Emacs Function to add dashes to leading spaces in
> > a Selected Region. Require help to do this thing.
>
> Reading your post, "Transpose Sentences but stay at point", it would
> be helpful if your function could also have a REVERSE option.
Good point
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>