all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Bad Blue Bull <ibmbull@yandex.ru>
Cc: 32281@debbugs.gnu.org
Subject: bug#32281: shr.el align support patch
Date: Sun, 05 Aug 2018 22:52:35 -0400	[thread overview]
Message-ID: <87wot4xl3g.fsf@gmail.com> (raw)
In-Reply-To: <6177421532613989@iva7-bd007c44f58e.qloud-c.yandex.net> (Bad Blue Bull's message of "Thu, 26 Jul 2018 17:06:29 +0300")

severity 32281 wishlist
tags 32281 + patch
quit

Bad Blue Bull <ibmbull@yandex.ru> writes:

> Here's a patch for shr.el that makes it handle "align" attribute for
> headers, paragraphs and lists, works only when monospace font is used
> (becoz of lame implementation of fill-paragraph). Also default value
> of shr-use-fonts set to nil so monospace fonts are used by default.

Seems reasonable overall, but I'm not sure if changing the default is
justified.

> -(defcustom shr-use-fonts t
> +(defcustom shr-use-fonts nil ; set default value to nil because monospace fonts are better for Emacs

Although I do somewhat agree with the "monospace fonts are better for
Emacs" sentiment.

> +(defun shr-fill-paragraph-with-breaks (&optional justify bre-del bre-regexp)
> +  "Fill paragraph at or after point, breaking lines at positions matching regexp argument BRE-REGEXP.
> +If JUSTIFY is non-nil justify as well.
> +Delete matched text if BRE-DEL is non nil
> +BRE-REGEXP must be a regexp that determines positions where to break lines, default value is \\x2028."
> +  (unless bre-regexp (setq bre-regexp "\x2028"))
> +  (setq bre-regexp (concat bre-regexp "\\|\x2029"))
> +  (save-excursion
> +   (let ((line-begin) (paragraph-end))
> +	 (forward-paragraph)
> +	 (insert "\x2029") ; use \x2029 (unicode paragraph separator) to mark end of a paragraph
> +	 (backward-paragraph)
> +	 (setq line-begin (point))
> +	 (while (not paragraph-end)
> +			(re-search-forward bre-regexp)
> +			(if (equal (match-string 0) "\x2029") (setq paragraph-end t)) ; end of paragraph reached
> +			(if (or bre-del paragraph-end) (replace-match ""))
> +			(unless (equal (char-after) ?\n) (insert "\n")) ; I don't know why but two adjacent \n leave an empty line after fill
> +			(fill-region-as-paragraph line-begin (- (point) 1) justify)
> +			(setq line-begin (point)))
> +	 (delete-char -1)
> +	 )))

> +(defun shr-fill-paragraph (dom)
> +  "Fill paragraph"
> +  (when (not shr-use-fonts) ;fill-paragraph is useful only with monospace fonts
> + 	(shr-fill-paragraph-with-breaks
> +	 ((lambda (x)
> +	   (cond
> + 		 ((equal x "right") 'right)
> + 		 ((equal x "center") 'center)
> + 		 ((equal x "left") 'left)
> + 		 ))
> + 	 (cdr (assq 'align (dom-attributes dom)))) ; justify parameter
> +	 t) ; bre-del t
> + 	)
> +  )
> +

>  (defun shr-tag-li (dom)
> @@ -1770,6 +1813,7 @@
>  	(put-text-property start (1+ start) 'shr-prefix-length (length bullet))
>  	(shr-generic dom))))
>    (unless (bolp)
> +	(unless shr-use-fonts (insert "\x2028")) ; insert a line separator
>      (insert "\n")))
>  
>  (defun shr-mark-fill (start)
> @@ -1785,7 +1829,8 @@
>  	     (or (not (bolp))
>  		 (and (> (- (point) 2) (point-min))
>  		      (not (= (char-after (- (point) 2)) ?\n)))))
> -    (insert "\n"))
> +	(unless shr-use-fonts (insert "\x2028")) ; insert a line separator
> +	(insert "\n"))
>    (shr-generic dom))

The indentation in your patch looks kind of off, are you not using
Emacs' builtin auto-indentation?  (also, don't leave hanging parens.)





  reply	other threads:[~2018-08-06  2:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-26 14:06 bug#32281: shr.el align support patch Bad Blue Bull
2018-08-06  2:52 ` Noam Postavsky [this message]
2018-08-06 15:13   ` Eli Zaretskii
2018-08-07  0:51     ` Bad Blue Bull
2018-08-07  0:59       ` Bad Blue Bull
2018-08-07  2:34       ` Noam Postavsky
2018-08-07 15:07       ` Eli Zaretskii
2018-08-07 16:54         ` Bad Blue Bull
2018-08-07 17:11           ` Bad Blue Bull
2018-08-07 17:19           ` Eli Zaretskii
2018-08-07 18:15             ` Bad Blue Bull
2018-08-07 18:15       ` Lars Ingebrigtsen
2018-08-07 19:56         ` Bad Blue Bull
2018-08-10  0:12           ` Noam Postavsky
2018-08-06 17:36 ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wot4xl3g.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=32281@debbugs.gnu.org \
    --cc=ibmbull@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.