How to pass arguments to Elisp function?Emacs lisp “shell-command-on-region”How to make Emacs (without GUI) differentiate between Ctrl+Shift+S and Ctrl+S?How do I make Git use the editor of my choice for commits?writing lisp emacs key binding and cannot specify the <delete> characteremacs — keybind questionsDifferent results when elisp function is run different ways; why?Cannot get to bind Enter to 'newline-and-indent in Emacs !!! Very annoyingHow to rebind TAB and RET in an Emacs minor mode?EMACS rebinding C-spc disable highlight of selected regionHow to bind CTRL-<home> and CTRL-<end> to beginning/end-of-buffer in Emacs?

Why does a simple loop result in ASYNC_NETWORK_IO waits?

Quoting Keynes in a lecture

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Non-trope happy ending?

How do you make your own symbol when Detexify fails?

Can a Canadian Travel to the USA twice, less than 180 days each time?

How should I respond when I lied about my education and the company finds out through background check?

Is there a RAID 0 Equivalent for RAM?

How to cover method return statement in Apex Class?

Yosemite Fire Rings - What to Expect?

What exact color does ozone gas have?

Creepy dinosaur pc game identification

Does Doodling or Improvising on the Piano Have Any Benefits?

Why would a new[] expression ever invoke a destructor?

The IT department bottlenecks progress. How should I handle this?

What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

Why does the Sun have different day lengths, but not the gas giants?

How can I write humor as character trait?

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

Mixing PEX brands

Biological Blimps: Propulsion

Sums of entire surjective functions

Open a doc from terminal, but not by its name



How to pass arguments to Elisp function?


Emacs lisp “shell-command-on-region”How to make Emacs (without GUI) differentiate between Ctrl+Shift+S and Ctrl+S?How do I make Git use the editor of my choice for commits?writing lisp emacs key binding and cannot specify the <delete> characteremacs — keybind questionsDifferent results when elisp function is run different ways; why?Cannot get to bind Enter to 'newline-and-indent in Emacs !!! Very annoyingHow to rebind TAB and RET in an Emacs minor mode?EMACS rebinding C-spc disable highlight of selected regionHow to bind CTRL-<home> and CTRL-<end> to beginning/end-of-buffer in Emacs?













2















I have this keymap to flush empty lines like this:



(global-set-key (kbd "M-T") (lambda () (interactive) (flush-lines "^[[:space:]]*$")))


But this doesn't work over a region. Unrelated lines out of the region are getting merged. But when I select a region and manually try M-x flush-lines RET ^[[:space:]]*$ RET, it works as expected.
What am I doing wrong ?










