diff mbox

[PATCHv2] gdbserver: Add .dir-locals.el file

Message ID 20200302123123.13921-1-andrew.burgess@embecosm.com
State New
Headers show

Commit Message

Andrew Burgess March 2, 2020, 12:31 p.m. UTC
Baris,

Good spot on the *.h files, I hadn't considered them.  I did look
breifly at how I might change the mode only for *.h files, but
couldn't see anything obvious, and as we don't currently have any *.c
files I just restored the c-mode to c++-mode setting.

Thanks,
Andrew


---

Copy the .dir-locls.el file from gdb/ to gdbserver/ so that we get the
GNU style when editing these files in Emacs.

I initially wanted to remove the (c-mode . ((mode . c++))) that
switches c-mode files into c++-mode as we store C++ code in *.cc files
in the gdbserver/ directory, unlike gdb/ where we use *.c, however, I
was forgetting about the header files - we still use *.h for our C++
header files, so for now I left the settings in place to open all C
files in c++-mode.

The copyright date in the new file is left as for gdb/.dir-locals.el,
as the new file is a copy of the old with just one new comment
added, this is inline with this rule:

  https://sourceware.org/gdb/wiki/ContributionChecklist#Copyright_Header

gdbserver/ChangeLog:

	* .dir-locals.el: New file.
---
 gdbserver/.dir-locals.el | 39 +++++++++++++++++++++++++++++++++++++++
 gdbserver/ChangeLog      |  4 ++++
 2 files changed, 43 insertions(+)
 create mode 100644 gdbserver/.dir-locals.el

Comments

Pedro Alves March 2, 2020, 2:06 p.m. UTC | #1
On 3/2/20 12:31 PM, Andrew Burgess wrote:
> Baris,
> 
> Good spot on the *.h files, I hadn't considered them.  I did look
> breifly at how I might change the mode only for *.h files, but
> couldn't see anything obvious, and as we don't currently have any *.c
> files I just restored the c-mode to c++-mode setting.
> 
> Thanks,
> Andrew
> 
> 
> ---
> 
> Copy the .dir-locls.el file from gdb/ to gdbserver/ so that we get the
> GNU style when editing these files in Emacs.

I think we want this in gdbsupport/ as well?

Since this is now just a plain copy with no modifications, can't we
source the original file instead of copying it?

Thanks,
Pedro Alves
Andrew Burgess March 2, 2020, 5:08 p.m. UTC | #2
* Pedro Alves <palves@redhat.com> [2020-03-02 14:06:46 +0000]:

> On 3/2/20 12:31 PM, Andrew Burgess wrote:
> > Baris,
> > 
> > Good spot on the *.h files, I hadn't considered them.  I did look
> > breifly at how I might change the mode only for *.h files, but
> > couldn't see anything obvious, and as we don't currently have any *.c
> > files I just restored the c-mode to c++-mode setting.
> > 
> > Thanks,
> > Andrew
> > 
> > 
> > ---
> > 
> > Copy the .dir-locls.el file from gdb/ to gdbserver/ so that we get the
> > GNU style when editing these files in Emacs.
> 
> I think we want this in gdbsupport/ as well?
> 
> Since this is now just a plain copy with no modifications, can't we
> source the original file instead of copying it?

I'm not aware of a way to import one .dir-locals from another, I did
some searching and couldn't find anything promising.

Given that would you accept 3 copies of the file?

Thanks,
Andrew
Pedro Alves March 2, 2020, 5:34 p.m. UTC | #3
On 3/2/20 5:08 PM, Andrew Burgess wrote:
> * Pedro Alves <palves@redhat.com> [2020-03-02 14:06:46 +0000]:
> 
>> On 3/2/20 12:31 PM, Andrew Burgess wrote:
>>> Baris,
>>>
>>> Good spot on the *.h files, I hadn't considered them.  I did look
>>> breifly at how I might change the mode only for *.h files, but
>>> couldn't see anything obvious, and as we don't currently have any *.c
>>> files I just restored the c-mode to c++-mode setting.
>>>
>>> Thanks,
>>> Andrew
>>>
>>>
>>> ---
>>>
>>> Copy the .dir-locls.el file from gdb/ to gdbserver/ so that we get the
>>> GNU style when editing these files in Emacs.
>>
>> I think we want this in gdbsupport/ as well?
>>
>> Since this is now just a plain copy with no modifications, can't we
>> source the original file instead of copying it?
> 
> I'm not aware of a way to import one .dir-locals from another, I did
> some searching and couldn't find anything promising.
> 

