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 8340217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:07:11+00:00 2026-06-09T05:07:11+00:00

I found the function here for replace filen at point but it doesn’t seem

  • 0

I found the function here for replace filen at point but it doesn’t seem to work properly: http://www.emacswiki.org/emacs/InsertFileName. It correctly finds the file-at-point but the replace appears to take the file you input and not the file detected originally from what I can see. I’m not sure how to fix this.

If I Run the function on /home/testfile

First it says file to replace so for example: /home/secondfile
Then it says replace ‘/home/secondfile’ with: /home/secondfile
and then it says: No file at point

Any ideas??

Here is the function:

(autoload 'ffap-guesser "ffap")
(autoload 'ffap-read-file-or-url "ffap")

(defun my-replace-file-at-point (currfile newfile)
"Replace CURRFILE at point with NEWFILE.

  When interactive, CURRFILE will need to be confirmed by user
  and will need to exist on the file system to be recognized,
  unless it is a URL.

  NEWFILE does not need to exist.  However, Emacs's minibuffer
  completion can help if it needs to be.
  " 

(interactive
 (let ((currfile (ffap-read-file-or-url "Replace filename: "
                                        (ffap-guesser))))
   (list currfile
         (ffap-read-file-or-url (format "Replace `%s' with: "
                                        currfile) currfile))))
(save-match-data
  (if (or (looking-at (regexp-quote currfile))
          (let ((filelen (length currfile))
                (opoint (point))
                (limit (+ (point) (length currfile))))
            (save-excursion
              (goto-char (1- filelen))
              (and (search-forward currfile limit
                                   'noerror)
                   (< (match-beginning 0) opoint))
                   (>= (match-end 0) opoint))))
      (replace-match newfile)
    (error "No file at point to replace"))))
  • 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-09T05:07:12+00:00Added an answer on June 9, 2026 at 5:07 am

    There are probably a few things wrong/going on here. The first is, your point position when you are executing this. The second is, if you are using /home/user/something, that there is a strong possibility you will have mismatch between /home/user/something and ~/something (ffap returns the latter while at the point you may have written the former).

    First:

    The use of looking-at with the regexp quoted filename expects the point to be at the beginning: e.g. |/home/user/something.

    Its partner, looking-back expects /home/user/something|. Being somewhere in the middle will throw this error.

    One quick fix for this is changing looking-at to thing-at-point-looking-at.

    Second:

    If you have written /home/user/something, ffap functions (in my case) shorten this using ~.
    There are probably some settings that govern this, but the easiest, quick fix I know of is using expand-file-name. This will take care of the first case, and if it is written as ~/something, the save-excursion body will replace it in the alternate case.

    The only negative result I see is that, you might sometimes replace:

    /home/user/something with ~/somethingelse

    But, anyways, these two quick fixes just result in this complete change:

    (thing-at-point-looking-at (regexp-quote (expand-file-name currfile)))

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

Sidebar

Related Questions

I found a php function checkdate() , but strangely enough it only seems to
I am converting an eregi_replace function I found to preg_replace, but the eregi string
I found a function on the web that generates all sub-multisets of a set
recently I found a function like this in a generic JSR245 portlet class: public
Working with an undisclosed API, I found a function that can set the number
I'm reading some third party Verilog, and found this: function [31:0] factorial; input [3:0]
Having a bit of a mental block. I am sure I found a function
How to move custom marker to front on google map? I found moveToTop function
PHP5.1.6 has no json_encode(), so I wanted to use function found on json_encode documentation
I used the following function I found online and it works perfectly. However, when

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.