unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5127: Indentation of top level tags when no single top level tag
@ 2009-12-04 23:17 Lennart Borgman
  2009-12-05  5:04 ` Stefan Monnier
  2020-08-25 13:47 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 4+ messages in thread
From: Lennart Borgman @ 2009-12-04 23:17 UTC (permalink / raw)
  To: Emacs Bugs

[-- Attachment #1: Type: text/plain, Size: 582 bytes --]

Sometimes a user is working with part of a code and still want to do
indentation. In cases like this

              <head>
              </head>
              <body>

the body tag will currently be intended to column 0 by sgml-indent-line.

The attached patch handles this particular case specially to avoid
that. Since I do not want to change the return values from
sgml-geet-context (which is where this situation best can be detected)
I have transferred the extra information in a global variable
sgml-get-context-last-close instead.

This is against a checkout from 2009-12-04.

[-- Attachment #2: indent-outermost.patch --]
[-- Type: text/x-diff, Size: 3897 bytes --]

Index: sgml-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/textmodes/sgml-mode.el,v
retrieving revision 1.145
diff -c -r1.145 sgml-mode.el
*** sgml-mode.el	31 Oct 2009 21:52:56 -0000	1.145
--- sgml-mode.el	4 Dec 2009 23:04:06 -0000
***************
*** 1265,1270 ****
--- 1265,1274 ----
        (goto-char tag-start)
        (sgml-make-tag tag-type tag-start tag-end name))))
  
+ (defvar sgml-get-context-last-close nil
+   "Last close tag start.
+ Only used for outermost level.")
+ 
  (defun sgml-get-context (&optional until)
    "Determine the context of the current position.
  By default, parse until we find a start-tag as the first thing on a line.
***************
*** 1280,1291 ****
  	(stack nil)
  	(ignore nil)
  	(context nil)
! 	tag-info)
      ;; CONTEXT keeps track of the tag-stack
      ;; STACK keeps track of the end tags we've seen (and thus the start-tags
      ;;   we'll have to ignore) when skipping over matching open..close pairs.
      ;; IGNORE is a list of tags that can be ignored because they have been
      ;;   closed implicitly.
      (skip-chars-backward " \t\n")      ; Make sure we're not at indentation.
      (while
  	(and (not (eq until 'now))
--- 1284,1298 ----
  	(stack nil)
  	(ignore nil)
  	(context nil)
! 	tag-info
!         last-close)
      ;; CONTEXT keeps track of the tag-stack
      ;; STACK keeps track of the end tags we've seen (and thus the start-tags
      ;;   we'll have to ignore) when skipping over matching open..close pairs.
      ;; IGNORE is a list of tags that can be ignored because they have been
      ;;   closed implicitly.
+     ;; LAST-CLOSE is last close tag that can be useful for indentation
+     ;;   when on outermost level.
      (skip-chars-backward " \t\n")      ; Make sure we're not at indentation.
      (while
  	(and (not (eq until 'now))
***************
*** 1312,1317 ****
--- 1319,1327 ----
  
         ;; start-tag
         ((eq (sgml-tag-type tag-info) 'open)
+         (when (and (null stack)
+                    last-close)
+           (setq last-close 'no-use))
  	(cond
  	 ((null stack)
  	  (if (assoc-string (sgml-tag-name tag-info) ignore t)
***************
*** 1354,1363 ****
--- 1364,1389 ----
         ((eq (sgml-tag-type tag-info) 'close)
  	(if (sgml-empty-tag-p (sgml-tag-name tag-info))
  	    (message "Spurious </%s>: empty tag" (sgml-tag-name tag-info))
+           ;; Keep track of last close if context will return nil
+           (when (and (not last-close)
+                      (null stack)
+                      (> here (point-at-eol))
+                      (let ((here (point)))
+                        (goto-char (sgml-tag-start tag-info))
+                        (skip-chars-backward " \t")
+                        (prog1
+                            (bolp)
+                          (goto-char here))))
+             (setq last-close tag-info))
+ 
  	  (push (sgml-tag-name tag-info) stack)))
         ))
  
      ;; return context
+     (setq sgml-get-context-last-close
+           (when (and last-close
+                      (not (eq last-close 'no-use)))
+             (sgml-tag-start last-close)))
      context))
  
  (defun sgml-show-context (&optional full)
***************
*** 1508,1514 ****
  	      (< (point) here) (sgml-at-indentation-p))
  	 (current-column))
  	(t
! 	 (goto-char there)
  	 (+ (current-column)
  	    (* sgml-basic-offset (length context)))))))
  
--- 1534,1542 ----
  	      (< (point) here) (sgml-at-indentation-p))
  	 (current-column))
  	(t
! 	 (goto-char (or (and (null context)
!                              sgml-get-context-last-close)
!                         there))
  	 (+ (current-column)
  	    (* sgml-basic-offset (length context)))))))
  

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

* bug#5127: Indentation of top level tags when no single top level tag
  2009-12-04 23:17 bug#5127: Indentation of top level tags when no single top level tag Lennart Borgman
@ 2009-12-05  5:04 ` Stefan Monnier
  2009-12-05  9:49   ` Lennart Borgman
  2020-08-25 13:47 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2009-12-05  5:04 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 5127

> Sometimes a user is working with part of a code and still want to do
> indentation. In cases like this

>               <head>
>               </head>
>               <body>

> the body tag will currently be intended to column 0 by sgml-indent-line.

What's wrong with that?  Or do you mean it shoujld be indented to the
same level as the preceding <head>?


        Stefan





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

* bug#5127: Indentation of top level tags when no single top level tag
  2009-12-05  5:04 ` Stefan Monnier
@ 2009-12-05  9:49   ` Lennart Borgman
  0 siblings, 0 replies; 4+ messages in thread
From: Lennart Borgman @ 2009-12-05  9:49 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 5127

On Sat, Dec 5, 2009 at 6:04 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> Sometimes a user is working with part of a code and still want to do
>> indentation. In cases like this
>
>>               <head>
>>               </head>
>>               <body>
>
>> the body tag will currently be intended to column 0 by sgml-indent-line.
>
> What's wrong with that?  Or do you mean it shoujld be indented to the
> same level as the preceding <head>?


Yes.





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

* bug#5127: Indentation of top level tags when no single top level tag
  2009-12-04 23:17 bug#5127: Indentation of top level tags when no single top level tag Lennart Borgman
  2009-12-05  5:04 ` Stefan Monnier
@ 2020-08-25 13:47 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-25 13:47 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 5127

Lennart Borgman <lennart.borgman@gmail.com> writes:

> Sometimes a user is working with part of a code and still want to do
> indentation. In cases like this
>
>               <head>
>               </head>
>               <body>
>
> the body tag will currently be intended to column 0 by sgml-indent-line.

I put the example into a file called foo.sgml and hit TAB on the <body>
in Emacs 28, and the <body> didn't move, so I'm guessing this has been
fixed in the decade since this was reported?

So I'm closing this bug report.  If you're still seeing the problem,
send a mail to the debbugs address and we'll reopen the bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2020-08-25 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-04 23:17 bug#5127: Indentation of top level tags when no single top level tag Lennart Borgman
2009-12-05  5:04 ` Stefan Monnier
2009-12-05  9:49   ` Lennart Borgman
2020-08-25 13:47 ` Lars Ingebrigtsen

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