C About Emacs

You might want to look into what Spacemacs provides. It contains a huge amount of great software and you can configure it relatively easily, no matter if you use evil mode or not.
 
The default install of emacs includes a decent c/c++ mode, plus a bunch of other modes by default like javascript/js, java, etc.
Only thing I've added beyond default install is yaml-mode.el
Tags: etags/ctags
 
You might want to look into what Spacemacs provides. It contains a huge amount of great software and you can configure it relatively easily, no matter if you use evil mode or not.
Thank you for the post. But i think Spacemacs is too heavy. My code is mainly focus on c/c++, and a bit of shell code.....
 
The default install of emacs includes a decent c/c++ mode, plus a bunch of other modes by default like javascript/js, java, etc.
Only thing I've added beyond default install is yaml-mode.el
Tags: etags/ctags
Thanks for your reply. I think etags/ctags can not find the reference calls of functions. And how do you solve this? grep or rip-grep?
 
Honestly it's been a while since I've used tags, my simple preference to using grep in a separate window. Tags suffer the same problem as IDEs; you need to regenerate the files.
 
Could emacs gurus tell me if I can set up Ctl-Ins and Sh-ins for copy and paste in Emacs?

I just noticed that you can turn on CUA for copy and paste, but I never use Ctl-c /Ctl-v. That is just as alien as Alt-w / Ctl-y to me.

Is it possible to redefine CUA somewhere within emacs?
 
not sure what the exact key binding or function would be but probably look at "keybinding". I have the following in my emacs init file to bind ctrl-c ctrl-c to comment-region:

