unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: YUE Daian <sheepduke@gmail.com>
To: "R. Diez" <rdiezmail-emacs@yahoo.de>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Indenting with the tab key like everyone else
Date: Mon, 01 Jul 2019 12:29:35 +0800	[thread overview]
Message-ID: <87ef3abcnk.fsf@work.i-did-not-set--mail-host-address--so-tickle-me> (raw)
In-Reply-To: <4deddc97-3a92-c350-01b0-75d47f1077fa@yahoo.de>

On 2019-06-25 10:09, "R. Diez" <rdiezmail-emacs@yahoo.de> wrote:
> Hallo Danny:
>
> Thanks for your help. I got a little further, see the code I came up with below (I used some code I found on the Internet too).
>
> There is a little issue I have not been able to fix yet. Say I place the cursor at the beginning of a line, and select a few lines by 
> keeping the "shift" key pressed and hitting the down arrow key a few times. I call this selecting lines "downwards". Then indenting by 
> hitting the tab key multiple times works fine.
>
> However, if I select/mark the lines "upwards" (by using the up arrow key), then 'my-indent-rigidly' loses the selection after indenting the 
> first time.
>
> I am confused with the terms 'region', 'mark' and 'transient mark', and my Lisp skills are not very good either. Have you got any ideas on 
> how to fix that?
>
>
> The Lisp code is here:
>
> ; This routine keeps the region/mark/transient mark (?) when doing an indent-rigidly.
> (defun my-indent-rigidly (amount) ""
>    (save-excursion
>      (let ((deactivate-mark nil)
>            (beg (region-beginning)))
>        (move-beginning-of-line nil)
>        (indent-rigidly beg (region-end) amount)
>        (push-mark beg t t))))
>
>
> ; Shift-Tab to decrease the indentation.
> ; As an alternative, block-select the columns of spaces you want to delete, and press the Del key.
> (defun unindent-rigidly nil ""
>    (interactive)
>    (my-indent-rigidly -1)
> )
>
> (global-set-key [S-tab] 'unindent-rigidly)
> ; Sometimes "S-tab" does not work, use [backtab] instead:
> (global-set-key [backtab] 'unindent-rigidly)
>
>
> ; The Tab key has 2 functions:
> ; - If some text is selected, ridigly increases indentation.
> ; - Otherwise, intelligently indent the current line.
> (defun my-tab-indent nil ""
>    (interactive)
>    (if (use-region-p)
>      (my-indent-rigidly 1)
>      (indent-for-tab-command)))
>
> (global-set-key (kbd "TAB") 'my-tab-indent)
>
>
> Best regards,
>    rdiez

Sorry for the late reply.

I am not sure what you really want to do exactly. There are some tips I
thought of based on the code:

- If you look at the document of the function `push-mark`, you may
  notice that "Novice Emacs Lisp programmers often try to use the mark
  for the wrong purposes". I am not sure if this is the case but I
  presume that the weird behavior relates to it.

- Key binding Tab can be obtained by calling `(kbd "<tab>")` and
  back-tab using `(kbd "S-<tab>")`. I tried your function and both
  selecting downwards and upwards work. Please check the real key
  binding by typing `C-h k <tab>` and see if your function got
  called. The global key binding can be overrode by mode-map.

- If you want to edit multiple lines, you may consider using the
  multi-cursors package.

- It is very unusual to use `nil` instead of `()` for argument
  list. Also document string usually remains below the header line of a
  function.

Please describe what you want to achieve exactly so that more specific
help could be given.

Cheers.



  reply	other threads:[~2019-07-01  4:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1019418503.3900238.1559510385829.ref@mail.yahoo.com>
2019-06-02 21:19 ` Indenting with the tab key like everyone else R. Diez via help-gnu-emacs
2019-06-04  1:19   ` Emanuel Berg via help-gnu-emacs
2019-06-04  4:29   ` YUE Daian
2019-06-25  8:09     ` R. Diez via help-gnu-emacs
2019-07-01  4:29       ` YUE Daian [this message]
2019-07-16  7:23         ` R. Diez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ef3abcnk.fsf@work.i-did-not-set--mail-host-address--so-tickle-me \
    --to=sheepduke@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rdiezmail-emacs@yahoo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).