all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Display "dash" as "minus" in programming language mode?
@ 2009-07-08 21:01 Torsten Bronger
  2009-07-08 21:39 ` Pascal J. Bourguignon
  2009-07-09  1:23 ` Kevin Rodgers
  0 siblings, 2 replies; 8+ messages in thread
From: Torsten Bronger @ 2009-07-08 21:01 UTC (permalink / raw)
  To: help-gnu-emacs

Hallöchen!

I have an arguably odd question: Is it possible to tell Emacs to
display every "dash" character as an "en-dash" character?

The reason is that I use the DejaVu fonts which have a particularly
short dash.  In source code, this is unfortunate.  Is is possible to
use e.g. font-lock-mode to substitute "en-dash" or "minus" for every
"dash"?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                   Jabber ID: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com


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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-08 21:01 Display "dash" as "minus" in programming language mode? Torsten Bronger
@ 2009-07-08 21:39 ` Pascal J. Bourguignon
  2009-07-09  7:56   ` Torsten Bronger
  2009-07-09  1:23 ` Kevin Rodgers
  1 sibling, 1 reply; 8+ messages in thread
From: Pascal J. Bourguignon @ 2009-07-08 21:39 UTC (permalink / raw)
  To: help-gnu-emacs

Torsten Bronger <bronger@physik.rwth-aachen.de> writes:

> Hallöchen!
>
> I have an arguably odd question: Is it possible to tell Emacs to
> display every "dash" character as an "en-dash" character?
>
> The reason is that I use the DejaVu fonts which have a particularly
> short dash.  In source code, this is unfortunate.  Is is possible to
> use e.g. font-lock-mode to substitute "en-dash" or "minus" for every
> "dash"?

Yes, it's trivial:

(font-lock-add-keywords nil
   '(("-" (0 (progn (compose-region (match-beginning 0) (match-end 0)  "–"
                                  'decompose-region)
                     nil)))))


-- 
__Pascal Bourguignon__


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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-08 21:01 Display "dash" as "minus" in programming language mode? Torsten Bronger
  2009-07-08 21:39 ` Pascal J. Bourguignon
@ 2009-07-09  1:23 ` Kevin Rodgers
  1 sibling, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2009-07-09  1:23 UTC (permalink / raw)
  To: help-gnu-emacs

Torsten Bronger wrote:
> Hallöchen!
> 
> I have an arguably odd question: Is it possible to tell Emacs to
> display every "dash" character as an "en-dash" character?
> 
> The reason is that I use the DejaVu fonts which have a particularly
> short dash.  In source code, this is unfortunate.  Is is possible to
> use e.g. font-lock-mode to substitute "en-dash" or "minus" for every
> "dash"?

How about:

(aset (or standard-display-table
	  (setq standard-display-table (make-display-table)))
       ?- [?\u2013])

Or for just programming language mode foo:

(add-hook 'foo-mode-hook
	  (lambda ()
	    (aset (or buffer-display-table
		      (setq buffer-display-table (make-display-table)))
		  ?- [?\u2013])))

-- 
Kevin Rodgers
Denver, Colorado, USA





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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-08 21:39 ` Pascal J. Bourguignon
@ 2009-07-09  7:56   ` Torsten Bronger
  2009-07-09  9:00     ` Miles Bader
  2009-07-10 14:15     ` Torsten Bronger
  0 siblings, 2 replies; 8+ messages in thread
From: Torsten Bronger @ 2009-07-09  7:56 UTC (permalink / raw)
  To: help-gnu-emacs

Hallöchen!

Pascal J. Bourguignon writes:

> Torsten Bronger <bronger@physik.rwth-aachen.de> writes:
>
>> I have an arguably odd question: Is it possible to tell Emacs to
>> display every "dash" character as an "en-dash" character?
>>
>> The reason is that I use the DejaVu fonts which have a
>> particularly short dash.  In source code, this is unfortunate.
>> Is is possible to use e.g. font-lock-mode to substitute "en-dash"
>> or "minus" for every "dash"?
>
> Yes, it's trivial:
>
> (font-lock-add-keywords nil
>    '(("-" (0 (progn (compose-region (match-beginning 0) (match-end 0)  "–"
>                                   'decompose-region)
>                      nil)))))

Thanks to both of you.  I now use

(add-hook 'python-mode-hook
	  (lambda ()
	    (font-lock-add-keywords nil
				    '(("\\B-\\B"
				       (0 (progn (compose-region (match-beginning 0) (match-end 0)  "−"
								 'decompose-region)
						 nil)))
				      ))))
(add-hook 'python-mode-hook
	  (lambda ()
	    (aset (or buffer-display-table
		      (setq buffer-display-table (make-display-table)))
		  ?* [?✻])))

Although the heuristics are not perfict, it works quite nicely.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                   Jabber ID: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com


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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-09  7:56   ` Torsten Bronger
@ 2009-07-09  9:00     ` Miles Bader
  2009-07-09  9:15       ` Torsten Bronger
  2009-07-10 14:15     ` Torsten Bronger
  1 sibling, 1 reply; 8+ messages in thread
From: Miles Bader @ 2009-07-09  9:00 UTC (permalink / raw)
  To: help-gnu-emacs

Torsten Bronger <bronger@physik.rwth-aachen.de> writes:
> (add-hook 'python-mode-hook
> 	  (lambda ()
> 	    (font-lock-add-keywords nil
> 				    '(("\\B-\\B"
> 				       (0 (progn (compose-region (match-beginning 0) (match-end 0)  "−"
> 								 'decompose-region)
> 						 nil)))
> 				      ))))
> (add-hook 'python-mode-hook
> 	  (lambda ()
> 	    (aset (or buffer-display-table
> 		      (setq buffer-display-table (make-display-table)))
> 		  ?* [?✻])))

Hmm, why add font-lock stuff, when using display-table for dash too
would be easier and far more efficient (and you're already setting up
the display table anyway, so even simpler...)?

[I mean, like:

(add-hook 'python-mode-hook
	  (lambda ()
            (unless buffer-display-table
              (setq buffer-display-table (make-display-table)))
            (aset buffer-display-table ?* [?✻])
            (aset buffer-display-table ?- [?−])))

]

-Miles

-- 
Politics, n. A strife of interests masquerading as a contest of
principles. The conduct of public affairs for private advantage.


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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-09  9:00     ` Miles Bader
@ 2009-07-09  9:15       ` Torsten Bronger
  2009-07-09 11:04         ` Miles Bader
  0 siblings, 1 reply; 8+ messages in thread
