all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs Function to add dashes to leading spaces in a Selected Region
@ 2020-10-29 23:34 Christopher Dimech
  2020-10-30  0:12 ` Stephen Berman
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christopher Dimech @ 2020-10-29 23:34 UTC (permalink / raw)
  To: Help Gnu Emacs

I need an Emacs Function to add dashes to leading spaces in a Selected Region.
Require help to do this thing.


Salut



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-29 23:34 Emacs Function to add dashes to leading spaces in a Selected Region Christopher Dimech
@ 2020-10-30  0:12 ` Stephen Berman
  2020-10-30  2:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-11-05  3:15 ` David Masterson
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Berman @ 2020-10-30  0:12 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: Help Gnu Emacs

On Fri, 30 Oct 2020 00:34:16 +0100 Christopher Dimech <dimech@gmx.com> wrote:

> I need an Emacs Function to add dashes to leading spaces in a Selected Region.
> Require help to do this thing.

(defun space-to-dash (beg end)
  "Replace spaces by dashes in region."
  (interactive "r")
  (goto-char beg)
  (while (< (point) end)
    (when (looking-at "^ +")
      (let ((rep (make-string (length (match-string 0)) ?-)))
	(replace-match rep)))
    (forward-line)))

Steve Berman



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-29 23:34 Emacs Function to add dashes to leading spaces in a Selected Region Christopher Dimech
  2020-10-30  0:12 ` Stephen Berman
@ 2020-10-30  2:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-10-30  3:17   ` Christopher Dimech
  2020-11-05  3:15 ` David Masterson
  2 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-10-30  2:36 UTC (permalink / raw)
  To: help-gnu-emacs

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.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-30  2:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-10-30  3:17   ` Christopher Dimech
  2020-10-30  8:00     ` tomas
  0 siblings, 1 reply; 8+ messages in thread
From: Christopher Dimech @ 2020-10-30  3:17 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs

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
>
>
>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-30  3:17   ` Christopher Dimech
@ 2020-10-30  8:00     ` tomas
  2020-10-30 14:28       ` Christopher Dimech
  0 siblings, 1 reply; 8+ messages in thread
From: tomas @ 2020-10-30  8:00 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

On Fri, Oct 30, 2020 at 04:17:37AM +0100, Christopher Dimech wrote:

[...]

> > Christopher Dimech wrote:
> >
> > > I need an Emacs Function to add dashes to leading spaces in
> > > a Selected Region. Require help to do this thing.

[Emanuel Berg]

> > Reading your post, "Transpose Sentences but stay at point", it would
> > be helpful if your function could also have a REVERSE option.
> 
> Good point

I think Emanuel was politely hinting at the possibility that not
everyone may find the leading dashes variant more readable.

In my personal case, I do prefer leading space (the result of
many years of doint it this way, probably).

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-30  8:00     ` tomas
@ 2020-10-30 14:28       ` Christopher Dimech
  2020-10-31 20:05         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 8+ messages in thread
From: Christopher Dimech @ 2020-10-30 14:28 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs


I agree with you. The problem is that my email client removes all
formatting when I send messages as text. Others have complained
they don't like html tags either. Time to change client.




> Sent: Friday, October 30, 2020 at 9:00 AM
> From: tomas@tuxteam.de
> To: help-gnu-emacs@gnu.org
> Subject: Re: Emacs Function to add dashes to leading spaces in a Selected Region
>
> On Fri, Oct 30, 2020 at 04:17:37AM +0100, Christopher Dimech wrote:
>
> [...]
>
> > > Christopher Dimech wrote:
> > >
> > > > I need an Emacs Function to add dashes to leading spaces in
> > > > a Selected Region. Require help to do this thing.
>
> [Emanuel Berg]
>
> > > Reading your post, "Transpose Sentences but stay at point", it would
> > > be helpful if your function could also have a REVERSE option.
> >
> > Good point
>
> I think Emanuel was politely hinting at the possibility that not
> everyone may find the leading dashes variant more readable.
>
> In my personal case, I do prefer leading space (the result of
> many years of doint it this way, probably).
>
> Cheers
>  - t
>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-30 14:28       ` Christopher Dimech
@ 2020-10-31 20:05         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-10-31 20:05 UTC (permalink / raw)
  To: help-gnu-emacs

Christopher Dimech wrote:

> I agree with you. The problem is that my email client removes all
> formatting when I send messages as text. Others have complained they
> don't like html tags either. Time to change client.

Good call. Two wrongs don't make a right.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs Function to add dashes to leading spaces in a Selected Region
  2020-10-29 23:34 Emacs Function to add dashes to leading spaces in a Selected Region Christopher Dimech
  2020-10-30  0:12 ` Stephen Berman
  2020-10-30  2:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-11-05  3:15 ` David Masterson
  2 siblings, 0 replies; 8+ messages in thread
From: David Masterson @ 2020-11-05  3:15 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: Help Gnu Emacs

Christopher Dimech <dimech@gmx.com> writes:

> I need an Emacs Function to add dashes to leading spaces in a Selected Region.
> Require help to do this thing.

Given that you are new, I would use re-search-forward.  Figure out an RE
that matches what you want, then start at the beginning of your region
and step thru til you get to the end of the region.

-- 
David Masterson



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-11-05  3:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-29 23:34 Emacs Function to add dashes to leading spaces in a Selected Region Christopher Dimech
2020-10-30  0:12 ` Stephen Berman
2020-10-30  2:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-30  3:17   ` Christopher Dimech
2020-10-30  8:00     ` tomas
2020-10-30 14:28       ` Christopher Dimech
2020-10-31 20:05         ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-11-05  3:15 ` David Masterson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.