Is there an emacs command to go to end of code line (before line comment and whitespaces start)












5















say you have that:



stuff
indented stuff # commented stuff


We already got move-beginning-of-line and back-to-indentation for the left side. Now, for the right side...



I'd love to know if you are aware of a function that goes at the end of the code line (square position)



stuff
indented stuff□ # commented stuff


should be able to understand the comment symbol depending on mode I guess.










share|improve this question















migrated from superuser.com Mar 1 at 18:24


This question came from our site for computer enthusiasts and power users.























    5















    say you have that:



    stuff
    indented stuff # commented stuff


    We already got move-beginning-of-line and back-to-indentation for the left side. Now, for the right side...



    I'd love to know if you are aware of a function that goes at the end of the code line (square position)



    stuff
    indented stuff□ # commented stuff


    should be able to understand the comment symbol depending on mode I guess.










    share|improve this question















    migrated from superuser.com Mar 1 at 18:24


    This question came from our site for computer enthusiasts and power users.





















      5












      5








      5








      say you have that:



      stuff
      indented stuff # commented stuff


      We already got move-beginning-of-line and back-to-indentation for the left side. Now, for the right side...



      I'd love to know if you are aware of a function that goes at the end of the code line (square position)



      stuff
      indented stuff□ # commented stuff


      should be able to understand the comment symbol depending on mode I guess.










      share|improve this question
















      say you have that:



      stuff
      indented stuff # commented stuff


      We already got move-beginning-of-line and back-to-indentation for the left side. Now, for the right side...



      I'd love to know if you are aware of a function that goes at the end of the code line (square position)



      stuff
      indented stuff□ # commented stuff


      should be able to understand the comment symbol depending on mode I guess.







      comment motion






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 18:14









      Dan

      21.3k549113




      21.3k549113










      asked Mar 1 at 10:04









      v.oddouv.oddou

      1284




      1284




      migrated from superuser.com Mar 1 at 18:24


      This question came from our site for computer enthusiasts and power users.









      migrated from superuser.com Mar 1 at 18:24


      This question came from our site for computer enthusiasts and power users.
























          2 Answers
          2






          active

          oldest

          votes


















          2














          The package mwim offers this functionality. By setting



          (global-set-key (kbd "C-e") 'mwim-end)


          you get behavior similar to what you described. The package also offers the corresponding mwim-beginning command which you can add using



          (global-set-key (kbd "C-a") 'mwim-beginning)


          See the package README for more.






          share|improve this answer

































            5














            Here's a quick command, lightly tested, that does what you're looking for.



            (defun eol-dwim ()
            "Go to the end of the line, ignoring comments and trailing
            whitespace."
            (interactive)
            (let ((bol (line-beginning-position 1))
            (eol (line-end-position 1)))
            (if (condition-case nil
            (comment-search-forward eol)
            (error nil))
            (re-search-backward comment-start bol nil)
            (end-of-line 1))
            (skip-syntax-backward " " bol)))





            share|improve this answer
























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "583"
              };
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2femacs.stackexchange.com%2fquestions%2f48121%2fis-there-an-emacs-command-to-go-to-end-of-code-line-before-line-comment-and-whi%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              The package mwim offers this functionality. By setting



              (global-set-key (kbd "C-e") 'mwim-end)


              you get behavior similar to what you described. The package also offers the corresponding mwim-beginning command which you can add using



              (global-set-key (kbd "C-a") 'mwim-beginning)


              See the package README for more.






              share|improve this answer






























                2














                The package mwim offers this functionality. By setting



                (global-set-key (kbd "C-e") 'mwim-end)


                you get behavior similar to what you described. The package also offers the corresponding mwim-beginning command which you can add using



                (global-set-key (kbd "C-a") 'mwim-beginning)


                See the package README for more.






                share|improve this answer




























                  2












                  2








                  2







                  The package mwim offers this functionality. By setting



                  (global-set-key (kbd "C-e") 'mwim-end)


                  you get behavior similar to what you described. The package also offers the corresponding mwim-beginning command which you can add using



                  (global-set-key (kbd "C-a") 'mwim-beginning)


                  See the package README for more.






                  share|improve this answer















                  The package mwim offers this functionality. By setting



                  (global-set-key (kbd "C-e") 'mwim-end)


                  you get behavior similar to what you described. The package also offers the corresponding mwim-beginning command which you can add using



                  (global-set-key (kbd "C-a") 'mwim-beginning)


                  See the package README for more.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 4 at 16:43

























                  answered Mar 4 at 16:04









                  clemeraclemera

                  1,875623




                  1,875623























                      5














                      Here's a quick command, lightly tested, that does what you're looking for.



                      (defun eol-dwim ()
                      "Go to the end of the line, ignoring comments and trailing
                      whitespace."
                      (interactive)
                      (let ((bol (line-beginning-position 1))
                      (eol (line-end-position 1)))
                      (if (condition-case nil
                      (comment-search-forward eol)
                      (error nil))
                      (re-search-backward comment-start bol nil)
                      (end-of-line 1))
                      (skip-syntax-backward " " bol)))





                      share|improve this answer




























                        5














                        Here's a quick command, lightly tested, that does what you're looking for.



                        (defun eol-dwim ()
                        "Go to the end of the line, ignoring comments and trailing
                        whitespace."
                        (interactive)
                        (let ((bol (line-beginning-position 1))
                        (eol (line-end-position 1)))
                        (if (condition-case nil
                        (comment-search-forward eol)
                        (error nil))
                        (re-search-backward comment-start bol nil)
                        (end-of-line 1))
                        (skip-syntax-backward " " bol)))





                        share|improve this answer


























                          5












                          5








                          5







                          Here's a quick command, lightly tested, that does what you're looking for.



                          (defun eol-dwim ()
                          "Go to the end of the line, ignoring comments and trailing
                          whitespace."
                          (interactive)
                          (let ((bol (line-beginning-position 1))
                          (eol (line-end-position 1)))
                          (if (condition-case nil
                          (comment-search-forward eol)
                          (error nil))
                          (re-search-backward comment-start bol nil)
                          (end-of-line 1))
                          (skip-syntax-backward " " bol)))





                          share|improve this answer













                          Here's a quick command, lightly tested, that does what you're looking for.



                          (defun eol-dwim ()
                          "Go to the end of the line, ignoring comments and trailing
                          whitespace."
                          (interactive)
                          (let ((bol (line-beginning-position 1))
                          (eol (line-end-position 1)))
                          (if (condition-case nil
                          (comment-search-forward eol)
                          (error nil))
                          (re-search-backward comment-start bol nil)
                          (end-of-line 1))
                          (skip-syntax-backward " " bol)))






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 2 at 1:08









                          DanDan

                          21.3k549113




                          21.3k549113






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Emacs Stack Exchange!


                              • 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%2femacs.stackexchange.com%2fquestions%2f48121%2fis-there-an-emacs-command-to-go-to-end-of-code-line-before-line-comment-and-whi%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

                              How do I know what Microsoft account the skydrive app is syncing to?

                              When does type information flow backwards in C++?

                              Grease: Live!