Let's ask an Emacs maintainer.

Eli, what's the best way to handle this?

> Given that would you accept 3 copies of the file?

Thanks,
Pedro Alves
Eli Zaretskii March 2, 2020, 5:58 p.m. UTC | #4
> Cc: gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 2 Mar 2020 17:34:20 +0000
> 
> > I'm not aware of a way to import one .dir-locals from another, I did
> > some searching and couldn't find anything promising.
> > 
> 
> Let's ask an Emacs maintainer.
> 
> Eli, what's the best way to handle this?

Put a single file in the parent directory of those 3, I think.
Pedro Alves March 2, 2020, 6:12 p.m. UTC | #5
On 3/2/20 5:58 PM, Eli Zaretskii wrote:
>> Cc: gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>
>> From: Pedro Alves <palves@redhat.com>
>> Date: Mon, 2 Mar 2020 17:34:20 +0000
>>
>>> I'm not aware of a way to import one .dir-locals from another, I did
>>> some searching and couldn't find anything promising.
>>>
>>
>> Let's ask an Emacs maintainer.
>>
>> Eli, what's the best way to handle this?
> 
> Put a single file in the parent directory of those 3, I think.

Good point.  This would affect all projects in the top level,
though perhaps the file is right for all of them.  

OOC, if we wanted to say, source "../gdb/.dir-locals.el" from
a gdbserver/.dir-locals.el file, would it be possible?

I guess a symlink would do too.  Except that might not work
as nicely on Windows filesystems.

Thanks,
Pedro Alves
Eli Zaretskii March 2, 2020, 7:19 p.m. UTC | #6
> Cc: andrew.burgess@embecosm.com, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 2 Mar 2020 18:12:53 +0000
> 
> > Put a single file in the parent directory of those 3, I think.
> 
> Good point.  This would affect all projects in the top level,
> though perhaps the file is right for all of them.  

You can arrange for the settings to affect only some of the
subdirectories, the Emacs manual shows an example of that.

> OOC, if we wanted to say, source "../gdb/.dir-locals.el" from
> a gdbserver/.dir-locals.el file, would it be possible?

.dir-locals.el supports 'eval' forms, so you could in principle do
anything there.  But my advice is to stick to simplicity, for reasons
of speed of visiting files, if nothing else.  Also, maintaining such a
tricky file would need an Emacs expert, something that is not
guaranteed (although currently we have several on board).

> I guess a symlink would do too.  Except that might not work
> as nicely on Windows filesystems.

IME, symlinks in versioned directories are a PITA.
Andrew Burgess March 5, 2020, 3:12 p.m. UTC | #7
* Eli Zaretskii <eliz@gnu.org> [2020-03-02 21:19:18 +0200]:

> > Cc: andrew.burgess@embecosm.com, gdb-patches@sourceware.org
> > From: Pedro Alves <palves@redhat.com>
> > Date: Mon, 2 Mar 2020 18:12:53 +0000
> > 
> > > Put a single file in the parent directory of those 3, I think.
> > 
> > Good point.  This would affect all projects in the top level,
> > though perhaps the file is right for all of them.  
> 
> You can arrange for the settings to affect only some of the
> subdirectories, the Emacs manual shows an example of that.

I took a look at the examples, and, if I understand correctly I would
need to do something like:

  (("gdb/" . ((tcl-mode . (... settings ...))
              (nil . (... settings ...))
              (c-mode . (... settings ...))
              (c++-mode . (... settings ...))))
   ("gdbserver/" . ((tcl-mode . (... settings ...))
                    (nil . (... settings ...))
                    (c-mode . (... settings ...))
                    (c++-mode . (... settings ...))))
   ("gdbsupport/" . ((tcl-mode . (... settings ...))
                     (nil . (... settings ...))
                     (c-mode . (... settings ...))
                     (c++-mode . (... settings ...)))))

As there's no easy way (I think) to define a list of settings then
apply them to multiple directories.