From: Torsten Bronger @ 2009-07-09  9:15 UTC (permalink / raw)
  To: help-gnu-emacs

Hallöchen!

Miles Bader writes:

> Torsten Bronger <bronger@physik.rwth-aachen.de> writes:
>
>> (add-hook 'python-mode-hook
>> 	  (lambda ()
>> 	    (font-lock-add-keywords nil
>> 				    '(("\\B-\\B"
>> (0 (progn (compose-region (match-beginning 0) (match-end 0) "−"
>> 'decompose-region)
>> 						 nil)))
>> 				      ))))
>> (add-hook 'python-mode-hook
>> 	  (lambda ()
>> 	    (aset (or buffer-display-table
>> 		      (setq buffer-display-table (make-display-table)))
>> 		  ?* [?✻])))
>
> Hmm, why add font-lock stuff, when using display-table for dash
> too would be easier and far more efficient (and you're already
> setting up the display table anyway, so even simpler...)?

I couldn't restrict the effect to (Python) code, so all dashs in
comments and strings became minuses, too.  But the "\\B-\\B" worked
quite well.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                   Jabber ID: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com


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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-09  9:15       ` Torsten Bronger
@ 2009-07-09 11:04         ` Miles Bader
  0 siblings, 0 replies; 8+ messages in thread
From: Miles Bader @ 2009-07-09 11:04 UTC (permalink / raw)
  To: help-gnu-emacs

Torsten Bronger <bronger@physik.rwth-aachen.de> writes:
> I couldn't restrict the effect to (Python) code, so all dashs in
> comments and strings became minuses, too.  But the "\\B-\\B" worked
> quite well.

ah, ic...

Personally I think the default dejavu sans mono hyphen looks kind crappy
in comments and strings too, so a global replace would be fine, but I
suppose ymmv...

[I'd go so far as to call it a bug in dejavu sans mono -- a monospaced
font shouldn't have such a dinky hyphen.  I guess they probably just
copied it from dejavu sans.  Hmm, maybe I oughta file a bug report...]

-Miles

-- 
Accordion, n. An instrument in harmony with the sentiments of an assassin.


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

* Re: Display "dash" as "minus" in programming language mode?
  2009-07-09  7:56   ` Torsten Bronger
  2009-07-09  9:00     ` Miles Bader
@ 2009-07-10 14:15     ` Torsten Bronger
  1 sibling, 0 replies; 8+ messages in thread
From: Torsten Bronger @ 2009-07-10 14:15 UTC (permalink / raw)
  To: help-gnu-emacs

Hallöchen!

Torsten Bronger writes:

> [...]
>
> [...]  I now use
>
> (add-hook 'python-mode-hook
> 	  (lambda ()
> 	    (font-lock-add-keywords nil
> 				    '(("\\B-\\B"
> 				       (0 (progn (compose-region (match-beginning 0) (match-end 0) "−" 'decompose-region)
> 						 nil)))
> 				      ))))

Sorry to disturb again, but it didn't work because Emacs treats
numbers as words, so the regexp \B-\B means that negative integers
like -1 get a dash instead of a minus.  And negative integers are
frequent in Python.

Is it possible to substitute *all* "-", except those in comments and
string literals?  The documentation of font-lock-mode just says that
add-keywords really works also in comments but I didn't understand
enough of it to prevent it.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                   Jabber ID: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com


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

end of thread, other threads:[~2009-07-10 14:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-08 21:01 Display "dash" as "minus" in programming language mode? Torsten Bronger
2009-07-08 21:39 ` Pascal J. Bourguignon
2009-07-09  7:56   ` Torsten Bronger
2009-07-09  9:00     ` Miles Bader
2009-07-09  9:15       ` Torsten Bronger
2009-07-09 11:04         ` Miles Bader
2009-07-10 14:15     ` Torsten Bronger
2009-07-09  1:23 ` Kevin Rodgers

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.