* How to change Perl mode indentation to two spaces and no tabs? @ 2015-06-15 16:38 Kenneth Wolcott 2015-06-16 7:28 ` tomas [not found] ` <mailman.5082.1434439741.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 14+ messages in thread From: Kenneth Wolcott @ 2015-06-15 16:38 UTC (permalink / raw) To: help-gnu-emacs HI; I'd like to change the default indentation of the Emacs Perl mode from four spaces (and tabs?) to be two spaces and no tabs. How do I do this? I'd also like to do this for my bash (bourne?) shell scripts. I'm on MacOS (Darwin) and various flavors of Linux. Thanks, Ken Wolcott ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-15 16:38 How to change Perl mode indentation to two spaces and no tabs? Kenneth Wolcott @ 2015-06-16 7:28 ` tomas 2015-06-16 13:31 ` Kenneth Wolcott [not found] ` <mailman.5082.1434439741.904.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 14+ messages in thread From: tomas @ 2015-06-16 7:28 UTC (permalink / raw) To: Kenneth Wolcott; +Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, Jun 15, 2015 at 09:38:06AM -0700, Kenneth Wolcott wrote: > HI; > > I'd like to change the default indentation of the Emacs Perl mode > from four spaces (and tabs?) to be two spaces and no tabs. How do I > do this? As an alternative way which might be more amenable to exploration, you might want to try Emacs' "customize" interface. Just type M-x customize <ENTER> then follow the links "Programming" (you can click on the link or move point (aka "the cursor") and press <ENTER>), then "Languages", then "Perl". There you can set the values for all the settings Perl-Mode has. You can set those values just for the current session or set them permanently (in the last case Emacs writes those settings to your .emacs, so this method is compatible to what the other posters have recommended you. If you have set things "by hand" and via customize, you might want to have a look at your .emacs to consolidate things (no use in setting some variable twice, and in the long run it makes things unreadable). Customize: warmly recommended. And it's included! regards - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlV/0DAACgkQBcgs9XrR2kZM6gCfVWg61GndJZe6w5fuCmvQc5It c+sAn2vT7GonDw9bQdSOG1H2BoAvfnAt =iw2g -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-16 7:28 ` tomas @ 2015-06-16 13:31 ` Kenneth Wolcott 0 siblings, 0 replies; 14+ messages in thread From: Kenneth Wolcott @ 2015-06-16 13:31 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs On Tue, Jun 16, 2015 at 12:28 AM, <tomas@tuxteam.de> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Mon, Jun 15, 2015 at 09:38:06AM -0700, Kenneth Wolcott wrote: >> HI; >> >> I'd like to change the default indentation of the Emacs Perl mode >> from four spaces (and tabs?) to be two spaces and no tabs. How do I >> do this? > > As an alternative way which might be more amenable to exploration, you > might want to try Emacs' "customize" interface. Just type > > M-x customize <ENTER> > > then follow the links "Programming" (you can click on the link or move > point (aka "the cursor") and press <ENTER>), then "Languages", then > "Perl". There you can set the values for all the settings Perl-Mode > has. > > You can set those values just for the current session or set them > permanently (in the last case Emacs writes those settings to your > .emacs, so this method is compatible to what the other posters have > recommended you. > > If you have set things "by hand" and via customize, you might want > to have a look at your .emacs to consolidate things (no use in setting > some variable twice, and in the long run it makes things unreadable). > > Customize: warmly recommended. And it's included! > > regards > - -- tomás > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.12 (GNU/Linux) > > iEYEARECAAYFAlV/0DAACgkQBcgs9XrR2kZM6gCfVWg61GndJZe6w5fuCmvQc5It > c+sAn2vT7GonDw9bQdSOG1H2BoAvfnAt > =iw2g > -----END PGP SIGNATURE----- Thank you Tomas! ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.5082.1434439741.904.help-gnu-emacs@gnu.org>]
* Re: How to change Perl mode indentation to two spaces and no tabs? [not found] ` <mailman.5082.1434439741.904.help-gnu-emacs@gnu.org> @ 2015-06-16 21:48 ` Emanuel Berg 0 siblings, 0 replies; 14+ messages in thread From: Emanuel Berg @ 2015-06-16 21:48 UTC (permalink / raw) To: help-gnu-emacs <tomas@tuxteam.de> writes: > Customize: warmly recommended. And it's included! It is warmly recommended to know of the existence of Customize, but it doesn't suit everyone's purposes and not everyone likes it. For exploration, another way is `apropos' which I think the OP already knows of, but anyway: C-h a runs the command `apropos'... C-h A runs the command `apropos-command'... Tho to be honest I don't think either (apropos nor Customize) would have solved this problem in a smooth way. Well, it is a good thing this list/group exists. Anytime we engage in discussions, we do something we enjoy. But anytime we help people with problems like this, we do something good. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.5054.1434389545.904.help-gnu-emacs@gnu.org>]
* Re: How to change Perl mode indentation to two spaces and no tabs? [not found] <mailman.5054.1434389545.904.help-gnu-emacs@gnu.org> @ 2015-06-15 18:27 ` Emanuel Berg 2015-06-15 19:17 ` Kenneth Wolcott 0 siblings, 1 reply; 14+ messages in thread From: Emanuel Berg @ 2015-06-15 18:27 UTC (permalink / raw) To: help-gnu-emacs Kenneth Wolcott <kennethwolcott@gmail.com> writes: > I'd like to change the default indentation of the > Emacs Perl mode from four spaces (and tabs?) to be > two spaces and no tabs. How do I do this? > > I'd also like to do this for my bash (bourne?) > shell scripts. I agree tabs shouldn't be used in source - except for Makefiles, because there it won't work otherwise. Try this: (setq-default tab-width 2) (setq-default indent-tabs-mode nil) -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-15 18:27 ` Emanuel Berg @ 2015-06-15 19:17 ` Kenneth Wolcott 2015-06-15 19:47 ` John Mastro 0 siblings, 1 reply; 14+ messages in thread From: Kenneth Wolcott @ 2015-06-15 19:17 UTC (permalink / raw) To: help-gnu-emacs On Mon, Jun 15, 2015 at 11:27 AM, Emanuel Berg <embe8573@student.uu.se> wrote: > Kenneth Wolcott <kennethwolcott@gmail.com> writes: > >> I'd like to change the default indentation of the >> Emacs Perl mode from four spaces (and tabs?) to be >> two spaces and no tabs. How do I do this? >> >> I'd also like to do this for my bash (bourne?) >> shell scripts. > > I agree tabs shouldn't be used in source - except for > Makefiles, because there it won't work otherwise. > > Try this: > > (setq-default tab-width 2) > (setq-default indent-tabs-mode nil) > > -- > underground experts united > http://user.it.uu.se/~embe8573 Hi Emanuel; Thank you for your response! However, it looks like bash mode and perl mode seem to overrule these two lines when I place them in my ~/.emacs file as I see the same four space indentation when typing in new text in new files. So, either I placed these lines in the wrong file or these lines need to be within the context of the mode (or both). I like the syntax highlighting and the formatting (in general) of the perl mode, I just want multiples of two spaces for indentation rather than multiples of four. Thanks, Ken Wolcott ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-15 19:17 ` Kenneth Wolcott @ 2015-06-15 19:47 ` John Mastro 2015-06-15 19:58 ` Kenneth Wolcott [not found] ` <mailman.5060.1434398291.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 14+ messages in thread From: John Mastro @ 2015-06-15 19:47 UTC (permalink / raw) To: Kenneth Wolcott, help-gnu-emacs@gnu.org > I like the syntax highlighting and the formatting (in general) of > the perl mode, I just want multiples of two spaces for indentation > rather than multiples of four. Then it looks like you'll want something like: (defun my-init-perl-mode () (setq perl-indent-level 2 perl-continued-statement-offset 2 perl-continued-brace-offset -2)) (eval-after-load 'perl-mode '(add-hook 'perl-mode-hook #'my-init-perl-mode)) See `C-h f perl-mode RET' for more information on those, and other, options. I based the above on the "LW" style (the default) with every 4 replaced by a 2. -- john ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-15 19:47 ` John Mastro @ 2015-06-15 19:58 ` Kenneth Wolcott [not found] ` <mailman.5060.1434398291.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 14+ messages in thread From: Kenneth Wolcott @ 2015-06-15 19:58 UTC (permalink / raw) To: John Mastro; +Cc: help-gnu-emacs@gnu.org On Mon, Jun 15, 2015 at 12:47 PM, John Mastro <john.b.mastro@gmail.com> wrote: >> I like the syntax highlighting and the formatting (in general) of >> the perl mode, I just want multiples of two spaces for indentation >> rather than multiples of four. > > Then it looks like you'll want something like: > > (defun my-init-perl-mode () > (setq perl-indent-level 2 > perl-continued-statement-offset 2 > perl-continued-brace-offset -2)) > > (eval-after-load 'perl-mode > '(add-hook 'perl-mode-hook #'my-init-perl-mode)) > > See `C-h f perl-mode RET' for more information on those, and other, > options. I based the above on the "LW" style (the default) with every 4 > replaced by a 2. > > -- > john Thanks, John! I did as you suggested, looking at the built-in help for perl-mode. I'm now experimenting with these lines in my ~/.emacs file. Well, initial experiments still show that the default perl-mode still seems to override what I have in the ~/.emacs file, as the four-space indentation is still occurring. I'm still googling for this as well; haven't found the right info yet. Thanks, Ken Wolcott ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.5060.1434398291.904.help-gnu-emacs@gnu.org>]
* Re: How to change Perl mode indentation to two spaces and no tabs? [not found] ` <mailman.5060.1434398291.904.help-gnu-emacs@gnu.org> @ 2015-06-15 20:10 ` Dan Espen 2015-06-15 20:53 ` Kenneth Wolcott [not found] ` <mailman.5061.1434401625.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 14+ messages in thread From: Dan Espen @ 2015-06-15 20:10 UTC (permalink / raw) To: help-gnu-emacs Kenneth Wolcott <kennethwolcott@gmail.com> writes: R> On Mon, Jun 15, 2015 at 12:47 PM, John Mastro <john.b.mastro@gmail.com> wrote: >>> I like the syntax highlighting and the formatting (in general) of >>> the perl mode, I just want multiples of two spaces for indentation >>> rather than multiples of four. >> >> Then it looks like you'll want something like: >> >> (defun my-init-perl-mode () >> (setq perl-indent-level 2 >> perl-continued-statement-offset 2 >> perl-continued-brace-offset -2)) >> >> (eval-after-load 'perl-mode >> '(add-hook 'perl-mode-hook #'my-init-perl-mode)) >> >> See `C-h f perl-mode RET' for more information on those, and other, >> options. I based the above on the "LW" style (the default) with every 4 >> replaced by a 2. >> >> -- >> john > > Thanks, John! > > I did as you suggested, looking at the built-in help for perl-mode. > > I'm now experimenting with these lines in my ~/.emacs file. > > Well, initial experiments still show that the default perl-mode still > seems to override what I have in the ~/.emacs file, as the four-space > indentation is still occurring. > > I'm still googling for this as well; haven't found the right info yet. Make sure you are in perl-mode. You could be in cperl-mode. (Look at your mode line while editing a Perl file.) Then set either perl-indent-level or cperl-indent-level in a hook as shown above. The technique above is going to require an Emacs restart to take effect. Stilll having issues? Add a message to the defun to verify that the defun is being run: (message "defun has run") -- Dan Espen ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-15 20:10 ` Dan Espen @ 2015-06-15 20:53 ` Kenneth Wolcott [not found] ` <mailman.5061.1434401625.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 14+ messages in thread From: Kenneth Wolcott @ 2015-06-15 20:53 UTC (permalink / raw) To: help-gnu-emacs On Mon, Jun 15, 2015 at 1:10 PM, Dan Espen <despen@verizon.net> wrote: > Kenneth Wolcott <kennethwolcott@gmail.com> writes: > > R> On Mon, Jun 15, 2015 at 12:47 PM, John Mastro <john.b.mastro@gmail.com> wrote: >>>> I like the syntax highlighting and the formatting (in general) of >>>> the perl mode, I just want multiples of two spaces for indentation >>>> rather than multiples of four. >>> >>> Then it looks like you'll want something like: >>> >>> (defun my-init-perl-mode () >>> (setq perl-indent-level 2 >>> perl-continued-statement-offset 2 >>> perl-continued-brace-offset -2)) >>> >>> (eval-after-load 'perl-mode >>> '(add-hook 'perl-mode-hook #'my-init-perl-mode)) >>> >>> See `C-h f perl-mode RET' for more information on those, and other, >>> options. I based the above on the "LW" style (the default) with every 4 >>> replaced by a 2. >>> >>> -- >>> john >> >> Thanks, John! >> >> I did as you suggested, looking at the built-in help for perl-mode. >> >> I'm now experimenting with these lines in my ~/.emacs file. >> >> Well, initial experiments still show that the default perl-mode still >> seems to override what I have in the ~/.emacs file, as the four-space >> indentation is still occurring. >> >> I'm still googling for this as well; haven't found the right info yet. > > Make sure you are in perl-mode. > You could be in cperl-mode. > > (Look at your mode line while editing a Perl file.) > > Then set either perl-indent-level or cperl-indent-level in a hook as > shown above. > > The technique above is going to require an Emacs restart to take effect. > > Stilll having issues? > Add a message to the defun to verify that the defun is being run: > > (message "defun has run") > > -- > Dan Espen Hi Dan; It does says "(Perl)" on the mode line, but even with the most recent idea submitted here (I love the support!) the indentation is still by multiplies of four spaces, not two spaces. I did exit emacs and come back in. GNU Emacs 24.4.1 (x86_64-apple-darwin14.0.0) Thanks, Ken Wolcott ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.5061.1434401625.904.help-gnu-emacs@gnu.org>]
* Re: How to change Perl mode indentation to two spaces and no tabs? [not found] ` <mailman.5061.1434401625.904.help-gnu-emacs@gnu.org> @ 2015-06-15 22:51 ` Emanuel Berg 2015-06-15 23:48 ` Kenneth Wolcott [not found] ` <mailman.5067.1434412130.904.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 14+ messages in thread From: Emanuel Berg @ 2015-06-15 22:51 UTC (permalink / raw) To: help-gnu-emacs Kenneth Wolcott <kennethwolcott@gmail.com> writes: > It does says "(Perl)" on the mode line, but even > with the most recent idea submitted here (I love the > support!) the indentation is still by multiplies of > four spaces, not two spaces. I did exit emacs and > come back in. As for the tab width, my initial suggestion doesn't do what you want. As for tabs (instead of spaces), I don't get tabs, even with emacs -Q file.pl Are you sure you get tabs? Also, this works for me: (defun my-init-perl-mode () (setq perl-indent-level 2) (setq perl-continued-statement-offset 2) (setq perl-continued-brace-offset -2) ) ;; (my-init-perl-mode) ;; ^ evaluate here And I don't need to restart Emacs to get it to work! However I can think of one more thing. After evaluating (my-init-perl-mode), say that you have a piece of Perl like this: sub setup_db { print BOLD, RED, " Type ", YELLOW, "y", RED, " to reset database: ", RESET; open(my $in, "<-") or die "setup_db: cannot open stdin.\n"; If you put point on the second line and hit TAB, it will work. If you put point on the third line and hit TAB, it won't work because it will look at the line above for alignment. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-15 22:51 ` Emanuel Berg @ 2015-06-15 23:48 ` Kenneth Wolcott [not found] ` <mailman.5067.1434412130.904.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 14+ messages in thread From: Kenneth Wolcott @ 2015-06-15 23:48 UTC (permalink / raw) To: help-gnu-emacs On Mon, Jun 15, 2015 at 3:51 PM, Emanuel Berg <embe8573@student.uu.se> wrote: > Kenneth Wolcott <kennethwolcott@gmail.com> writes: > >> It does says "(Perl)" on the mode line, but even >> with the most recent idea submitted here (I love the >> support!) the indentation is still by multiplies of >> four spaces, not two spaces. I did exit emacs and >> come back in. > > As for the tab width, my initial suggestion doesn't do > what you want. > > As for tabs (instead of spaces), I don't get tabs, > even with > > emacs -Q file.pl > > Are you sure you get tabs? > > Also, this works for me: > > (defun my-init-perl-mode () > (setq perl-indent-level 2) > (setq perl-continued-statement-offset 2) > (setq perl-continued-brace-offset -2) ) > ;; (my-init-perl-mode) > ;; ^ evaluate here > > And I don't need to restart Emacs to get it to work! > > However I can think of one more thing. > After evaluating (my-init-perl-mode), say that you > have a piece of Perl like this: > > sub setup_db { > print BOLD, RED, " Type ", YELLOW, "y", RED, " to reset database: ", RESET; > open(my $in, "<-") or die "setup_db: cannot open stdin.\n"; > > If you put point on the second line and hit TAB, it > will work. If you put point on the third line and hit > TAB, it won't work because it will look at the line > above for alignment. > > -- > underground experts united > http://user.it.uu.se/~embe8573 Now this is *weird* :-) This time I edited body of the function, in ~/.emacs, using emacs, removing pieces, adding pieces (I'm not good at LISP!), just experimenting, and resulted in the original function definition. Now the two-space indentation works :-) So I'll experiment with doubly- and triply-nested conditionals and see if it works. Thanks, it seems to be working! Ken ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.5067.1434412130.904.help-gnu-emacs@gnu.org>]
* Re: How to change Perl mode indentation to two spaces and no tabs? [not found] ` <mailman.5067.1434412130.904.help-gnu-emacs@gnu.org> @ 2015-06-16 0:48 ` Emanuel Berg 2015-06-17 3:55 ` Robert Thorpe 0 siblings, 1 reply; 14+ messages in thread From: Emanuel Berg @ 2015-06-16 0:48 UTC (permalink / raw) To: help-gnu-emacs Kenneth Wolcott <kennethwolcott@gmail.com> writes: > Now this is *weird* :-) > > This time I edited body of the function, in > ~/.emacs, using emacs, removing pieces, adding > pieces (I'm not good at LISP!), just experimenting, > and resulted in the original function definition. Well, it happens. I think my rephrasing makes it more simple and less error-prone but the puzzle pieces were unknown to me until I saw Mr. Mastro's code, which by the way works instantly for me just yanking it into ~/.emacs. As a side note, I don't understand why one cannot get this by the use of a single variable value. I seems like a thing one would just store in a (1) variable and then have that configurable by the user, and propagated down the pipe. Why should it be there three times - out of which, once negated? If there is a good answer, this is a serious question, if there isn't, consider it rhetorical... > Now the two-space indentation works :-) ... Thanks, > it seems to be working! No problem, again, John Mastro is the guy who solved it. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How to change Perl mode indentation to two spaces and no tabs? 2015-06-16 0:48 ` Emanuel Berg @ 2015-06-17 3:55 ` Robert Thorpe 0 siblings, 0 replies; 14+ messages in thread From: Robert Thorpe @ 2015-06-17 3:55 UTC (permalink / raw) To: Emanuel Berg; +Cc: help-gnu-emacs Emanuel Berg <embe8573@student.uu.se> writes: > As a side note, I don't understand why one cannot get > this by the use of a single variable value. I seems > like a thing one would just store in a (1) variable > and then have that configurable by the user, and > propagated down the pipe. Why should it be there three > times - out of which, once negated? If there is a good > answer, this is a serious question, if there isn't, > consider it rhetorical... This is tricky. There are two aspects to tabs: * How a tab character is displayed. This is controlled by the variable tab-width. Usually though, the only way you can insert a tab character is with C-q TAB or C-q C-i though. By default Emacs binds TAB to a command. * What pressing tab inserts. If a mode doesn't have an indentation convention then this is defined by tab-stops-list and tab-to-tab-stop. If the mode does have an indentation convention then that takes over and it's defined by a mode specific variable. BR, Robert Thorpe ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2015-06-17 3:55 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-06-15 16:38 How to change Perl mode indentation to two spaces and no tabs? Kenneth Wolcott 2015-06-16 7:28 ` tomas 2015-06-16 13:31 ` Kenneth Wolcott [not found] ` <mailman.5082.1434439741.904.help-gnu-emacs@gnu.org> 2015-06-16 21:48 ` Emanuel Berg [not found] <mailman.5054.1434389545.904.help-gnu-emacs@gnu.org> 2015-06-15 18:27 ` Emanuel Berg 2015-06-15 19:17 ` Kenneth Wolcott 2015-06-15 19:47 ` John Mastro 2015-06-15 19:58 ` Kenneth Wolcott [not found] ` <mailman.5060.1434398291.904.help-gnu-emacs@gnu.org> 2015-06-15 20:10 ` Dan Espen 2015-06-15 20:53 ` Kenneth Wolcott [not found] ` <mailman.5061.1434401625.904.help-gnu-emacs@gnu.org> 2015-06-15 22:51 ` Emanuel Berg 2015-06-15 23:48 ` Kenneth Wolcott [not found] ` <mailman.5067.1434412130.904.help-gnu-emacs@gnu.org> 2015-06-16 0:48 ` Emanuel Berg 2015-06-17 3:55 ` Robert Thorpe
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).