help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bounds-of-thing-at-point for paragraphs


From: Jean Louis
Subject: Re: bounds-of-thing-at-point for paragraphs
Date: Sun, 1 Nov 2020 21:22:26 +0300
User-agent: Mutt/+ (1036f0e) (2020-10-18)

* Christopher Dimech <dimech@gmx.com> [2020-11-01 19:09]:
> Been trying to write a function to transpose two paragraphs but keep the 
> cursor
> at the same position.  How is it that bounds-of-thing-at-point does not take
> paragraph as argument?

That is very nice.

I like ivy-mode from GNU ELPA, it is package for automatic completion
of many functions. There are many various completion packages.

It may help you faster explore which functions are available.

I was looking if such function already exists by doing {C-h f} and
then I get list of functions, I have tried typing "trans" and "para"
and I can find function `transpose-paragraphs'

You may spare your efforts by finding some probably already existing
functions.

If you wish to make your own function out of `transpose-paragraphs'
you may come with cursor on the function name, above here ^ and type
{C-h f} then you press TAB and enter into file `paragraphs.el' where
you can find how function is written.

Then you may copy the same function and name it
`my-transpose-paragraphs' and try modifying it as you wish. You could
as well modify original function to do what you wish and save it in
your configuration.

See below:

> (defun Skip-Over-Paragraphs (arg)

I understand that some programming languages have mixture of upper
case and lower case function names, in Lisp that is not so common. I
believe it is common in some versions of Lisp, not in Emacs
lisp.

As:

(setq A 1)
(setq a 2)

are not same so, so it is better writing all lower case letters.

>    (let ((Prg-Bounds (bounds-of-thing-at-point 'paragraph)))
> 
>       ;; ----------------------------------------------------------------
>       (when Wrd-Bounds
>          (let*
>             ( (Beg (point))
>               (End (cdr Prg-Bounds))
>               (Shift (- Beg End))

I understand you may need now for visibility or orientation some space
at ( (Beg)) yet by convention there is no such space. You better not
make new lines after let* to make it easier readable for people who
are familiar to different style. Lisp is great, you may write it
anyhow, but for readability there are some conventions.

You may mark the function and simply press TAB and it will indent it
for you.

Please see the Emacs Lisp manual as it is built into Emacs. There is
section "Tips" where you can read various conventions.

>               ;; --------------------------------------------------------
>               (Cursor-Psn
>                  (save-excursion
>                     (goto-char End)  ; [#A]
>                     (if (condition-case err
>                            (progn    ; bodyform
>                               (transpose-paragraphs arg) ; [#B]
>                               t
>                            )

Normally ending parenthesis you put straight after t.

I suggest you use Options -> Highlight matching parenthesis to help
you see where you are.

-- 
There are 50 messages yet in my incoming mailbox.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]