unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* electric-layout-local-mode does not work in c-mode and java-mode
@ 2020-02-04  1:39 stardiviner
  2020-02-04  8:10 ` Robert Pluim
  2020-02-04 13:43 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: stardiviner @ 2020-02-04  1:39 UTC (permalink / raw)
  To: Emacs Help


I have following configurations:

#+begin_src emacs-lisp
(defun c-mode-electric-layout-setting ()
  "auto insert newline after specific characters."
  (setq-local electric-layout-rules '((?\; . after)))
  (add-to-list 'electric-layout-rules '( ?\{ .  after))
  (add-to-list 'electric-layout-rules '( ?\} .  before)))
(add-hook 'c-mode-hook #'electric-layout-local-mode)
(add-hook 'c-mode-hook #'c-mode-electric-layout-setting)

(defun java-mode-electric-layout-setting ()
  "auto insert newline after specific characters."
  (setq-local electric-layout-rules '((?\; . after)))
  (add-to-list 'electric-layout-rules '( ?\{ .  after))
  (add-to-list 'electric-layout-rules '( ?\} .  before)))
(add-hook 'java-mode-hook #'electric-layout-local-mode)
(add-hook 'java-mode-hook #'java-mode-electric-layout-setting)
#+end_src

Here is language code demo:

#+begin_src java
public class Hello {
    public static void main(String[] args) {
        System.log.output("hello");
    }
}
#+end_src

#+begin_src C
#include <stdio.h>

int main(int argc, char *argv[]) {
  printf("hello");
}
#+end_src

When I press ";", electric-layout-local-mode does not auto insert newline and jump to newline.

I use similar configuration works fine on js-mode and web-mode.

I also tested with minimal emacs configuration. Still does not work.

Does anyone knows what's wrong and how to fix it?

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      



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

* Re: electric-layout-local-mode does not work in c-mode and java-mode
  2020-02-04  1:39 electric-layout-local-mode does not work in c-mode and java-mode stardiviner
@ 2020-02-04  8:10 ` Robert Pluim
  2020-02-05  5:05   ` stardiviner
  2020-02-04 13:43 ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Pluim @ 2020-02-04  8:10 UTC (permalink / raw)
  To: stardiviner; +Cc: Emacs Help

>>>>> On Tue, 04 Feb 2020 09:39:01 +0800, stardiviner <numbchild@gmail.com> said:
    stardiviner> When I press ";", electric-layout-local-mode does not auto insert newline and jump to newline.

    stardiviner> I use similar configuration works fine on js-mode and web-mode.

    stardiviner> I also tested with minimal emacs configuration. Still does not work.

    stardiviner> Does anyone knows what's wrong and how to fix it?

I donʼt use electric-layout-local-mode, I use this instead:

    c-toggle-auto-newline is an interactive compiled Lisp function in
    `cc-cmds.el'.

    (c-toggle-auto-newline &optional ARG)

      Probably introduced at or before Emacs version 22.1.

    Toggle auto-newline feature.
    Optional numeric ARG, if supplied, turns on auto-newline when
    positive, turns it off when negative, and just toggles it when zero or
    left out.

    Turning on auto-newline automatically enables electric indentation.

    When the auto-newline feature is enabled (indicated by "/la" on the
    mode line after the mode name) newlines are automatically inserted
    after special characters such as brace, comma, semi-colon, and colon.

Robert



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

* Re: electric-layout-local-mode does not work in c-mode and java-mode
  2020-02-04  1:39 electric-layout-local-mode does not work in c-mode and java-mode stardiviner
  2020-02-04  8:10 ` Robert Pluim
@ 2020-02-04 13:43 ` Stefan Monnier
  2020-02-05  7:38   ` [SOLVED] " stardiviner
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2020-02-04 13:43 UTC (permalink / raw)
  To: help-gnu-emacs

> When I press ";", electric-layout-local-mode does not auto insert newline and jump to newline.

CC-mode does things in its own way.  You should be able to get it to
work by disabling CC-mode's ad-hoc solution:

    (define-key c-mode-base-map ";" nil)


-- Stefan




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

* Re: electric-layout-local-mode does not work in c-mode and java-mode
  2020-02-04  8:10 ` Robert Pluim
@ 2020-02-05  5:05   ` stardiviner
  0 siblings, 0 replies; 5+ messages in thread
From: stardiviner @ 2020-02-05  5:05 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Emacs Help


This is interesting, thanks, Robert. I will try it. :)

Robert Pluim <rpluim@gmail.com> writes:

>>>>>> On Tue, 04 Feb 2020 09:39:01 +0800, stardiviner <numbchild@gmail.com> said:
>     stardiviner> When I press ";", electric-layout-local-mode does not auto insert newline and jump to newline.
>
>     stardiviner> I use similar configuration works fine on js-mode and web-mode.
>
>     stardiviner> I also tested with minimal emacs configuration. Still does not work.
>
>     stardiviner> Does anyone knows what's wrong and how to fix it?
>
> I donʼt use electric-layout-local-mode, I use this instead:
>
>     c-toggle-auto-newline is an interactive compiled Lisp function in
>     `cc-cmds.el'.
>
>     (c-toggle-auto-newline &optional ARG)
>
>       Probably introduced at or before Emacs version 22.1.
>
>     Toggle auto-newline feature.
>     Optional numeric ARG, if supplied, turns on auto-newline when
>     positive, turns it off when negative, and just toggles it when zero or
>     left out.
>
>     Turning on auto-newline automatically enables electric indentation.
>
>     When the auto-newline feature is enabled (indicated by "/la" on the
>     mode line after the mode name) newlines are automatically inserted
>     after special characters such as brace, comma, semi-colon, and colon.
>
> Robert


-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      



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

* [SOLVED] Re: electric-layout-local-mode does not work in c-mode and java-mode
  2020-02-04 13:43 ` Stefan Monnier
@ 2020-02-05  7:38   ` stardiviner
  0 siblings, 0 replies; 5+ messages in thread
From: stardiviner @ 2020-02-05  7:38 UTC (permalink / raw)
  To: help-gnu-emacs


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> When I press ";", electric-layout-local-mode does not auto insert newline and jump to newline.
>
> CC-mode does things in its own way.  You should be able to get it to
> work by disabling CC-mode's ad-hoc solution:
>
>     (define-key c-mode-base-map ";" nil)
>
>
> -- Stefan

You're right, thanks Stefan. :)

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      



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

end of thread, other threads:[~2020-02-05  7:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-04  1:39 electric-layout-local-mode does not work in c-mode and java-mode stardiviner
2020-02-04  8:10 ` Robert Pluim
2020-02-05  5:05   ` stardiviner
2020-02-04 13:43 ` Stefan Monnier
2020-02-05  7:38   ` [SOLVED] " stardiviner

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