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

The Archive Base Latest Questions

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

EMACS 24.1. I need to Rebind Ctrl-space to a custom function that: go to

  • 0

EMACS 24.1.
I need to Rebind Ctrl-space to a custom function that:

  • go to end of line
  • delete trailing spaces if any
  • set the Mark (as normal Ctrl-space)

This is my code not working:

(define-key global-map [?\C- ] 'my-set-mark-command)
(defun my-set-mark-command()
   (interactive)
   (end-of-line)
   (delete-char (* -1 (skip-chars-backward "\t\s")));;delete trailing spaces
   (set-mark-command nil))

When no trailing spaces it works normally: start to select and highlight the region.
When trailing spaces: it deletes trailing spaces, stop at end of line, set Mark but don’t highlight the region.

If I remove the last command (set-mark-command) and I run it manually M-xset-mark-command it works.
Please can somebody help me to make this function works properly??

  • 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-05T18:53:09+00:00Added an answer on June 5, 2026 at 6:53 pm

    Modification commands cause the variable deactivate-mark to be reset, causing the mark to be lost. In the documentation for save-excursion it says how to disable that behavior, by binding the deactivate-mark variable with let. You can then change the code to:

    (defun my-set-mark-command ()
       (interactive)
       (end-of-line)
       (let (deactivate-mark)
         (delete-char (* -1 (skip-chars-backward "\t\s"))))  ;;delete trailing spaces
       (set-mark-command nil))
    

    or even include the whole let inside a save-excursion.

    See manual:

    http://www.gnu.org/software/emacs/manual/html_node/elisp/The-Mark.html#index-deactivate_002dmark-2801

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

Sidebar

Related Questions

I need an emacs built-in function or elisp function that can take me to
I have a line in my .emacs which set a default font: (set-default-font Monaco-10)
Emacs's auto-fill mode splits the line to make the document look nice. I need
The Emacs function sgml-tag is just what I need for my DocBook editing. However,
I need to get selection as a string in my Emacs Lisp function.
For F# mode in emacs, one need the following line in .emacs. The problem
I am making the jump to EMACS, and I can't find what I need
I am using xcode with emacs. But everytime I start emacs, I need to
Currently, in order to evaluate elist in Emacs, I need to position the cursor
Emacs 23.1.1 Ediff 2.81.2 on CentOs 6 Prior to any customization, Ediff would, by

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.