Change emacs org-mode key binding for code block












0














In org-mode I use <s then TAB to insert a code block. This action will insert a code block like



 #+BEGIN_SRC
.
.
.
#+END_SRC


but I want to modify this action to insert something like



#+BEGIN_SRC python -n :results output pp replace :exports both
.
.
.
#+END_SRC


I know it's possible to change default behaviour of :result or :exports in emacs init file but I prefer to change this shortcut behaviour, because it makes me able to change the options in line.










share|improve this question





























    0














    In org-mode I use <s then TAB to insert a code block. This action will insert a code block like



     #+BEGIN_SRC
    .
    .
    .
    #+END_SRC


    but I want to modify this action to insert something like



    #+BEGIN_SRC python -n :results output pp replace :exports both
    .
    .
    .
    #+END_SRC


    I know it's possible to change default behaviour of :result or :exports in emacs init file but I prefer to change this shortcut behaviour, because it makes me able to change the options in line.










    share|improve this question



























      0












      0








      0







      In org-mode I use <s then TAB to insert a code block. This action will insert a code block like



       #+BEGIN_SRC
      .
      .
      .
      #+END_SRC


      but I want to modify this action to insert something like



      #+BEGIN_SRC python -n :results output pp replace :exports both
      .
      .
      .
      #+END_SRC


      I know it's possible to change default behaviour of :result or :exports in emacs init file but I prefer to change this shortcut behaviour, because it makes me able to change the options in line.










      share|improve this question















      In org-mode I use <s then TAB to insert a code block. This action will insert a code block like



       #+BEGIN_SRC
      .
      .
      .
      #+END_SRC


      but I want to modify this action to insert something like



      #+BEGIN_SRC python -n :results output pp replace :exports both
      .
      .
      .
      #+END_SRC


      I know it's possible to change default behaviour of :result or :exports in emacs init file but I prefer to change this shortcut behaviour, because it makes me able to change the options in line.







      emacs org-mode






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 14:46









      legoscia

      28.5k1179110




      28.5k1179110










      asked Nov 21 '18 at 13:39









      shae128shae128

      215




      215
























          3 Answers
          3






          active

          oldest

          votes


















          2














          Answering my own question based on legoscia's answer.



          As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. Using M-x customize-option and applying changes will add all easy templates to your init file, if you don't like it you can add just one line to your init file to change a template or add one.



          In my case I added this line to my emacs init file to add <p then TAB :



          (add-to-list 'org-structure-template-alist '("p" "#+BEGIN_SRC python -n :results output pp replace :exports bothn?n#+END_SRC"))


          ALL CREDITS GOES TO legoscia






          share|improve this answer





























            0














            As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. (Use M-x customize-option.)



            For <s, the default expansion is "#+BEGIN_SRC ?nn#+END_SRC". You can just edit it to include the options you want after BEGIN_SRC. Alternatively, you could add a new template, e.g. <p, that expands to the text you want.






            share|improve this answer





















            • Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
              – shae128
              Nov 21 '18 at 17:52



















            0














            just a complement of information.



            you are not obliged to define this in your global init file.



            you can set default options for any org mode file adding this line (to adapt to your case):



            #+PROPERTY: header-args:python :session *mysession* :eval no-export :results raw drawer


            at the beginning of your org file.



            In your org mode document



            #+BEGIN_SRC python :eval never :tangle yes
            ...
            #+END_SRC


            will use default option values unless there are overwritten (:eval example here)





            Note: if you modify your line



            #+PROPERTY: ...


            during editing your org mode file, do not forget to C-c C-c to update config.





            Extra info: https://org-babel.readthedocs.io/en/latest/header-args/






            share|improve this answer





















              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%2f53413338%2fchange-emacs-org-mode-key-binding-for-code-block%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              Answering my own question based on legoscia's answer.



              As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. Using M-x customize-option and applying changes will add all easy templates to your init file, if you don't like it you can add just one line to your init file to change a template or add one.



              In my case I added this line to my emacs init file to add <p then TAB :



              (add-to-list 'org-structure-template-alist '("p" "#+BEGIN_SRC python -n :results output pp replace :exports bothn?n#+END_SRC"))


              ALL CREDITS GOES TO legoscia






              share|improve this answer


























                2














                Answering my own question based on legoscia's answer.



                As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. Using M-x customize-option and applying changes will add all easy templates to your init file, if you don't like it you can add just one line to your init file to change a template or add one.



                In my case I added this line to my emacs init file to add <p then TAB :



                (add-to-list 'org-structure-template-alist '("p" "#+BEGIN_SRC python -n :results output pp replace :exports bothn?n#+END_SRC"))


                ALL CREDITS GOES TO legoscia






                share|improve this answer
























                  2












                  2








                  2






                  Answering my own question based on legoscia's answer.



                  As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. Using M-x customize-option and applying changes will add all easy templates to your init file, if you don't like it you can add just one line to your init file to change a template or add one.



                  In my case I added this line to my emacs init file to add <p then TAB :



                  (add-to-list 'org-structure-template-alist '("p" "#+BEGIN_SRC python -n :results output pp replace :exports bothn?n#+END_SRC"))


                  ALL CREDITS GOES TO legoscia






                  share|improve this answer












                  Answering my own question based on legoscia's answer.



                  As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. Using M-x customize-option and applying changes will add all easy templates to your init file, if you don't like it you can add just one line to your init file to change a template or add one.



                  In my case I added this line to my emacs init file to add <p then TAB :



                  (add-to-list 'org-structure-template-alist '("p" "#+BEGIN_SRC python -n :results output pp replace :exports bothn?n#+END_SRC"))


                  ALL CREDITS GOES TO legoscia







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 18:07









                  shae128shae128

                  215




                  215

























                      0














                      As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. (Use M-x customize-option.)



                      For <s, the default expansion is "#+BEGIN_SRC ?nn#+END_SRC". You can just edit it to include the options you want after BEGIN_SRC. Alternatively, you could add a new template, e.g. <p, that expands to the text you want.






                      share|improve this answer





















                      • Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
                        – shae128
                        Nov 21 '18 at 17:52
















                      0














                      As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. (Use M-x customize-option.)



                      For <s, the default expansion is "#+BEGIN_SRC ?nn#+END_SRC". You can just edit it to include the options you want after BEGIN_SRC. Alternatively, you could add a new template, e.g. <p, that expands to the text you want.






                      share|improve this answer





















                      • Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
                        – shae128
                        Nov 21 '18 at 17:52














                      0












                      0








                      0






                      As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. (Use M-x customize-option.)



                      For <s, the default expansion is "#+BEGIN_SRC ?nn#+END_SRC". You can just edit it to include the options you want after BEGIN_SRC. Alternatively, you could add a new template, e.g. <p, that expands to the text you want.






                      share|improve this answer












                      As mentioned in the Easy Templates section of the org-mode manual, you can modify these templates by customizing the variable org-structure-template-alist. (Use M-x customize-option.)



                      For <s, the default expansion is "#+BEGIN_SRC ?nn#+END_SRC". You can just edit it to include the options you want after BEGIN_SRC. Alternatively, you could add a new template, e.g. <p, that expands to the text you want.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 21 '18 at 14:44









                      legoscialegoscia

                      28.5k1179110




                      28.5k1179110












                      • Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
                        – shae128
                        Nov 21 '18 at 17:52


















                      • Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
                        – shae128
                        Nov 21 '18 at 17:52
















                      Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
                      – shae128
                      Nov 21 '18 at 17:52




                      Thank you, your answer solved my problem, but as it adds all easy template's config to init file I will add another answer based on your answer which will keep init file more readable by adding just one line for new or edited easy template. ALL CREDITS GOES TO @legoscia
                      – shae128
                      Nov 21 '18 at 17:52











                      0














                      just a complement of information.



                      you are not obliged to define this in your global init file.



                      you can set default options for any org mode file adding this line (to adapt to your case):



                      #+PROPERTY: header-args:python :session *mysession* :eval no-export :results raw drawer


                      at the beginning of your org file.



                      In your org mode document



                      #+BEGIN_SRC python :eval never :tangle yes
                      ...
                      #+END_SRC


                      will use default option values unless there are overwritten (:eval example here)





                      Note: if you modify your line



                      #+PROPERTY: ...


                      during editing your org mode file, do not forget to C-c C-c to update config.





                      Extra info: https://org-babel.readthedocs.io/en/latest/header-args/






                      share|improve this answer


























                        0














                        just a complement of information.



                        you are not obliged to define this in your global init file.



                        you can set default options for any org mode file adding this line (to adapt to your case):



                        #+PROPERTY: header-args:python :session *mysession* :eval no-export :results raw drawer


                        at the beginning of your org file.



                        In your org mode document



                        #+BEGIN_SRC python :eval never :tangle yes
                        ...
                        #+END_SRC


                        will use default option values unless there are overwritten (:eval example here)





                        Note: if you modify your line



                        #+PROPERTY: ...


                        during editing your org mode file, do not forget to C-c C-c to update config.





                        Extra info: https://org-babel.readthedocs.io/en/latest/header-args/






                        share|improve this answer
























                          0












                          0








                          0






                          just a complement of information.



                          you are not obliged to define this in your global init file.



                          you can set default options for any org mode file adding this line (to adapt to your case):



                          #+PROPERTY: header-args:python :session *mysession* :eval no-export :results raw drawer


                          at the beginning of your org file.



                          In your org mode document



                          #+BEGIN_SRC python :eval never :tangle yes
                          ...
                          #+END_SRC


                          will use default option values unless there are overwritten (:eval example here)





                          Note: if you modify your line



                          #+PROPERTY: ...


                          during editing your org mode file, do not forget to C-c C-c to update config.





                          Extra info: https://org-babel.readthedocs.io/en/latest/header-args/






                          share|improve this answer












                          just a complement of information.



                          you are not obliged to define this in your global init file.



                          you can set default options for any org mode file adding this line (to adapt to your case):



                          #+PROPERTY: header-args:python :session *mysession* :eval no-export :results raw drawer


                          at the beginning of your org file.



                          In your org mode document



                          #+BEGIN_SRC python :eval never :tangle yes
                          ...
                          #+END_SRC


                          will use default option values unless there are overwritten (:eval example here)





                          Note: if you modify your line



                          #+PROPERTY: ...


                          during editing your org mode file, do not forget to C-c C-c to update config.





                          Extra info: https://org-babel.readthedocs.io/en/latest/header-args/







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 22 '18 at 7:59









                          Picaud VincentPicaud Vincent

                          3,5991832




                          3,5991832






























                              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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2f53413338%2fchange-emacs-org-mode-key-binding-for-code-block%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

                              Tonle Sap (See)

                              I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                              Guatemaltekische Davis-Cup-Mannschaft