From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: YUE Daian Newsgroups: gmane.emacs.help Subject: Re: Indenting with the tab key like everyone else Date: Mon, 01 Jul 2019 12:29:35 +0800 Message-ID: <87ef3abcnk.fsf@work.i-did-not-set--mail-host-address--so-tickle-me> References: <1019418503.3900238.1559510385829.ref@mail.yahoo.com> <1019418503.3900238.1559510385829@mail.yahoo.com> <87blzegehi.fsf@work.i-did-not-set--mail-host-address--so-tickle-me> <4deddc97-3a92-c350-01b0-75d47f1077fa@yahoo.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="31880"; mail-complaints-to="usenet@blaine.gmane.org" Cc: "help-gnu-emacs@gnu.org" To: "R. Diez" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 01 06:29:54 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hhnwv-0008Bw-FO for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Jul 2019 06:29:53 +0200 Original-Received: from localhost ([::1]:47618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhnwu-0003sR-Fu for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Jul 2019 00:29:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55785) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhnwl-0003qw-4k for help-gnu-emacs@gnu.org; Mon, 01 Jul 2019 00:29:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhnwk-00019h-01 for help-gnu-emacs@gnu.org; Mon, 01 Jul 2019 00:29:43 -0400 Original-Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:37998) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hhnwj-000192-N8 for help-gnu-emacs@gnu.org; Mon, 01 Jul 2019 00:29:41 -0400 Original-Received: by mail-pg1-x535.google.com with SMTP id z75so5365146pgz.5 for ; Sun, 30 Jun 2019 21:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=Ne/Yr/lmvW01l27M7HcYThdyIl6ieivDgshyc6TwEh8=; b=A7gV9bWhVVZFnrVdWkrmUoO+/O+ycUePqWneHjFAeQ5/iitB4Rx2V2ex/a5hcLXutM 7mQgPDgG8IKbi9gRrBoBhOm9Rv5wt9HUOeAOSmPobIGfy/lGHldD/6JWjCR1MdBwHgjV vNRAdpndOrgAcEm3SArRvrXinM05CcnukM102veuZumt4pIBwN+t+8y5rHQv0Ve+s5wo 8d577HijqEjDwQzInYiJskTxgb3W45YEwbHQ8rHBjFJs6TWyBRWBG+4mo7ShWrjM7zf2 3jpDWdlDyezUzN71NQBfXlezoIj9qOgD0y/MM9Pal6y2KbPSh7/p+8+7LlzBPuA1PdJU 6FYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Ne/Yr/lmvW01l27M7HcYThdyIl6ieivDgshyc6TwEh8=; b=qKIToyv6DG2WBGwZOsJW02x5oipTVjPvnWskcXSmFpMGrwJPSOkg349Pi5lVqJYDCY X5Mh6vcWjEO8DJGhYPRKR8L/pVwDEiPU3vO1bXYFgg+dsL8cJQbe+ZlJe7npsEMrfcFz 8qhJuyO+ie4qx3O17dFBYFt5SflsQsZSAxIwAacvhl3lr7M2rhBlgriNfYOhsqCg0Yj6 fVnWJQwIWIbWYmpYYsKtTD3+WQNCRoykLJdjig/ysyp1WvlwyOpDr8f8SXNUEO7hc8dq VCxsxpUB0Oy8CFwU34YLPGM0WFY1BBFiiRwr9rKN8hwHT/lpA5XuZZZmp9yHnhjSXmYk eC8g== X-Gm-Message-State: APjAAAWoF0ORhi7Ej5uOhhKFIHHyelKGipDWgDeK0SWHMElJWGzhr0mR D4JX3vwmG4ghohY1BF/57JA= X-Google-Smtp-Source: APXvYqxoH/guU/aSnU3xUIaR35WVG5PAAM1vNW4so3SmHH5I2zKPxRx8FS3l1da7ZNPPQ7leWHuH3A== X-Received: by 2002:a63:7358:: with SMTP id d24mr19993651pgn.224.1561955379686; Sun, 30 Jun 2019 21:29:39 -0700 (PDT) Original-Received: from localhost ([118.201.58.126]) by smtp.gmail.com with ESMTPSA id o128sm12240311pfb.42.2019.06.30.21.29.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 30 Jun 2019 21:29:38 -0700 (PDT) In-Reply-To: <4deddc97-3a92-c350-01b0-75d47f1077fa@yahoo.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::535 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:121078 Archived-At: On 2019-06-25 10:09, "R. Diez" 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 "")` and back-tab using `(kbd "S-")`. I tried your function and both selecting downwards and upwards work. Please check the real key binding by typing `C-h k ` 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.