share|improve this question




























    2















    I have this keymap to flush empty lines like this:



    (global-set-key (kbd "M-T") (lambda () (interactive) (flush-lines "^[[:space:]]*$")))


    But this doesn't work over a region. Unrelated lines out of the region are getting merged. But when I select a region and manually try M-x flush-lines RET ^[[:space:]]*$ RET, it works as expected.
    What am I doing wrong ?










    share|improve this question


























      2












      2








      2








      I have this keymap to flush empty lines like this:



      (global-set-key (kbd "M-T") (lambda () (interactive) (flush-lines "^[[:space:]]*$")))


      But this doesn't work over a region. Unrelated lines out of the region are getting merged. But when I select a region and manually try M-x flush-lines RET ^[[:space:]]*$ RET, it works as expected.
      What am I doing wrong ?










      share|improve this question
















      I have this keymap to flush empty lines like this:



      (global-set-key (kbd "M-T") (lambda () (interactive) (flush-lines "^[[:space:]]*$")))


      But this doesn't work over a region. Unrelated lines out of the region are getting merged. But when I select a region and manually try M-x flush-lines RET ^[[:space:]]*$ RET, it works as expected.
      What am I doing wrong ?







      emacs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 17:40









      Drew

      24.2k55271




      24.2k55271










      asked Mar 7 at 6:36









      maindoormaindoor

      133




      133






















          1 Answer
          1






          active

          oldest

          votes


















          5














          A function can be called interactively or non-interactively (this is in fact a little bit more complex, but that's a good enough approximation). The interactive calling mode is used to bind some function arguments from the current environment, or by interacting with the user. The non-interactive mode is the normal calling mode when you write in Emacs Lisp.



          Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is partly automated by an interactive spec, and partly hardcoded (for the region part). You can ask Emacs whether the current code is executed interactively by calling called-interactively-p, but as the doc say, it is encouraged to have another optional argument that indicates whether the call is interactive.



          The function signature is:



          (flush-lines REGEXP &optional RSTART REND INTERACTIVE)


          RSTART and REND are the starting and ending position of the current region, as integers. They can also be nil. The last parameter indicates whether the call is interactive.



          When you call flush-lines from your anonymous function, you are calling it non-interactively, which means you need to pass arguments explicitly to the functions.



          For this function, you can simply call it as follows:



          (flush-lines "^[[:space:]]*$" nil nil t)


          This makes the function behaves as-if called interactively, in which case the region is computed automatically since the start and end argument are nil.



          In the general case, what you would do is have your own (interactive "r") declaration, and add two parameters to the anonymous function. For example, in the *scratch* buffer, you can evalue this expression:



          (call-interactively
          (lambda (beg end)
          (interactive "r")
          (list beg end)))


          Then, the result is a list of cursor positions, that represents your region.
          In your case you would call (flush-lines "^[[:space:]]*$" beg end), for example.






          share|improve this answer




















          • 1





            FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

            – Drew
            Mar 7 at 17:44












          • interactive "r" was very helpful!

            – maindoor
            Mar 7 at 18:14











          • @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

            – coredump
            Mar 7 at 22:22






          • 1





            Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

            – Drew
            Mar 7 at 23:42











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037495%2fhow-to-pass-arguments-to-elisp-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          A function can be called interactively or non-interactively (this is in fact a little bit more complex, but that's a good enough approximation). The interactive calling mode is used to bind some function arguments from the current environment, or by interacting with the user. The non-interactive mode is the normal calling mode when you write in Emacs Lisp.



          Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is partly automated by an interactive spec, and partly hardcoded (for the region part). You can ask Emacs whether the current code is executed interactively by calling called-interactively-p, but as the doc say, it is encouraged to have another optional argument that indicates whether the call is interactive.



          The function signature is:



          (flush-lines REGEXP &optional RSTART REND INTERACTIVE)


          RSTART and REND are the starting and ending position of the current region, as integers. They can also be nil. The last parameter indicates whether the call is interactive.



          When you call flush-lines from your anonymous function, you are calling it non-interactively, which means you need to pass arguments explicitly to the functions.



          For this function, you can simply call it as follows:



          (flush-lines "^[[:space:]]*$" nil nil t)


          This makes the function behaves as-if called interactively, in which case the region is computed automatically since the start and end argument are nil.



          In the general case, what you would do is have your own (interactive "r") declaration, and add two parameters to the anonymous function. For example, in the *scratch* buffer, you can evalue this expression:



          (call-interactively
          (lambda (beg end)
          (interactive "r")
          (list beg end)))


          Then, the result is a list of cursor positions, that represents your region.
          In your case you would call (flush-lines "^[[:space:]]*$" beg end), for example.






          share|improve this answer




















          • 1





            FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

            – Drew
            Mar 7 at 17:44












          • interactive "r" was very helpful!

            – maindoor
            Mar 7 at 18:14











          • @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

            – coredump
            Mar 7 at 22:22






          • 1





            Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

            – Drew
            Mar 7 at 23:42
















          5














          A function can be called interactively or non-interactively (this is in fact a little bit more complex, but that's a good enough approximation). The interactive calling mode is used to bind some function arguments from the current environment, or by interacting with the user. The non-interactive mode is the normal calling mode when you write in Emacs Lisp.



          Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is partly automated by an interactive spec, and partly hardcoded (for the region part). You can ask Emacs whether the current code is executed interactively by calling called-interactively-p, but as the doc say, it is encouraged to have another optional argument that indicates whether the call is interactive.



          The function signature is:



          (flush-lines REGEXP &optional RSTART REND INTERACTIVE)


          RSTART and REND are the starting and ending position of the current region, as integers. They can also be nil. The last parameter indicates whether the call is interactive.



          When you call flush-lines from your anonymous function, you are calling it non-interactively, which means you need to pass arguments explicitly to the functions.



          For this function, you can simply call it as follows:



          (flush-lines "^[[:space:]]*$" nil nil t)


          This makes the function behaves as-if called interactively, in which case the region is computed automatically since the start and end argument are nil.



          In the general case, what you would do is have your own (interactive "r") declaration, and add two parameters to the anonymous function. For example, in the *scratch* buffer, you can evalue this expression:



          (call-interactively
          (lambda (beg end)
          (interactive "r")
          (list beg end)))


          Then, the result is a list of cursor positions, that represents your region.
          In your case you would call (flush-lines "^[[:space:]]*$" beg end), for example.






          share|improve this answer




















          • 1





            FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

            – Drew
            Mar 7 at 17:44












          • interactive "r" was very helpful!

            – maindoor
            Mar 7 at 18:14











          • @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

            – coredump
            Mar 7 at 22:22






          • 1





            Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

            – Drew
            Mar 7 at 23:42














          5












          5








          5







          A function can be called interactively or non-interactively (this is in fact a little bit more complex, but that's a good enough approximation). The interactive calling mode is used to bind some function arguments from the current environment, or by interacting with the user. The non-interactive mode is the normal calling mode when you write in Emacs Lisp.



          Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is partly automated by an interactive spec, and partly hardcoded (for the region part). You can ask Emacs whether the current code is executed interactively by calling called-interactively-p, but as the doc say, it is encouraged to have another optional argument that indicates whether the call is interactive.



          The function signature is:



          (flush-lines REGEXP &optional RSTART REND INTERACTIVE)


          RSTART and REND are the starting and ending position of the current region, as integers. They can also be nil. The last parameter indicates whether the call is interactive.



          When you call flush-lines from your anonymous function, you are calling it non-interactively, which means you need to pass arguments explicitly to the functions.



          For this function, you can simply call it as follows:



          (flush-lines "^[[:space:]]*$" nil nil t)


          This makes the function behaves as-if called interactively, in which case the region is computed automatically since the start and end argument are nil.



          In the general case, what you would do is have your own (interactive "r") declaration, and add two parameters to the anonymous function. For example, in the *scratch* buffer, you can evalue this expression:



          (call-interactively
          (lambda (beg end)
          (interactive "r")
          (list beg end)))


          Then, the result is a list of cursor positions, that represents your region.
          In your case you would call (flush-lines "^[[:space:]]*$" beg end), for example.






          share|improve this answer















          A function can be called interactively or non-interactively (this is in fact a little bit more complex, but that's a good enough approximation). The interactive calling mode is used to bind some function arguments from the current environment, or by interacting with the user. The non-interactive mode is the normal calling mode when you write in Emacs Lisp.



          Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is partly automated by an interactive spec, and partly hardcoded (for the region part). You can ask Emacs whether the current code is executed interactively by calling called-interactively-p, but as the doc say, it is encouraged to have another optional argument that indicates whether the call is interactive.



          The function signature is:



          (flush-lines REGEXP &optional RSTART REND INTERACTIVE)


          RSTART and REND are the starting and ending position of the current region, as integers. They can also be nil. The last parameter indicates whether the call is interactive.



          When you call flush-lines from your anonymous function, you are calling it non-interactively, which means you need to pass arguments explicitly to the functions.



          For this function, you can simply call it as follows:



          (flush-lines "^[[:space:]]*$" nil nil t)


          This makes the function behaves as-if called interactively, in which case the region is computed automatically since the start and end argument are nil.



          In the general case, what you would do is have your own (interactive "r") declaration, and add two parameters to the anonymous function. For example, in the *scratch* buffer, you can evalue this expression:



          (call-interactively
          (lambda (beg end)
          (interactive "r")
          (list beg end)))


          Then, the result is a list of cursor positions, that represents your region.
          In your case you would call (flush-lines "^[[:space:]]*$" beg end), for example.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 22:23

























          answered Mar 7 at 9:57









          coredumpcoredump

          22k43047




          22k43047







          • 1





            FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

            – Drew
            Mar 7 at 17:44












          • interactive "r" was very helpful!

            – maindoor
            Mar 7 at 18:14











          • @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

            – coredump
            Mar 7 at 22:22






          • 1





            Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

            – Drew
            Mar 7 at 23:42













          • 1





            FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

            – Drew
            Mar 7 at 17:44












          • interactive "r" was very helpful!

            – maindoor
            Mar 7 at 18:14











          • @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

            – coredump
            Mar 7 at 22:22






          • 1





            Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

            – Drew
            Mar 7 at 23:42








          1




          1





          FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

          – Drew
          Mar 7 at 17:44






          FWIW, I don't understand what you're trying to say with this sentence: "Typically, the interactive behaviour is declared using an (interactive ...) form after the docstring, but in the particular case of flush-lines, the behaviour is hard-coded". There's nothing hard-coded about the interactive behavior, AFAICT, and it is declared using an (interactive...) spec.

          – Drew
          Mar 7 at 17:44














          interactive "r" was very helpful!

          – maindoor
          Mar 7 at 18:14





          interactive "r" was very helpful!

          – maindoor
          Mar 7 at 18:14













          @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

          – coredump
          Mar 7 at 22:22





          @Drew I expected the code to be entirely defined by an interacive spec, but then I tried to see how it was implemented and the existing interactive spec has a progn with two expressions (github.com/emacs-mirror/emacs/blob/master/lisp/replace.el#L882); a check and the prompt for the regex. But the part that computes rstart and rend is done in the following if. I probably expressed myself badly, I was focused on the region part when writing that.

          – coredump
          Mar 7 at 22:22




          1




          1





          Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

          – Drew
          Mar 7 at 23:42






          Yes, you're right. It's bad coding, IMHO. The doc string should at least say what nil values for RSTART and REND mean/do. You might want to update your answer to say something more like what you say in your comment. (Comments can be deleted at any time. Questions and answers should suffice for readers to learn.)

          – Drew
          Mar 7 at 23:42




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037495%2fhow-to-pass-arguments-to-elisp-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved