all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs Shell Ansi Colors
@ 2008-09-28 19:27 Lorenzo Isella
  2008-09-28 21:19 ` Thierry Volpiatto
  0 siblings, 1 reply; 14+ messages in thread
From: Lorenzo Isella @ 2008-09-28 19:27 UTC (permalink / raw
  To: help-gnu-emacs

Dear All,
I often use M-x shell to open a shell within Emacs.  Since I miss the 
colorized output, I tried to enable ansi-colors in my Emacs shell.  
After googling, I found suggestions along the lines of the link pasted below

http://www.grokblok.com/articles/2007/12/13/emacs-shell-ansi-colors/

The problem is that I added those few lines to my .emacs file, but 
nothing changed.
I had a look also at:
http://www.emacswiki.org/cgi-bin/wiki/ansi-color.el
but I did not copy the ansi-color.el file anywhere in my system (in case 
it matters, I am running emacs22 on a Debian testing box).
I notice that issuing the command (within emacs shell):
ls --color=yes
give the nice colorized output I am looking for, hence I do not think 
there is any substantial problem by default, just it seems that my 
output is not colorized by default (though when I type M-x shell I read 
the message
Loading ansi-color...done ).
Can anyone help me out with this?
Many thanks

Lorenzo




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

* Re: Emacs Shell Ansi Colors
  2008-09-28 19:27 Emacs Shell Ansi Colors Lorenzo Isella
@ 2008-09-28 21:19 ` Thierry Volpiatto
       [not found]   ` <F725F550-369F-4C9A-BACA-D13E30D70FC2@Web.DE>
  0 siblings, 1 reply; 14+ messages in thread
From: Thierry Volpiatto @ 2008-09-28 21:19 UTC (permalink / raw
  To: help-gnu-emacs

Hi Lorenzo,

Lorenzo Isella <lorenzo.isella@gmail.com> writes:

> Dear All,
> I often use M-x shell to open a shell within Emacs.  Since I miss the
> colorized output, I tried to enable ansi-colors in my Emacs shell.
> After googling, I found suggestions along the lines of the link pasted
> below
>
> http://www.grokblok.com/articles/2007/12/13/emacs-shell-ansi-colors/
>
> The problem is that I added those few lines to my .emacs file, but
> nothing changed.
> I had a look also at:
> http://www.emacswiki.org/cgi-bin/wiki/ansi-color.el
> but I did not copy the ansi-color.el file anywhere in my system (in
> case it matters, I am running emacs22 on a Debian testing box).
> I notice that issuing the command (within emacs shell):
> ls --color=yes
> give the nice colorized output I am looking for, hence I do not think
> there is any substantial problem by default, just it seems that my
> output is not colorized by default (though when I type M-x shell I
> read the message
> Loading ansi-color...done ).
> Can anyone help me out with this?
> Many thanks

Try that in your .emacs:

,----
| (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
| (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
`----

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





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

* Re: Emacs Shell Ansi Colors
       [not found]   ` <F725F550-369F-4C9A-BACA-D13E30D70FC2@Web.DE>
@ 2008-09-29 10:48     ` Lorenzo Isella
  2008-09-29 10:59       ` Thierry Volpiatto
                         ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Lorenzo Isella @ 2008-09-29 10:48 UTC (permalink / raw
  To: Peter Dyballa; +Cc: help-gnu-emacs, Thierry Volpiatto

2008/9/29 Peter Dyballa <Peter_Dyballa@web.de>:
>
> Am 28.09.2008 um 23:19 schrieb Thierry Volpiatto:
>
>> ,----
>> | (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
>> | (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
>> `----
>
>
> For me
>
>        (ansi-color-for-comint-mode-on)
>
> is enough ...
>
> --
> Greetings
>
>  Pete
>
> There's no place like ~
>                – (UNIX Guru)
>
>
>
>



Hi,
And thanks for your suggestions. I am puzzled since I gave both a try
(actually one of them is precisely the same recommendation from the
wiki page), but the problem stays the same.
From the web
http://www.emacswiki.org/cgi-bin/wiki/ansi-color.el
I read

;;; Commentary:

;; This file provides a function that takes a string or a region
;; containing Select Graphic Rendition (SGR) control sequences (formerly
;; known as ANSI escape sequences) and tries to translate these into
;; faces.
;;
;; This allows you to run ls --color=yes in shell-mode.  In order to
;; test this, proceed as follows:
;;
;; 1. start a shell: M-x shell
;; 2. load this file: M-x load-library RET ansi-color RET
;; 3. activate ansi-color: M-x ansi-color-for-comint-mode-on
;; 4. test ls --color=yes in the *shell* buffer
;;
;; Note that starting your shell from within Emacs might set the TERM
;; environment variable.  The new setting might disable the output of
;; SGR control sequences.  Using ls --color=yes forces ls to produce
;; these.
;;
;; If you decide you like this, add the following to your .emacs file:
;;
;; (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
;; (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

So it looks like there could be a problem with the TERM environment
variable (but do not ask me what this stands for).
I suppose (hope?) this is a one-liner for somebody really
knowledgeable about emacs.
Kind Regards

Lorenzo




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

* Re: Emacs Shell Ansi Colors
  2008-09-29 10:48     ` Lorenzo Isella
@ 2008-09-29 10:59       ` Thierry Volpiatto
  2008-09-29 12:37       ` Paul R
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Thierry Volpiatto @ 2008-09-29 10:59 UTC (permalink / raw
  To: Lorenzo Isella; +Cc: help-gnu-emacs

"Lorenzo Isella" <lorenzo.isella@gmail.com> writes:

> 2008/9/29 Peter Dyballa <Peter_Dyballa@web.de>:
>>
>> Am 28.09.2008 um 23:19 schrieb Thierry Volpiatto:
>>
>>> ,----
>>> | (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
>>> | (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
>>> `----
>>
>>
>> For me
>>
>>        (ansi-color-for-comint-mode-on)
>>
>> is enough ...
>>
>> --
>> Greetings
>>
>>  Pete
>>
>> There's no place like ~
>>                – (UNIX Guru)
>>
>>
>>
>>
>
>
>
> Hi,
> And thanks for your suggestions. I am puzzled since I gave both a try
> (actually one of them is precisely the same recommendation from the
> wiki page), but the problem stays the same.
>>From the web
> http://www.emacswiki.org/cgi-bin/wiki/ansi-color.el
> I read
>
> ;;; Commentary:
>
> ;; This file provides a function that takes a string or a region
> ;; containing Select Graphic Rendition (SGR) control sequences (formerly
> ;; known as ANSI escape sequences) and tries to translate these into
> ;; faces.
> ;;
> ;; This allows you to run ls --color=yes in shell-mode.  In order to
> ;; test this, proceed as follows:
> ;;
> ;; 1. start a shell: M-x shell
> ;; 2. load this file: M-x load-library RET ansi-color RET
> ;; 3. activate ansi-color: M-x ansi-color-for-comint-mode-on
> ;; 4. test ls --color=yes in the *shell* buffer
> ;;
> ;; Note that starting your shell from within Emacs might set the TERM
> ;; environment variable.  The new setting might disable the output of
> ;; SGR control sequences.  Using ls --color=yes forces ls to produce
> ;; these.
> ;;
> ;; If you decide you like this, add the following to your .emacs file:
> ;;
> ;; (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
> ;; (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
>
> So it looks like there could be a problem with the TERM environment
> variable (but do not ask me what this stands for).
> I suppose (hope?) this is a one-liner for somebody really
> knowledgeable about emacs.
> Kind Regards
>
> Lorenzo
>
ansi-color.el is part of emacs, it will be loaded with emacs, so you
have nothing to do with that.

Also:
be sure you have something like that in your .bashrc:

,----
| if [[ -f ~/.dir_colors ]]; then
| 	eval `dircolors -b ~/.dir_colors`
| else
| 	eval `dircolors -b /etc/DIR_COLORS`
| fi
`----
(Assume you have such a file)

The best is to have a per-user file : "~/.dir_colors"
Just copy it from /etc

You can also add this line in this file:

,----
| TERM dumb
`----

And now with the code i sent in precedent post or the code Peter sent,
it should work.

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France




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

* Re: Emacs Shell Ansi Colors
  2008-09-29 10:48     ` Lorenzo Isella
  2008-09-29 10:59       ` Thierry Volpiatto
@ 2008-09-29 12:37       ` Paul R
  2008-09-29 12:45       ` Paul R
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Paul R @ 2008-09-29 12:37 UTC (permalink / raw
  To: Lorenzo Isella; +Cc: help-gnu-emacs, Thierry Volpiatto

On Mon, 29 Sep 2008 12:48:53 +0200, "Lorenzo Isella" <lorenzo.isella@gmail.com> said:
Lorenzo> So it looks like there could be a problem with the TERM
Lorenzo> environment variable (but do not ask me what this stands
Lorenzo> for). I suppose (hope?) this is a one-liner for somebody
Lorenzo> really knowledgeable about emacs. Kind Regards

Yes, probably. Just read your ~/.bashrc and /etc/profile. Both files
are source'd when your shell starts. I suspect something like an alias
from 'ls' to 'ls --color' to be set in a conditionnal switch. If your
term is dumb (env | grep TERM), the alias is not made. Just ensure by
the mean you want that this alias occurs even in emacs shell mode.


-- 
  Paul




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

* Re: Emacs Shell Ansi Colors
  2008-09-29 10:48     ` Lorenzo Isella
  2008-09-29 10:59       ` Thierry Volpiatto
  2008-09-29 12:37       ` Paul R
@ 2008-09-29 12:45       ` Paul R
  2008-09-29 13:02         ` Lorenzo Isella
       [not found]         ` <mailman.20145.1222693383.18990.help-gnu-emacs@gnu.org>
       [not found]       ` <mailman.20143.1222686216.18990.help-gnu-emacs@gnu.org>
       [not found]       ` <mailman.20146.1222694164.18990.help-gnu-emacs@gnu.org>
  4 siblings, 2 replies; 14+ messages in thread
From: Paul R @ 2008-09-29 12:45 UTC (permalink / raw
  To: Lorenzo Isella; +Cc: help-gnu-emacs, Thierry Volpiatto


Lorenzo> So it looks like there could be a problem with the TERM
Lorenzo> environment variable (but do not ask me what this stands
Lorenzo> for). I suppose (hope?) this is a one-liner for somebody
Lorenzo> really knowledgeable about emacs. Kind Regards

in case you need a drop-in solution for emacs, you can use the lines
below. 

    (comint-send-string (current-buffer) "alias ls='ls --color'")
then do a 
    (comint-send-input)

-- 
  Paul




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

* Re: Emacs Shell Ansi Colors
  2008-09-29 12:45       ` Paul R
@ 2008-09-29 13:02         ` Lorenzo Isella
  2008-09-29 13:40           ` Paul R
       [not found]         ` <mailman.20145.1222693383.18990.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 14+ messages in thread
From: Lorenzo Isella @ 2008-09-29 13:02 UTC (permalink / raw
  To: Paul R; +Cc: help-gnu-emacs, Thierry Volpiatto

OK,
I think we are getting to the bottom of this. Apologies in advance for
the long email, but there are several suggestions here about what to
modify (and how), and my knowledge of shell scripting is clearly on a
different league wrt the one of many people on the list.
To make a long story short, this is the output of your command:

~$ env | grep TERM
TERM=xterm
COLORTERM=gnome-terminal

and this is my .bashrc file (or better: the part about aliases and
colors, which I think is relevant here):

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
'
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    ;;
esac

# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
'

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

and this is my /etc/profile file:

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

umask 022


As to your suggestion:

> in case you need a drop-in solution for emacs, you can use the lines
> below.
>
>    (comint-send-string (current-buffer) "alias ls='ls --color'")
> then do a
>    (comint-send-input)

please, do not laugh, but I am a bit at a loss about the way I should
put this into my .emacs file. The part dealing with the shell is now:

(require 'shell-command)
(shell-command-completion-mode)



;; ;;Now I add another customization for the shell-mode

(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)


(custom-set-variables
 '(comint-scroll-to-bottom-on-input t)  ; always insert at the bottom
 '(comint-scroll-to-bottom-on-output t) ; always add output at the bottom
 '(comint-scroll-show-maximum-output t) ; scroll to show max possible output
 '(comint-completion-autolist t)        ; show completion list when ambiguous
 '(comint-input-ignoredups t)           ; no duplicates in command history
 '(comint-completion-addsuffix t)       ; insert space/slash after
file completion
 )



; make completion buffers disappear after 3 seconds.
(add-hook 'completion-setup-hook
  (lambda () (run-at-time 3 nil
    (lambda () (delete-windows-on "*Completions*")))))

(add-hook 'shell-mode-hook '(lambda () (toggle-truncate-lines 1)))
(setq comint-prompt-read-only t)


What should I actually add to this?
Hope this is the conclusion, thanks again to everybody.
Cheers

Lorenzo


2008/9/29 Paul R <paul.r.ml@gmail.com>:
>
> Lorenzo> So it looks like there could be a problem with the TERM
> Lorenzo> environment variable (but do not ask me what this stands
> Lorenzo> for). I suppose (hope?) this is a one-liner for somebody
> Lorenzo> really knowledgeable about emacs. Kind Regards
>
> in case you need a drop-in solution for emacs, you can use the lines
> below.
>
>    (comint-send-string (current-buffer) "alias ls='ls --color'")
> then do a
>    (comint-send-input)
>
> --
>  Paul
>



-- 
It is hard to want something you cannot describe.




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

* Re: Emacs Shell Ansi Colors
       [not found]         ` <mailman.20145.1222693383.18990.help-gnu-emacs@gnu.org>
@ 2008-09-29 13:32           ` Andreas Politz
  2008-09-29 16:08             ` Peter Dyballa
  0 siblings, 1 reply; 14+ messages in thread
From: Andreas Politz @ 2008-09-29 13:32 UTC (permalink / raw
  To: help-gnu-emacs

Lorenzo Isella wrote:
> OK,
> I think we are getting to the bottom of this. Apologies in advance for
> the long email, but there are several suggestions here about what to
> modify (and how), and my knowledge of shell scripting is clearly on a
> different league wrt the one of many people on the list.
> To make a long story short, this is the output of your command:
> 
> ~$ env | grep TERM
> TERM=xterm
> COLORTERM=gnome-terminal
> 
> and this is my .bashrc file (or better: the part about aliases and
> colors, which I think is relevant here):
> 
> # set a fancy prompt (non-color, unless we know we "want" color)
> case "$TERM" in
> xterm-color)
>     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
> '
>     ;;
> *)
>     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
>     ;;
> esac
> 
> # Comment in the above and uncomment this below for a color prompt
> #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
> '
> 
> # If this is an xterm set the title to user@host:dir
> case "$TERM" in
> xterm*|rxvt*)
>     PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
>     ;;
> *)
>     ;;
> esac
> 
> # Alias definitions.
> # You may want to put all your additions into a separate file like
> # ~/.bash_aliases, instead of adding them here directly.
> # See /usr/share/doc/bash-doc/examples in the bash-doc package.
> 
> #if [ -f ~/.bash_aliases ]; then
> #    . ~/.bash_aliases
> #fi
> 
> # enable color support of ls and also add handy aliases
> if [ "$TERM" != "dumb" ]; then
>     eval "`dircolors -b`"
>     alias ls='ls --color=auto'
>     #alias dir='ls --color=auto --format=vertical'
>     #alias vdir='ls --color=auto --format=long'
> fi
> 
> # some more ls aliases
> #alias ll='ls -l'
> #alias la='ls -A'
> #alias l='ls -CF'
> 
> and this is my /etc/profile file:
> 
> # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
> # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
> 
> if [ "`id -u`" -eq 0 ]; then
>   PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
> else
>   PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
> fi
> 
> if [ "$PS1" ]; then
>   if [ "$BASH" ]; then
>     PS1='\u@\h:\w\$ '
>   else
>     if [ "`id -u`" -eq 0 ]; then
>       PS1='# '
>     else
>       PS1='$ '
>     fi
>   fi
> fi
> 
> export PATH
> 
> umask 022
> 
> 
> As to your suggestion:
> 
>> in case you need a drop-in solution for emacs, you can use the lines
>> below.
>>
>>    (comint-send-string (current-buffer) "alias ls='ls --color'")
>> then do a
>>    (comint-send-input)
> 
> please, do not laugh, but I am a bit at a loss about the way I should
> put this into my .emacs file. The part dealing with the shell is now:
> 
> (require 'shell-command)
> (shell-command-completion-mode)
> 
> 
> 
> ;; ;;Now I add another customization for the shell-mode
> 
> (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
> (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
> 
> 
> (custom-set-variables
>  '(comint-scroll-to-bottom-on-input t)  ; always insert at the bottom
>  '(comint-scroll-to-bottom-on-output t) ; always add output at the bottom
>  '(comint-scroll-show-maximum-output t) ; scroll to show max possible output
>  '(comint-completion-autolist t)        ; show completion list when ambiguous
>  '(comint-input-ignoredups t)           ; no duplicates in command history
>  '(comint-completion-addsuffix t)       ; insert space/slash after
> file completion
>  )
> 
> 
> 
> ; make completion buffers disappear after 3 seconds.
> (add-hook 'completion-setup-hook
>   (lambda () (run-at-time 3 nil
>     (lambda () (delete-windows-on "*Completions*")))))
> 
> (add-hook 'shell-mode-hook '(lambda () (toggle-truncate-lines 1)))
> (setq comint-prompt-read-only t)
> 
> 
> What should I actually add to this?
> Hope this is the conclusion, thanks again to everybody.
> Cheers
> 
> Lorenzo
> 

> 
> 2008/9/29 Paul R <paul.r.ml@gmail.com>:
>> Lorenzo> So it looks like there could be a problem with the TERM
>> Lorenzo> environment variable (but do not ask me what this stands
>> Lorenzo> for). I suppose (hope?) this is a one-liner for somebody
>> Lorenzo> really knowledgeable about emacs. Kind Regards
>>
>> in case you need a drop-in solution for emacs, you can use the lines
>> below.
>>
>>    (comint-send-string (current-buffer) "alias ls='ls --color'")
>> then do a
>>    (comint-send-input)
>>
>> --
>>  Paul
>>
> 
> 
> 

Leave your .emacs as it is and create a file '~/.emacs_bash', insert
the following lines, save and you should have colors.

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
eval "`dircolors -b`"
alias ls='ls --color=auto'


-ap


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

* Re: Emacs Shell Ansi Colors
  2008-09-29 13:02         ` Lorenzo Isella
@ 2008-09-29 13:40           ` Paul R
  2008-09-29 14:32             ` Lorenzo Isella
  0 siblings, 1 reply; 14+ messages in thread
From: Paul R @ 2008-09-29 13:40 UTC (permalink / raw
  To: Lorenzo Isella; +Cc: help-gnu-emacs, Thierry Volpiatto

On Mon, 29 Sep 2008 15:02:57 +0200, "Lorenzo Isella" <lorenzo.isella@gmail.com> said:
Lorenzo> ~$ env | grep TERM TERM=xterm COLORTERM=gnome-terminal

I guess this is the output of the command run from within
gnome-terminal, not from emacs shell mode :)
Run it from shell mode you should read that the term is dumb.

Lorenzo> [ "$TERM" != "dumb" ]; then eval "`dircolors -b`" alias
Lorenzo> ls='ls --color=auto' #alias

Here we go. Emacs comint shell is dumb so the alias won't happen.


Lorenzo> please, do not laugh, but I am a bit at a loss about the way
Lorenzo> I should put this into my .emacs file. The part dealing with
Lorenzo> the shell is now:

I don't use M-x shell at all so I have hard time helping you more.
Reading shell.el code yield :
,---- see lines starting with !!!
|   (interactive
|    (list
|     (and current-prefix-arg
| 	 (read-buffer "Shell buffer: "
| 		      (generate-new-buffer-name "*shell*")))))
|   (setq buffer (get-buffer-create (or buffer "*shell*")))
|   ;; Pop to buffer, so that the buffer's window will be correctly set
|   ;; when we call comint (so that comint sets the COLUMNS env var properly).
|   (pop-to-buffer buffer)
|   (unless (comint-check-proc buffer)
|     (let* ((prog (or explicit-shell-file-name
| 		     (getenv "ESHELL") shell-file-name))
| 	   (name (file-name-nondirectory prog))
|!!!!! NOTICE BELOW
| 	   (startfile (concat "~/.emacs_" name))
| 	   (xargs-name (intern-soft (concat "explicit-" name "-args"))))
|       (unless (file-exists-p startfile)
| 	(setq startfile (concat "~/.emacs.d/init_" name ".sh")))
|       (apply 'make-comint-in-buffer "shell" buffer prog
| 	     (if (file-exists-p startfile) startfile)
| 	     (if (and xargs-name (boundp xargs-name))
| 		 (symbol-value xargs-name)
| 	       '("-i")))
|       (shell-mode)))
|   buffer)
`----

So what we read here is that shell will try to evaluate (with your
shell) the file ~/.emacs_bash or ~/.emacs.d/init_bash.sh

So just drop in either file
   alias ls='ls --color'

followed by a blank line (thx comint) and it should work
automagically.

By the way, have you tried eshell ? In most cases, it just works.

-- 
  Paul




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

* Re: Emacs Shell Ansi Colors
       [not found]       ` <mailman.20143.1222686216.18990.help-gnu-emacs@gnu.org>
@ 2008-09-29 14:14         ` Richard Riley
  0 siblings, 0 replies; 14+ messages in thread
From: Richard Riley @ 2008-09-29 14:14 UTC (permalink / raw
  To: help-gnu-emacs

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> "Lorenzo Isella" <lorenzo.isella@gmail.com> writes:
>
>> 2008/9/29 Peter Dyballa <Peter_Dyballa@web.de>:
>>>
>>> Am 28.09.2008 um 23:19 schrieb Thierry Volpiatto:
>>>
>>>> ,----
>>>> | (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
>>>> | (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
>>>> `----
>>>
>>>
>>> For me
>>>
>>>        (ansi-color-for-comint-mode-on)
>>>
>>> is enough ...
>>>
>>> --
>>> Greetings
>>>
>>>  Pete
>>>
>>> There's no place like ~
>>>                – (UNIX Guru)
>>>
>>>
>>>
>>>
>>
>>
>>
>> Hi,
>> And thanks for your suggestions. I am puzzled since I gave both a try
>> (actually one of them is precisely the same recommendation from the
>> wiki page), but the problem stays the same.
>>>From the web
>> http://www.emacswiki.org/cgi-bin/wiki/ansi-color.el
>> I read
>>
>> ;;; Commentary:
>>
>> ;; This file provides a function that takes a string or a region
>> ;; containing Select Graphic Rendition (SGR) control sequences (formerly
>> ;; known as ANSI escape sequences) and tries to translate these into
>> ;; faces.
>> ;;
>> ;; This allows you to run ls --color=yes in shell-mode.  In order to
>> ;; test this, proceed as follows:
>> ;;
>> ;; 1. start a shell: M-x shell
>> ;; 2. load this file: M-x load-library RET ansi-color RET
>> ;; 3. activate ansi-color: M-x ansi-color-for-comint-mode-on
>> ;; 4. test ls --color=yes in the *shell* buffer
>> ;;
>> ;; Note that starting your shell from within Emacs might set the TERM
>> ;; environment variable.  The new setting might disable the output of
>> ;; SGR control sequences.  Using ls --color=yes forces ls to produce
>> ;; these.
>> ;;
>> ;; If you decide you like this, add the following to your .emacs file:
>> ;;
>> ;; (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
>> ;; (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
>>
>> So it looks like there could be a problem with the TERM environment
>> variable (but do not ask me what this stands for).
>> I suppose (hope?) this is a one-liner for somebody really
>> knowledgeable about emacs.
>> Kind Regards
>>
>> Lorenzo
>>
> ansi-color.el is part of emacs, it will be loaded with emacs, so you
> have nothing to do with that.
>
> Also:
> be sure you have something like that in your .bashrc:
>
> ,----
> | if [[ -f ~/.dir_colors ]]; then
> | 	eval `dircolors -b ~/.dir_colors`
> | else
> | 	eval `dircolors -b /etc/DIR_COLORS`
> | fi
> `----
> (Assume you have such a file)
>
> The best is to have a per-user file : "~/.dir_colors"
> Just copy it from /etc
>
> You can also add this line in this file:
>
> ,----
> | TERM dumb
> `----
>
> And now with the code i sent in precedent post or the code Peter sent,
> it should work.

I just noticed that I have the alias for my ls --color=auto in my bashrc
but the emacs shell does not pick it up in debian. So maybe another rc
file needs this stuff?


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

* Re: Emacs Shell Ansi Colors
       [not found]       ` <mailman.20146.1222694164.18990.help-gnu-emacs@gnu.org>
@ 2008-09-29 14:22         ` Richard Riley
  2008-09-29 14:57           ` Paul R
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Riley @ 2008-09-29 14:22 UTC (permalink / raw
  To: help-gnu-emacs

Paul R <paul.r.ml@gmail.com> writes:

> On Mon, 29 Sep 2008 12:48:53 +0200, "Lorenzo Isella" <lorenzo.isella@gmail.com> said:
> Lorenzo> So it looks like there could be a problem with the TERM
> Lorenzo> environment variable (but do not ask me what this stands
> Lorenzo> for). I suppose (hope?) this is a one-liner for somebody
> Lorenzo> really knowledgeable about emacs. Kind Regards
>
> Yes, probably. Just read your ~/.bashrc and /etc/profile. Both files
> are source'd when your shell starts. I suspect something like an alias
> from 'ls' to 'ls --color' to be set in a conditionnal switch. If your
> term is dumb (env | grep TERM), the alias is not made. Just ensure by
> the mean you want that this alias occurs even in emacs shell mode.

I am not sure .bashrc is sourced when you start "shell". It doesnt seem
to be here on my debian system. I think you need a .emacs_bash. Which is
different from a few years ago. Maybe someone more knowledgeable can
comment.


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

* Re: Emacs Shell Ansi Colors
  2008-09-29 13:40           ` Paul R
@ 2008-09-29 14:32             ` Lorenzo Isella
  0 siblings, 0 replies; 14+ messages in thread
From: Lorenzo Isella @ 2008-09-29 14:32 UTC (permalink / raw
  To: Paul R; +Cc: help-gnu-emacs, Thierry Volpiatto

Perfect! Just to finish off this thread, here is the output of
$ env | grep TERM
TERM=dumb
TERMCAP=
COLORTERM=gnome-terminal

This time ran from within emacs.
I had neither file ~/.emacs_bash nor ~/.emacs.d/init_bash.sh, but
creating ~/.emacs.d/init_bash.sh with the only content

alias ls='ls --color'

 followed by a blank line (precisely as you said) got the job done.
Thanks again to the people on the list.
Cheers

Lorenzo




2008/9/29 Paul R <paul.r.ml@gmail.com>:
> On Mon, 29 Sep 2008 15:02:57 +0200, "Lorenzo Isella" <lorenzo.isella@gmail.com> said:
> Lorenzo> ~$ env | grep TERM TERM=xterm COLORTERM=gnome-terminal
>
> I guess this is the output of the command run from within
> gnome-terminal, not from emacs shell mode :)
> Run it from shell mode you should read that the term is dumb.
>
> Lorenzo> [ "$TERM" != "dumb" ]; then eval "`dircolors -b`" alias
> Lorenzo> ls='ls --color=auto' #alias
>
> Here we go. Emacs comint shell is dumb so the alias won't happen.
>
>
> Lorenzo> please, do not laugh, but I am a bit at a loss about the way
> Lorenzo> I should put this into my .emacs file. The part dealing with
> Lorenzo> the shell is now:
>
> I don't use M-x shell at all so I have hard time helping you more.
> Reading shell.el code yield :
> ,---- see lines starting with !!!
> |   (interactive
> |    (list
> |     (and current-prefix-arg
> |        (read-buffer "Shell buffer: "
> |                     (generate-new-buffer-name "*shell*")))))
> |   (setq buffer (get-buffer-create (or buffer "*shell*")))
> |   ;; Pop to buffer, so that the buffer's window will be correctly set
> |   ;; when we call comint (so that comint sets the COLUMNS env var properly).
> |   (pop-to-buffer buffer)
> |   (unless (comint-check-proc buffer)
> |     (let* ((prog (or explicit-shell-file-name
> |                    (getenv "ESHELL") shell-file-name))
> |          (name (file-name-nondirectory prog))
> |!!!!! NOTICE BELOW
> |          (startfile (concat "~/.emacs_" name))
> |          (xargs-name (intern-soft (concat "explicit-" name "-args"))))
> |       (unless (file-exists-p startfile)
> |       (setq startfile (concat "~/.emacs.d/init_" name ".sh")))
> |       (apply 'make-comint-in-buffer "shell" buffer prog
> |            (if (file-exists-p startfile) startfile)
> |            (if (and xargs-name (boundp xargs-name))
> |                (symbol-value xargs-name)
> |              '("-i")))
> |       (shell-mode)))
> |   buffer)
> `----
>
> So what we read here is that shell will try to evaluate (with your
> shell) the file ~/.emacs_bash or ~/.emacs.d/init_bash.sh
>
> So just drop in either file
>   alias ls='ls --color'
>
> followed by a blank line (thx comint) and it should work
> automagically.
>
> By the way, have you tried eshell ? In most cases, it just works.
>
> --
>  Paul
>



-- 
It is hard to want something you cannot describe.




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

* Re: Emacs Shell Ansi Colors
  2008-09-29 14:22         ` Richard Riley
@ 2008-09-29 14:57           ` Paul R
  0 siblings, 0 replies; 14+ messages in thread
From: Paul R @ 2008-09-29 14:57 UTC (permalink / raw
  To: Richard Riley; +Cc: help-gnu-emacs

On Mon, 29 Sep 2008 16:22:57 +0200, Richard Riley <rileyrgdev@gmail.com> said:
Richard> I am not sure .bashrc is sourced when you start "shell". It
Richard> doesnt seem to be here on my debian system. I think you need
Richard> a .emacs_bash. Which is different from a few years ago. Maybe
Richard> someone more knowledgeable can comment.

It is sourced here on my box with default settings, but as written
above, your alias statement it probably bypassed because of dumb
terminal.

-- 
  Paul




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

* Re: Emacs Shell Ansi Colors
  2008-09-29 13:32           ` Andreas Politz
@ 2008-09-29 16:08             ` Peter Dyballa
  0 siblings, 0 replies; 14+ messages in thread
From: Peter Dyballa @ 2008-09-29 16:08 UTC (permalink / raw
  To: Andreas Politz; +Cc: help-gnu-emacs


Am 29.09.2008 um 15:32 schrieb Andreas Politz:

> Leave your .emacs as it is and create a file '~/.emacs_bash', insert
> the following lines, save and you should have colors.
>
> PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033 
> [00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
> eval "`dircolors -b`"
> alias ls='ls --color=auto'

This is only bash code – don't you think you need to prepare GNU  
Emacs to *execute* the ANSI codes GNU ls will be emitting? This is  
true for my GNU Emacs 22.3. Your example of a shell prompt can cause  
problems in *shell* buffer – such a prompt is not easy to find, which  
means that older commands also are not easy to find or recognised.  
You can customise instead the variable comint-highlight-prompt.

There are also other versions of ls around that for example make  
colourisation depending on terminal capabilities. Anyway, it's good  
to know that a file ~/.emacs_<shell interpreter> exists that can be  
used to setup *shell* buffer, for example switch off what's working  
in xterm or such. Or switch on.

--
Mit friedvollen Grüßen

   Pete                           <]
              o        __o         |__    o       HPV, the real
     ___o    /I       -\<,         |o \  -\),-%     high speed!
___/\ /\___./ \___...O/ O____.....`-O-'-()--o_________________






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

end of thread, other threads:[~2008-09-29 16:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-28 19:27 Emacs Shell Ansi Colors Lorenzo Isella
2008-09-28 21:19 ` Thierry Volpiatto
     [not found]   ` <F725F550-369F-4C9A-BACA-D13E30D70FC2@Web.DE>
2008-09-29 10:48     ` Lorenzo Isella
2008-09-29 10:59       ` Thierry Volpiatto
2008-09-29 12:37       ` Paul R
2008-09-29 12:45       ` Paul R
2008-09-29 13:02         ` Lorenzo Isella
2008-09-29 13:40           ` Paul R
2008-09-29 14:32             ` Lorenzo Isella
     [not found]         ` <mailman.20145.1222693383.18990.help-gnu-emacs@gnu.org>
2008-09-29 13:32           ` Andreas Politz
2008-09-29 16:08             ` Peter Dyballa
     [not found]       ` <mailman.20143.1222686216.18990.help-gnu-emacs@gnu.org>
2008-09-29 14:14         ` Richard Riley
     [not found]       ` <mailman.20146.1222694164.18990.help-gnu-emacs@gnu.org>
2008-09-29 14:22         ` Richard Riley
2008-09-29 14:57           ` Paul R

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.