Given how rarely the .dir-locals files change, my instinct is to just
add two new copies, and possibly ensure that all three versions of the
file have a big comment saying "remember to update the other versions
of this file located in ......".

Thoughts welcome,

thanks,
Andrew



> 
> > OOC, if we wanted to say, source "../gdb/.dir-locals.el" from
> > a gdbserver/.dir-locals.el file, would it be possible?
> 
> .dir-locals.el supports 'eval' forms, so you could in principle do
> anything there.  But my advice is to stick to simplicity, for reasons
> of speed of visiting files, if nothing else.  Also, maintaining such a
> tricky file would need an Emacs expert, something that is not
> guaranteed (although currently we have several on board).
> 
> > I guess a symlink would do too.  Except that might not work
> > as nicely on Windows filesystems.
> 
> IME, symlinks in versioned directories are a PITA.
Eli Zaretskii March 5, 2020, 3:26 p.m. UTC | #8
> Date: Thu, 5 Mar 2020 15:12:32 +0000
> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Cc: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
> 
> > > > Put a single file in the parent directory of those 3, I think.
> > > 
> > > Good point.  This would affect all projects in the top level,
> > > though perhaps the file is right for all of them.  
> > 
> > You can arrange for the settings to affect only some of the
> > subdirectories, the Emacs manual shows an example of that.
> 
> I took a look at the examples, and, if I understand correctly I would
> need to do something like:

Yes, I think this is correct.

> Given how rarely the .dir-locals files change, my instinct is to just
> add two new copies, and possibly ensure that all three versions of the
> file have a big comment saying "remember to update the other versions
> of this file located in ......".

I'm okay with that as well, if people prefer it.
Pedro Alves March 5, 2020, 4 p.m. UTC | #9
On 3/5/20 3:26 PM, Eli Zaretskii wrote:
>> Date: Thu, 5 Mar 2020 15:12:32 +0000
>> From: Andrew Burgess <andrew.burgess@embecosm.com>
>> Cc: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
>>
>>>>> Put a single file in the parent directory of those 3, I think.
>>>>
>>>> Good point.  This would affect all projects in the top level,
>>>> though perhaps the file is right for all of them.  
>>>
>>> You can arrange for the settings to affect only some of the
>>> subdirectories, the Emacs manual shows an example of that.
>>
>> I took a look at the examples, and, if I understand correctly I would
>> need to do something like:
> 
> Yes, I think this is correct.

Thanks for exploring this.

> 
>> Given how rarely the .dir-locals files change, my instinct is to just
>> add two new copies, and possibly ensure that all three versions of the
>> file have a big comment saying "remember to update the other versions
>> of this file located in ......".
> 
> I'm okay with that as well, if people prefer it.

Yes, let's do that.

Thanks,
Pedro Alves
diff mbox

Patch

diff --git a/gdbserver/.dir-locals.el b/gdbserver/.dir-locals.el
new file mode 100644
index 00000000000..29c3d69869e
--- /dev/null
+++ b/gdbserver/.dir-locals.el
@@ -0,0 +1,39 @@ 
+;; Emacs settings.
+;; Copyright (C) 2012-2020 Free Software Foundation, Inc.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+(
+ (tcl-mode . ((tcl-indent-level . 4)
+	      (tcl-continued-indent-level . 4)
+	      (indent-tabs-mode . t)))
+ (nil . ((bug-reference-url-format . "http://sourceware.org/bugzilla/show_bug.cgi?id=%s")))
+ ;; We store C++ headers in files matching *.h, which is usually for C
+ ;; headers, so here we arrange to switch all c-mode files into c++-mode.
+ (c-mode . ((c-file-style . "GNU")
+	    (mode . c++)
+	    (indent-tabs-mode . t)
+	    (tab-width . 8)
+	    (c-basic-offset . 2)
+	    (eval . (c-set-offset 'innamespace 0))
+	    ))
+ (c++-mode . ((eval . (when (fboundp 'c-toggle-comment-style)
+			(c-toggle-comment-style 1)))
+	      (indent-tabs-mode . t)
+	      (tab-width . 8)
+	      (c-file-style . "GNU")
+	      (c-basic-offset . 2)
+	      (eval . (c-set-offset 'innamespace 0))
+	      ))
+)