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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:37:42+00:00 2026-06-01T19:37:42+00:00

I currently have the following: (defun my-hide-code () (interactive) (set-selective-display 2)) (defvar my-keys-minor-mode-map (make-keymap)

  • 0

I currently have the following:

(defun my-hide-code ()                                                                                                                         
  (interactive)                                                                                                                                
  (set-selective-display 2))                                                                                                                   

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")                                                                     
(define-key my-keys-minor-mode-map (kbd "<f2>") 'my-hide-code)                                                                                 
(define-minor-mode my-keys-minor-mode                                                                                                          
  "use"                                                                                                                                        
  t " my-keys" 'my-keys-minor-mode-map)                                                                                                        
(my-keys-minor-mode 1)    

Now, I want to toggle between
(set-selective-display 2)
and
(set-selective-display ‘nil)

Now, if I was in scheme, I would just create a s closure, and the closure would store a state variable, which would allow me to know which state I was in, and how to toggle.

However, Elisp is apparently a lisp-2 where variables and functions have different scope. Given this, how do I create closures / have be a toggle key?

  • 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-01T19:37:44+00:00Added an answer on June 1, 2026 at 7:37 pm

    selective-display itself is the variable that contains the state you need to check, so you can write

    (defun my-toggle-selective-display ()
      (interactive)
      (if selective-display
          (set-selective-display nil)
        (set-selective-display 2)))
    

    As for closures in general, I had need of them for a project long ago and resorted to inserting uninterned symbols into a function definition using backquote substitution to avoid global variables. E.g.

    (fset 'toggler
          (let ((toggle-var (make-symbol "toggle")))
            (set toggle-var nil)
            `(lambda () (interactive)
               (cond (,toggle-var
                      (setq ,toggle-var nil))
                     (t
                      (setq ,toggle-var t)))
               (message "toggle is %s" ,toggle-var))))
    

    which when run produces

    M-x toggler
    toggle is t
    M-x toggler
    toggle is nil
    M-x toggler
    toggle is t
    M-: (boundp 'toggle)
    nil
    

    I guess this qualifies as a kludge, but I know of no other way to get anything like a closure in Emacs-Lisp.

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

Sidebar

Related Questions

I currently have the following js code function clearMulti(option) { var i; var select
Currently I have the following code creating my timer: <script type=text/javascript> var interval; var
I currently have the following code in an NSOperation that has an observer for
I currently have the following code $TimelineEvents[$i][Date] = date(F j, Y, strtotime($Date)); Which works
Currently I have the following code for a project that represents some probability trees
I currently have the following code that retrieves data from the database and then
I currently have the following array set up: var TicketInfo = { t1: {
I currently have the following table: Checkbox (ID) | Training Course Code | Training
I currently have the following code that loads a UIWebView from another View. Now
I currently have the following PHP code to control the visibility of a block:

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.