help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comment indentation problems in nxml


From: Andreas Röhler
Subject: Re: Comment indentation problems in nxml
Date: Tue, 13 Nov 2018 11:55:45 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 11.11.2018 15:51, Steinar Bang wrote:
Emacs version: GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 
2017-09-15, modified by Debian
               (I'm using the version of nxml delivered with emacs)

I recently changed the copyright headers in XML files in one of my
projects from the massive
     <!-- Copyright 2018 Steinar Bang                                              
       -->
     <!--                                                                          
       -->
     <!-- Licensed under the Apache License, Version 2.0 (the "License");          
       -->
     <!-- you may not use this file except in compliance with the License.         
       -->
     <!-- You may obtain a copy of the License at                                  
       -->
     <!--   http://www.apache.org/licenses/LICENSE-2.0                             
       -->
     <!-- Unless required by applicable law or agreed to in writing,               
       -->
     <!-- software distributed under the License is distributed on an "AS IS" 
BASIS,      -->
     <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
       -->
     <!-- See the License for the specific language governing permissions and 
limitations -->
     <!-- under the License.                                                       
       -->


to the more "airy" an (I think) estetic

     <!--
         Copyright 2018 Steinar Bang

         Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

         Unless required by applicable law or agreed to in writing,
         software distributed under the License is distributed on an "AS IS" 
BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied.
         See the License for the specific language governing permissions and 
limitations
         under the License.
     -->
However, this doesn't play well with my formatting fixup function:
(defun ide-fix ()
   "Remove trailing spaces and fix indentation"
   (interactive)
   (save-excursion
     (goto-char (point-min))
     (replace-regexp "[ \t]+$" "")
     (goto-char (point-min))
     (replace-string "\t" " ")
     (indent-region (point-min) (point-max))))


After running "ide-fix", the indentation of the first line is kept, but
all of the other lines are moved to the left margin:

     <!--
         Copyright 2018 Steinar Bang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations
under the License.
     -->


Is it possible to make nxml preserve the original indentation in these
comments?

(Or should I just bite the bullet and go back to the old copyright
headers?)

Thanks!


- Steinar




In ide-fix

replacing

 (replace-string "\t" " ")

bei a call like of untabify, for example

(untabify (point-min) (point-max))

would keep indent and might help.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]