Hot answers tagged

5

If you ever want to add shortcuts functionality where you have control over the exact behavior, it's worth learning a little emacs-lisp. This kind of functionality is trivial to write. (global-set-key (kbd "<f12>") (lambda () (interactive) ;; Keep cursor motion within this block (don't move the users cursor). (save-excursion ...


2

I think you're looking for which-function-mode (which is indeed a standard feature).


2

C-hk( tells us: ( runs the command c-electric-paren (found in c-mode-map), which is an interactive compiled Lisp function in ‘cc-cmds.el’. It is bound to ), (. I suggest: (with-eval-after-load "cc-mode" (define-key c-mode-map (kbd "(") #'self-insert-command) (define-key c-mode-map (kbd ")") #'self-insert-command))


1

You'll end up doing it the same way most programming modes do syntax highlighting: by matching regular expressions against the buffer contents. You'll want to search backwards for the beginning of the function, and then search forwards from there to find the end of it. Using LSP is a nice idea, but the protocol doesn't deal in the actual syntax of the ...


1

While composing this and doing my due diligence, I solved my problem. For some reason, Emacs generated the expression with the name I chose to name the style as the base style, and because I specified the same name for both the base style and the added style name, it got into an infinite recursion loop in c-get-style-variables when it tried to evaluate ...


1

C-c . just sets the formatting style to use when indenting the code, it doesn't actually change the indentation of anything the buffer. You can change the indentation of a region with the indent-region command, bound by default to C-M-\. c-mode also has the c-indent-exp command that indents an expression; this is handy for multi-line expressions near the ...


1

Use the :flags or :libs header to pass flags to the compiler (or libraries to the linker): #+begin_src C :libs -lm #include <stdio.h> #include <math.h> int main(){ printf("Square = %f", pow(4,2)); return 0; } #+end_src See the Working with source code/Languages section of the Org mode manual. That contains a link to a page on Worg with ...


Only top voted, non community-wiki answers of a minimum length are eligible