(global-set-key (kbd "C-c C-c") 'comment-region)
 
Found this in my init.el - hope this is of use to you?

Code:
(load-file "/usr/src/tools/tools/editing/freebsd.el")
(defun my-c-mode-hook ()
    (c-set-style "bsd")
    (c-set-offset 'substatement-open '0) ; brackets should be at same indentation level as the statements they open
    (c-set-offset 'inline-open '+)
    (c-set-offset 'block-open '+)
    (c-set-offset 'brace-list-open '+)   ; all "opens" should be indented by the c-indent-level
    (c-set-offset 'case-label '-))       ; indent case labels by c-indent-level, too
(add-hook 'c-mode-hook 'my-c-mode-hook)
; turn on semantic
(semantic-mode 1)
; toggle tag decoration?
(global-semantic-decoration-mode 1)
;; enable auto complete
 
Found this in my init.el - hope this is of use to you?

Code:
(load-file "/usr/src/tools/tools/editing/freebsd.el")
(defun my-c-mode-hook ()
    (c-set-style "bsd")
    (c-set-offset 'substatement-open '0) ; brackets should be at same indentation level as the statements they open
    (c-set-offset 'inline-open '+)
    (c-set-offset 'block-open '+)
    (c-set-offset 'brace-list-open '+)   ; all "opens" should be indented by the c-indent-level
    (c-set-offset 'case-label '-))       ; indent case labels by c-indent-level, too
(add-hook 'c-mode-hook 'my-c-mode-hook)
; turn on semantic
(semantic-mode 1)
; toggle tag decoration?
(global-semantic-decoration-mode 1)
;; enable auto complete
I'm very much an emacs novice, but will try and include this. I prefer running emacs -nw and am slowly trying to configure things.

It would be nice to understand all this... Just wish I'd started using emacs 20 years ago as there's a lot to learn.
 
I'm very much an emacs novice, but will try and include this. I prefer running emacs -nw and am slowly trying to configure things.

It would be nice to understand all this... Just wish I'd started using emacs 20 years ago as there's a lot to learn.
Emacs. I've always thought of it as "the first IDE".
The basic use is straight forward (learn the keystrokes to do things), but customize and you are off. The init.el from cmoerz is basically customizing the format of "C/C++ mode" (indentation level, braces, etc) to fit either a $work format or "I like the way this looks".

I would separate my thoughts on "how should the code look" vs "what keybindings to what function". That way you can develop you keybindings separately from "the code looks". So just step back and think "what" and break it down to smaller bits. I've worked with people that spend the whole day inside of emacs (emacs as an OS): email, build, debug, shell commands, etc. More than just editor
 
Being one of those weak-minded IDE users, I gots to have my tree view on the left. I'm decidedly a junior Emacs user, but FWIW, I find this framework intriguing:

Yes, probably way too heavy-weight for you, but the name is pretty cool too.
 
Could emacs gurus tell me if I can set up Ctl-Ins and Sh-ins for copy and paste in Emacs?

Hi, these should already be set up. They are for me. Try running the following to see what the keystrokes are bound to:

Ctrl-h k C-<Ins>
Ctrl-h k S-<Ins>

Or simply select some text and hit C-<Ins> to try and copy it and then S-<Ins> to try and paste it. Works for me.

One caveat is that they may not work like that in all key maps. You can check which keys are bound in a key map in Emacs v28+ by using: M-x describe-keymap

Is it possible to redefine CUA somewhere within emacs?

When you say 'redefine', do you mean turn it off? Or rebind the keys to something else? Turning it off is as simple as adding (cua-mode -1) to your emacs init file and restarting emacs. If you want to redefine it some other way you'll have to be more specific.
 
When you say 'redefine', do you mean turn it off? Or rebind the keys to something else? Turning it off is as simple as adding (cua-mode -1) to your emacs init file and restarting emacs. If you want to redefine it some other way you'll have to be more specific.

I'm not really certain how copy/paste are defined under CUA, but have been using Ctrl-Insert Sh-Insert for copy/paste for decades and it almost always works. It looks like is an IBM definition

https://en.wikipedia.org/wiki/IBM_Common_User_Access

  • The Cut command is ⇧ Shift+Del; Copy is Ctrl+Ins; Paste is ⇧ Shift+Ins;

and maybe a Microsoft definition which defines things differently. I got use to the IBM way many years ago.
 
It would be nice to understand all this... Just wish I'd started using emacs 20 years ago as there's a lot to learn.
The best way to learn emacs (in my opinion) is not to start with any of the starter kits (doom, spacemacs etc) but with a vanilla set up. And then start using it and doing everything in it that you would do in your usual editor. This forces you to confront fixing your pain points as you come across them and forces you to learn how to navigate the documentation, how to pick up small bits of emacs lisp and how to tweak your init file to suit your needs. If you can version control your init file using git then so much the better as this will simplify any mistakes you make. Then it's just a simple git restore to return to a working config. It also gives you the confidence to try things out knowing that you can always get back to something that will work. I would also suggest trying to pick up some emacs lisp to make tweaking your config less daunting. And if you can use emacs at work so that you're using it 8 hours a day rather than trying to pick it up in your spare time then this will also pay dividends as it increases your exposure, making things second nature. There are lots of emacs tutorials and blogs on the net, but I found Mike Zamansky's videos really helpful. Each video is only about 10 minutes long, but he walks through setting up various packages and modes in an easy-going manner showing you what's possible and where to find help etc. Highly recommended.

However, one thing you should know now, is that no matter how long you try and learn emacs you never 'arrive', so just sit back, relax and enjoy the journey because it never ends! 🙂
 
I'm not really certain how copy/paste are defined under CUA
I don't use CUA mode, but according to the EmacsWiki:

Cua-mode allows one to use ‘C-v’, ‘C-c’, and ‘C-x’ to paste, copy, and cut the region.

As far as I understand it, CUA mode in emacs sets up key bindings that are compatible with the Common User Access (CUA) system used in many other applications like Windows etc
 
The best way to learn emacs (in my opinion) is not to start with any of the starter kits (doom, spacemacs etc) but with a vanilla set up. And then start using it and doing everything in it that you would do in your usual editor. This forces you to confront fixing your pain points as you come across them and forces you to learn how to navigate the documentation, how to pick up small bits of emacs lisp and how to tweak your init file to suit your needs. If you can version control your init file using git then so much the better as this will simplify any mistakes you make. Then it's just a simple git restore to return to a working config. It also gives you the confidence to try things out knowing that you can always get back to something that will work. I would also suggest trying to pick up some emacs lisp to make tweaking your config less daunting. And if you can use emacs at work so that you're using it 8 hours a day rather than trying to pick it up in your spare time then this will also pay dividends as it increases your exposure, making things second nature. There are lots of emacs tutorials and blogs on the net, but I found Mike Zamansky's videos really helpful. Each video is only about 10 minutes long, but he walks through setting up various packages and modes in an easy-going manner showing you what's possible and where to find help etc. Highly recommended.

However, one thing you should know now, is that no matter how long you try and learn emacs you never 'arrive', so just sit back, relax and enjoy the journey because it never ends! 🙂

I think I will need to start with my own init.el written from scratch. I searched around for various packages to provide a colour scheme I liked, because I can hardly read the screen with the default theme, but the package I chose was so complicated I could figure out how anything actually works.

The first thing I think I need to do is load a color-theme. I found some in /usr/local/share/emacs/28.2/etc/themes, but can't work out if emacs will try to load them from there or whether you need to copy them or provide a path.
 
I'm following a GNU guide for choosing colour themes


It's very frustrating because nothing works the way it is explained. Perhaps that's because we have a FreeBSD build of the program with bits missing.

According to the guide:

Put the file color-theme.el and the folder themes (with the files color-theme-example.el and color-theme-library.el) in a directory on your LoadPath. The main function to use is ‘color-theme-select’. It creates the Color Theme Selection buffer that allows you to test the themes before choosing one.

M-x load-library RET color-theme RET
M-x color-theme-select RET

When I do this I get

Cannot open load file: No such file or directory: color-theme.

Maybe I haven't copied it from /usr/local/share/emacs/

There are various themes in /usr/local/share/emacs/28.8/etc/themes/ some of which I've copied to ~/.emacs.d/ but am unable to load them.
 
The page that you're referring to states 'The library has not really been well maintained since 2009'. Things have probably moved on since then. Don't let a possibly out-of-date library sidetrack you. The easiest way to display a selectable list of custom themes is to use M-x customize-themes. And then just select a theme to try. You can always go back to libraries like that when you have more experience and understand a bit more how Emacs works.
 
Hopefully some emacs wizard might be able to help me with this....

When I'm using midnight commander for traversing a directory tree, I use 'lynx-like motion' for navigation which allows me to go into or come out of a directory using the left and right arrow keys. I would like to be able to do something similar whilst using the dired function in emacs. I can go forward quite easily by selecting a file or directory and pressing enter, but is there a simple way to go back to the file listing? At the moment, I think I need to 'kill-current-buffer'. Is there an alternative?
 
To go back up a directory in dired just navigate to the entry in the current folder with the double ellipses and hit enter:

drwxr-xr-x 23 balanga balanga 1536 20 Aug 07:35 ..

It's basically the dired equivalent to cd ../ at the command-line.
 
To go back up a directory in dired just navigate to the entry in the current folder with the double ellipses and hit enter:

drwxr-xr-x 23 balanga balanga 1536 20 Aug 07:35 ..

It's basically the dired equivalent to cd ../ at the command-line.
I realise how to get to the parent directory, but you end up with a buffer for the directory you just visited which can up with loads of buffers when you are looking around the filesystem. Just wondered if there is a 'tree-mode' when using dired.
 
Apologies, I misunderstood your requirement. Add the following declaration in your emacs initialisation file:
(setq dired-kill-when-opening-new-dired-buffer t)
This will close any previous dired buffer when you open a new one. Note that it only works from emacs 28 and above.
 
Back
Top