Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:21:53+00:00 2026-06-07T18:21:53+00:00

I use term-mode to run Bash shells within Emacs. On remote hosts, term-mode ‘s

  • 0

I use term-mode to run Bash shells within Emacs. On remote hosts, term-mode‘s directory tracking feature helpfully sets default-directory to have the host name in it, so that tab completion and file access is done remotely via Tramp. Sometimes, however, I use remote hosts that mostly share the same filesystems as my workstation, as they load the same directories from NFS. In these cases, Tramp slows me down too much. I would like, when using these systems, for Emacs to set the default-directory locally. To do this I have copied term-handle-ansi-terminal-messages from the system term.el to a new file loaded by my .emacs. I replace this part:

((= command-code ?h)
 (setq term-ansi-at-host argument))

with this:

((= command-code ?h)
 (setq term-ansi-at-host-real argument)
 (setq term-ansi-at-host
       ;; if it has an equivalent filesystem group, set to system-name
       (if (term-equivalent-filesystem-host-group-p argument)
           (system-name)
         argument)))

This calls a term-equivalent-filesystem-host-group-p function that tells whether a host should be treated as having an equivalent filesystem.

This method has the desired effect but copying and modifying system Lisp code isn’t robust to any future changes in the code. I don’t think advising the function would be possible without duplicating half its functionality (either the message loop or the setting of default-directory and ange-ftp-… variables).

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:21:55+00:00Added an answer on June 7, 2026 at 6:21 pm

    I think you can get darn close with advice. I’d define advice as follows:

    (defadvice term-handle-ansi-terminal-messages
       (before rewrite-remote-paths-to-local (message) activate)
       (when (and (string-match ".*\eAnSiTh.\\([^\r\n]+\\)\r?\n" message)
                  (term-equivalent-filesystem-host-group-p (match-string 1 message)))
         (setq term-ansi-at-host-real (match-string 1 message))
         (setq message (replace-match (system-name) t t message 1))))
    

    All this does is look for a substring of the input to term-handle-ansi-terminal-messages that’s going to fall into the case in question, and proactively rewrite the path. Now there’s no need to fiddle with the internals of term-handle-ansi-terminal-messages, since it’ll never see the remote path.

    Is this different than modifying the function? I’d say yes, but this is open to interpretation. In particular, I think that the only knowledge the above code depends on is the format of the submessage term-long-function-name-you-already-know is going to look for, which is really an attribute of the terminal protocol, not the internals of term-now-i'm-just-being-silly. There are some potential problems, such as new code that changes behavior based on the 7th character in the match. (This is the lone . in the string-match above.)

    Needless to say, I didn’t test this code at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like to use Emacs' shell mode, but it has a few deficiencies. One
In the context of functional programming which is the correct term to use: persistent
The Term::Size-module jumbles up the encoding. How can I fix this? #!/usr/bin/env perl use
I am starting to use JPA and I always get confused with the term
Use case: I've just entered insert mode, and typed some text. Now I want
use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
I am not sure if CopyMost is the correct term to use here, but
(I use the term asynchronously loosely in the subject) I've been using the below
I am reading EJB 3 in Action and they use the term Component model
I am a self taught developer. I use the term loosely because I only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.