* bug#14593: 24.3; java-mode indentation of try-with-resources statement
@ 2013-06-11 22:24 Patrick Brinich-Langlois
2013-07-13 19:19 ` Alan Mackenzie
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Brinich-Langlois @ 2013-06-11 22:24 UTC (permalink / raw)
To: 14593
[-- Attachment #1: Type: text/plain, Size: 9838 bytes --]
Java's try-with-resources statement (new in version 1.7) is indented
incorrectly in java-mode. Steps to reproduce:
* Create a new file. Enable java-mode and electric-indent-mode.
* Type the following:
public class Test {
public static void main(String[] args) {
Path dir = Paths.get(System.getProperty("user.home"));
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
System.out.println("test");
}
}
}
The two lines after the try statement are indented an additional four
spaces. The final two closing braces are indented properly. Somebody
else has the same problem:
http://stackoverflow.com/questions/16554232/why-does-try-with-resources-break-indentation-in-emacs
I submitted this bug report a couple of weeks ago, but I didn't receive
a reply, so I'm trying again. I hope I'm not creating a duplicate.
If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
`bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
/usr/share/emacs/24.3/etc/DEBUG.
In GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.6.4)
of 2013-04-14 on marid, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11303000
System Description: Ubuntu 13.04
Configured using:
`configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
'--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
'--localstatedir=/var/lib' '--infodir=/usr/share/info'
'--mandir=/usr/share/man' '--with-pop=yes'
'--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3/site-lisp:/usr/share/emacs/site-lisp'
'--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
'--with-x-toolkit=gtk3' '--with-toolkit-scroll-bars'
'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'
'CPPFLAGS=-D_FORTIFY_SOURCE=2''
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
default enable-multibyte-characters: t
Major mode: Emacs-Lisp
Minor modes in effect:
paredit-mode: t
my-keys-minor-mode: t
recentf-mode: t
show-paren-mode: t
global-auto-revert-mode: t
iswitchb-mode: t
ido-everywhere: t
global-linum-mode: t
linum-mode: t
global-auto-complete-mode: t
auto-complete-mode: t
highlight-sexps-mode: t
electric-indent-mode: t
global-edit-server-edit-mode: t
workgroups-mode: t
desktop-save-mode: t
global-surround-mode: t
surround-mode: t
volatile-highlights-mode: t
yas-global-mode: t
yas-minor-mode: t
evil-leader-mode: t
global-evil-leader-mode: t
evil-mode: t
evil-local-mode: t
global-undo-tree-mode: t
tooltip-mode: t
mouse-wheel-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
global-visual-line-mode: t
visual-line-mode: t
transient-mark-mode: t
Recent input:
b u t SPC I SPC d i d n ' t SPC r e c e i v e SPC a
SPC r e p l y , SPC s o SPC I ' m SPC t r y i n SPC
<backspace> g SPC a SPC g <backspace> <backspace> g
a i n e n . t z M-z M-z M-z M-Y . e n J u u , s u u
u u u u u u u u u u u u u u u u u u u u u u u u u u
u u u u y y y y y y w r < M-z n e w r M-k M-a e m a
i l <M-backspace> a d d r e s s C-g M-a m a i l - h
o s t <M-backspace> t o <return> u <f1> f <escape>
C-g e C-g m a i e e <f1> f m a i l - t o <return> M-r
q M-a <return> e e M-a m a i l - f o <backspace> r
o <backspace> r <backspace> o m <M-backspace> C-g <f1>
v m a i l - h <tab> o s t - a d <tab> <return> C-x
r j e G <backspace> <backspace> o ( t e <backspace>
<backspace> s t e <backspace> <backspace> e t q SPC
m a i l - h o s t <return> SPC " p b r i n i c h l
a n g l o i r <backspace> s @ g m a i l . c o m M-Y
C-x C-e s t <return> e e u u e e u u e a ] ] ] ] ]
c , w M-a M-i <return>
Recent messages:
Type "q" in help window to restore its previous buffer.
~/.emacs and /home/pat/.emacs.d/.emacs are the same file
Executing: ~/apps/eclipse/eclim -command project_list [2 times]
Mark set
[yas] Cyclic parenthood: mode text-mode has already seen as a parent of
mode emacs-lisp-mode
Auto-saving...done
"pbrinichlanglois@gmail.com"
Executing: ~/apps/eclipse/eclim -command project_list
user-error: Beginning of history; no preceding item [2 times]
user-error: End of history; no default available [15 times]
Load-path shadows:
/home/pat/.emacs.d/elpa/company-20130604.316/.dir-locals hides
/home/pat/.emacs.d/elpa/magit-20130604.1754/.dir-locals
/home/pat/.emacs.d/elpa/color-theme-solarized-20130307.1350/solarized-dark-theme
hides
/home/pat/.emacs.d/elpa/solarized-theme-20130531.2020/solarized-dark-theme
/home/pat/.emacs.d/elpa/color-theme-solarized-20130307.1350/solarized-light-theme
hides
/home/pat/.emacs.d/elpa/solarized-theme-20130531.2020/solarized-light-theme
/home/pat/.emacs.d/elpa/pylint-20121112.1335/pylint hides
/usr/share/emacs24/site-lisp/pylint/pylint
/home/pat/.emacs.d/elpa/ipython-2927/ipython hides
/usr/share/emacs/site-lisp/ipython
/usr/share/emacs/24.3/site-lisp/debian-startup hides
/usr/share/emacs/site-lisp/debian-startup
/usr/share/emacs24/site-lisp/dictionaries-common/ispell hides
/usr/share/emacs/24.3/lisp/textmodes/ispell
/usr/share/emacs24/site-lisp/dictionaries-common/flyspell hides
/usr/share/emacs/24.3/lisp/textmodes/flyspell
/home/pat/.emacs.d/elpa/company-20130604.316/.dir-locals hides
/usr/share/emacs/24.3/lisp/gnus/.dir-locals
Features:
(find-func shadow sort mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils
cc-langs cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs executable two-column misearch multi-isearch
ffap url-parse auth-source gnus-util mm-util mail-prsvr password-cache
url-vars smex server vc-git paredit dropdown-list helm-config
helm-aliases recentf tree-widget wid-edit solarized-light-theme
solarized-definitions paren ruby-end autorevert iswitchb ido linum
dired+ dired-x dired-aux dired edit-server-htmlize html2text
ac-emacs-eclim-source eclim-completion auto-complete-config
auto-complete popup time-date help-at-pt eclimd eclim eclim-problems
eclim-maven eclim-ant eclim-java json eclim-project highlight-sexps
multi-term term disp-table ehelp electric edit-server workgroups desktop
surround cl-macs gv buffer-stack smooth-scrolling etags
volatile-highlights key-chord smarter-compile yasnippet help-mode
evil-leader evil evil-integration evil-maps evil-commands evil-types
evil-search evil-ex evil-macros evil-repeat evil-states evil-core
evil-common undo-tree diff windmove rect evil-digraphs evil-vars slime
easy-mmode pp hyperspec thingatpt browse-url cl pallet carton melpa
fill-column-indicator ac-dabbrev-autoloads ace-jump-mode-autoloads
ack-and-a-half-autoloads browse-kill-ring-autoloads
buffer-move-autoloads color-theme-solarized-autoloads
color-theme-autoloads company-autoloads diff-hl-autoloads
dired+-autoloads dropdown-list-autoloads edit-server-htmlize-autoloads
edit-server-autoloads emacs-eclim-autoloads evil-leader-autoloads
evil-autoloads expand-region-autoloads feature-mode-autoloads
fill-column-indicator-autoloads find-file-in-project-autoloads
fold-this-autoloads geiser-autoloads gist-autoloads gh-autoloads eieio
goto-chg-autoloads haml-mode-autoloads helm-autoloads htmlize-autoloads
idle-highlight-mode-autoloads ido-ubiquitous-autoloads ipython-autoloads
jedi-autoloads auto-complete-autoloads epc-autoloads ctable-autoloads
concurrent-autoloads deferred-autoloads key-chord-autoloads
logito-autoloads magit-autoloads info easymenu markdown-mode-autoloads
maxframe-autoloads melpa-autoloads byte-opt warnings bytecomp
byte-compile cconv multi-term-autoloads noctilux-theme-autoloads
pallet-autoloads carton-autoloads paredit-autoloads pcache-autoloads
pep8-autoloads popup-autoloads projectile-autoloads dash-autoloads
pylint-autoloads python-mode-autoloads quack-autoloads
rainbow-delimiters-autoloads rainbow-mode-autoloads revive-autoloads
rinari-autoloads jump-autoloads inflections-autoloads findr-autoloads
finder-inf ruby-block-autoloads ruby-compilation-autoloads edmacro
kmacro inf-ruby-autoloads inf-ruby ruby-mode ruby-end-autoloads
ruby-tools-autoloads s-autoloads scss-mode-autoloads slime-autoloads
smarter-compile-autoloads smex-autoloads sml-mode-autoloads
smooth-scrolling-autoloads advice help-fns cl-lib advice-preload
solarized-theme-autoloads surround-autoloads thesaurus-autoloads
tidy-autoloads unbound-autoloads undo-tree-autoloads
volatile-highlights-autoloads websocket-autoloads workgroups-autoloads
yari-autoloads yasnippet-autoloads package compile comint ansi-color
ring tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer loaddefs button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)
[-- Attachment #2: Type: text/html, Size: 11457 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#14593: 24.3; java-mode indentation of try-with-resources statement
2013-06-11 22:24 bug#14593: 24.3; java-mode indentation of try-with-resources statement Patrick Brinich-Langlois
@ 2013-07-13 19:19 ` Alan Mackenzie
2016-08-22 3:39 ` Alex
0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2013-07-13 19:19 UTC (permalink / raw)
To: 14593; +Cc: Patrick Brinich-Langlois
Hello, Patrick.
On Wed, 12 Jun 2013 00:24:13, Patrick Brinich-Langlois
<pbrinichlanglois@gmail.com> wrote:
> Java's try-with-resources statement (new in version 1.7) is indented
> incorrectly in java-mode. Steps to reproduce:
> * Create a new file. Enable java-mode and electric-indent-mode.
> * Type the following:
> public class Test {
> public static void main(String[] args) {
> Path dir = Paths.get(System.getProperty("user.home"));
> try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
> System.out.println("test");
> }
> }
> }
> The two lines after the try statement are indented an additional four
> spaces. The final two closing braces are indented properly.
This is indeed the case.
The following patch should hopefully handle this case properly. After
applying it, either recompile all the cc-*.el files, or just recompile
cc-langs.el, cc-engine.el, cc-fonts.el, and cc-mode.el.
Please confirm to me that the patch does indeed fix the bug, or report
any further problems which aren't fixed. Thanks!
diff -r a86a481f7a63 cc-engine.el
--- a/cc-engine.el Mon May 27 12:17:11 2013 +0000
+++ b/cc-engine.el Sun Jul 07 14:15:36 2013 +0000
@@ -1140,9 +1140,13 @@
(not (memq sym '(boundary ignore nil))))
;; Need to investigate closer whether we've crossed
;; between a substatement and its containing statement.
- (if (setq saved (if (looking-at c-block-stmt-1-key)
- ptok
- pptok))
+ (if (setq saved
+ (cond ((and (looking-at c-block-stmt-1-2-key)
+ (eq (char-after ptok) ?\())
+ pptok)
+ ((looking-at c-block-stmt-1-key)
+ ptok)
+ (t pptok)))
(cond ((> start saved) (setq pos saved))
((= start saved) (setq ret 'up)))))
@@ -8026,7 +8030,8 @@
(or (looking-at c-block-stmt-1-key)
(and (eq (char-after) ?\()
(zerop (c-backward-token-2 1 t lim))
- (looking-at c-block-stmt-2-key)))
+ (or (looking-at c-block-stmt-2-key)
+ (looking-at c-block-stmt-1-2-key))))
(point))))
(defun c-after-special-operator-id (&optional lim)
diff -r a86a481f7a63 cc-fonts.el
--- a/cc-fonts.el Mon May 27 12:17:11 2013 +0000
+++ b/cc-fonts.el Sun Jul 07 14:15:36 2013 +0000
@@ -1274,7 +1274,8 @@
(goto-char match-pos)
(backward-char)
(c-backward-token-2)
- (looking-at c-block-stmt-2-key)))
+ (or (looking-at c-block-stmt-2-key)
+ (looking-at c-block-stmt-1-2-key))))
(setq context nil
c-restricted-<>-arglists t))
;; Near BOB.
diff -r a86a481f7a63 cc-langs.el
--- a/cc-langs.el Mon May 27 12:17:11 2013 +0000
+++ b/cc-langs.el Sun Jul 07 14:15:36 2013 +0000
@@ -2181,6 +2181,18 @@
t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
(c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
+(c-lang-defconst c-block-stmt-1-2-kwds
+ "Statement keywords optionally followed by a paren sexp.
+Keywords here should also be in `c-block-stmt-1-key'."
+ t nil
+ java '("try"))
+
+(c-lang-defconst c-block-stmt-1-2-key
+ ;; Regexp matching the start of a statement which may be followed by a
+ ;; paren sexp and will then be followed by a substatement.
+ t (c-make-keywords-re t (c-lang-const c-block-stmt-1-2-kwds)))
+(c-lang-defvar c-block-stmt-1-2-key (c-lang-const c-block-stmt-1-2-key))
+
(c-lang-defconst c-block-stmt-2-kwds
"Statement keywords followed by a paren sexp and then by a substatement."
t '("for" "if" "switch" "while")
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#14593: 24.3; java-mode indentation of try-with-resources statement
2013-07-13 19:19 ` Alan Mackenzie
@ 2016-08-22 3:39 ` Alex
0 siblings, 0 replies; 3+ messages in thread
From: Alex @ 2016-08-22 3:39 UTC (permalink / raw)
To: Alan Mackenzie; +Cc: 14593-done, Patrick Brinich-Langlois
Alan Mackenzie <acm@muc.de> writes:
> Hello, Patrick.
>
> On Wed, 12 Jun 2013 00:24:13, Patrick Brinich-Langlois
> <pbrinichlanglois@gmail.com> wrote:
>
>> Java's try-with-resources statement (new in version 1.7) is indented
>> incorrectly in java-mode. Steps to reproduce:
>
>> * Create a new file. Enable java-mode and electric-indent-mode.
>> * Type the following:
>
>> public class Test {
>> public static void main(String[] args) {
>> Path dir = Paths.get(System.getProperty("user.home"));
>> try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
>> System.out.println("test");
>> }
>> }
>> }
>
>> The two lines after the try statement are indented an additional four
>> spaces. The final two closing braces are indented properly.
>
> This is indeed the case.
>
> The following patch should hopefully handle this case properly. After
> applying it, either recompile all the cc-*.el files, or just recompile
> cc-langs.el, cc-engine.el, cc-fonts.el, and cc-mode.el.
>
> Please confirm to me that the patch does indeed fix the bug, or report
> any further problems which aren't fixed. Thanks!
I'm closing this as the patch was applied in
5ab78d3d6a7efcb49d2a9be5b4bdb8eaf78f7a14 and it appears to fix the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-22 3:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-11 22:24 bug#14593: 24.3; java-mode indentation of try-with-resources statement Patrick Brinich-Langlois
2013-07-13 19:19 ` Alan Mackenzie
2016-08-22 3:39 ` Alex
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).