unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Comment indentation problems in nxml
@ 2018-11-11 14:51 Steinar Bang
  2018-11-13 10:55 ` Andreas Röhler
  0 siblings, 1 reply; 2+ messages in thread
From: Steinar Bang @ 2018-11-11 14:51 UTC (permalink / raw)
  To: help-gnu-emacs

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



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

* Re: Comment indentation problems in nxml
  2018-11-11 14:51 Comment indentation problems in nxml Steinar Bang
@ 2018-11-13 10:55 ` Andreas Röhler
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Röhler @ 2018-11-13 10:55 UTC (permalink / raw)
  To: help-gnu-emacs

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.



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

end of thread, other threads:[~2018-11-13 10:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-11 14:51 Comment indentation problems in nxml Steinar Bang
2018-11-13 10:55 ` Andreas Röhler

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