I have played with a lot of code in a repl console, how can I clear it? I would like a fresh one without restarting it. Can that be done?
If you want to clear the current namespace of all temporary variables and functions you declared you can use this one liner (or make a function of it) :
(map #(ns-unmap *ns* %) (keys (ns-interns *ns*)))
or
(ns myutil)
(defn ns-clean
"Remove all internal mappings from a given name space or the current one if no parameter given."
([] (ns-clean *ns*))
([ns] (map #(ns-unmap ns %) (keys (ns-interns ns)))))
(ns mytest)
... make loads of junk ...
(myutil/ns-clean)
... great!!! I can now make all new junk ...
It does not claim to give you a squeaky clean namespace, just one with less of the junk which usually accumulates in a typical repl session.
Use with caution : do not pull the rug from under your feet!
If you are running the repl through a terminal window (eg: Terminal.app on MacOS or xterm/aterm/urxvt etc on linux) then you can type Control-L and it should clear the terminal window and give you a new repl prompt. However all macros/atoms you previously defined are still going to be in memory, so this is just a "Cosmetic" clear.
In EMACS/slime REPLs
C-c C-o clears the last output (in case you've typed something that gave a very long answer)
C-c M-o clears the whole thing
In GNOME terminals, you've got a menu option Terminal/Reset and Clear
The shorcut to clean the whole buffer : C-u C-c C-o
The shortcut to clean the last output : C-c C-o
Note, the old way was : C-c M-o
Also, cider-repl-clear-buffer (which is bound to C-ENTER s-c on my machine)
If you are using Emacs + nREPL, you can either:
Run Mx nrepl-clear-buffer or
Run Cc Mo
If the key binding is not enabled, run Mxnrepl-interaction-mode to enable it. You can find other useful shortcuts in nrepl.el and/or customize the key bindings to fit your needs.
Note: you can find all nREPL's key bindings in your system by running M-x v nrepl-mode-map and following the nrepl.el link.
I use the Emacs command cider-repl-clear-buffer via M-x. One might also use cider-repl-clear-output with a prefix argument: C-u C-c C-o.
It depends what you mean by 'clean'. To remove all namespaces within a 'package' you can use:
(mapv remove-ns
(map symbol
(filter #(.startsWith % "org.mycompany")
(map str (all-ns)))))
For users of the Cursive IDE plugin for IntelliJ IDEA who end up here, like me:
You can "cosmetically" clear the REPL (keeping your def'd symbols etc.) by clicking on this icon at the top of the REPL frame:
There's no default key binding for this, but you can easily add one by opening your preferences, navigating to Keymap > Plugins > Cursive, and adding a binding for "Clear output for current REPL".
Alternatively, you can right-click in the editor and access "Clear output for current REPL" via the REPL commands.
Related
PROBLEM:
For some reason when I copy and paste a column property format header in a org-mode file, such as
#+COLUMNS: %25ITEM(Task) %5TODO(To-do) %1PRIORITY %10TAGS
to change the global properties of the trees of the file, it doesn't changes the default format. i.e. first column remains named as ITEM and not task (for this example). I've tried other changes and they are never applied.
TESTS:
I have reloaded the column mode without success.
Tried to add/delete columns with M-S-right/left and it updates the header/columns. But obviously I don't want to have to do it manually.
Here is my .emacs setup for org mode
;; Open ODT files with libre office
(defun my-org-export-to-odt-and-open ()
(interactive)
(org-open-file (org-odt-export-to-odt)))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(setq org-support-shift-select 't)
(setq org-agenda-include-diary t)
(setq org-src-fontify-natively t)
(setq org-src-tab-acts-natively t)
Just for completeness: when in-buffer settings like #+COLUMNS: ... are changed, the change does not take effect until you press C-c C-c on any in-buffer setting (although doing it on the just-changed setting is probably the most natural).
Alternatively, if you save and kill the buffer and visit the file anew, or
if you save the buffer and revert the buffer from the file, the change should take effect (the OP's lack of success with this notwithstanding - I'm not sure why it did not work).
The relevant documentation is In-buffer settings.
I am trying to fine-tune the setup for emacs with emacs prelude included.
I want to have as the default checker cppcheck for flycheck and activate ggtags by default for GNU Global. I am coding mainly c++. It used to work before for ggtags-mode variable but now it seems not to work anymore.
(load "/home/user/.emacs.d/init.el")
(defun my-c-mode-common-hook ()
"Hook for all c derived modes."
(c-add-style "my-style"
'("stroustrup"
(c-offsets-alist
(innamespace . [0])
(inline-open . 0)
(inher-cont . c-lineup-multi-inher)
(arglist-cont-nonempty . +)
(template-args-cont . +))))
(setq c-default-style "my-style")
(when (derived-mode-p 'c-mode 'c++-mode)
(ggtags-mode 1)
(flycheck-select-checker "c/c++-cppcheck"))
)
(add-hook 'c-mode-common-hook
(my-c-mode-common-hook))
I have a warning that says the following functions are not known to be defined: ggtags-mode, flycheck-select-checker. But when loading the .emacs file is loaded, there are no errors.
Can anyone help me with the right way to make these 2 minor modes work correctly configured? For me it seems the right way to do it, but obviously I am missing something.
You use add-hook wrongly: It takes a function as 2nd argument but you call your function there and so pass the value of (flycheck-select-checker ..) as the function. You will likely see an error in a C (C/Java/C++/AWK/...) mode.
What you need to do is (add-hook 'c-mode-common-hook 'my-c-mode-common-hook).
Also this code will never be executed:
(when (derived-mode-p 'c-mode 'c++-mode)
(ggtags-mode 1)
(flycheck-select-checker "c/c++-cppcheck"))
because 'c-mode is not derived of 'c++-mode, I guess you want to check if the current major-mode is derived of c++-mode:
(when (derived-mode-p major-mode 'c++-mode)
(ggtags-mode 1)
(flycheck-select-checker "c/c++-cppcheck"))
I am seeking a plugin to do autocompletion popup for c++ development in emacs. what I have tried are Cedet Semantics and the Autocompletion mode, they are pretty neat in terms of completing the variable and function names as long as I have a few words already. For example, I have a class named foo and a function that returns an integer 1
class foo{
int getInt(){return 1};
};
In the main method, so long as I started typing this
int main(){
foo bar;
bar.get...
}
the plugins have no problem popping up suggestions like bar.getInt(). However, what I am really looking for is something like in Eclipse, as soon as I press the "dot", possible choices could be generated for me. Is that possible in Emacs? Thanks
It depends on your settings of auto-complete & CEDET. It looks like that auto-complete is setup to show possible completions only after several characters will be typed. You can check value of the ac-auto-start variable - if this is a number, then auto-complete will be called after this number of characters.
Another important thing is a what is in your ac-sources variable - for work with CEDET you need to use ac-source-semantic-raw or ac-source-semantic completion source.
To automatic completion after . or -> you can try to use Semantic's built-in completion with something like:
(defun my-c-mode-cedet-hook ()
(local-set-key "." 'semantic-complete-self-insert)
(local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)
P.S. Had you seen my article on CEDET & C++?
I have found that cedet is really underwhelming, especially under cmake projects.
I would recommend using
https://github.com/Andersbakken/rtags
It underlines errors as you type as well as using smart completions. Just add this to your init file after obtaining the required emacs packages
(require 'rtags)
(require 'popup)
(require 'rtags-ac)
(setq rtags-completions-enabled t)
(rtags-enable-standard-keybindings c-mode-base-map)
(add-hook 'c++-mode-hook
(lambda ()
(setq ac-sources '(ac-source-rtags)
)))
I would like to use the semantic code folding from the cedet package (emacs). I installed the 1.1 version and added the following lines to .emacs:
(load-file "~/software/cedet-1.1/common/cedet.el")
(require 'semantic-tag-folding)
(defun c-folding-hook ()
(global-semantic-tag-folding-mode 1)
(local-set-key (kbd "C-c <left>") 'semantic-tag-folding-fold-block)
(local-set-key (kbd "C-c <right>") 'semantic-tag-folding-show-block)
)
(add-hook 'c-mode-common-hook 'c-folding-hook)
Okay, when I now load a c oder c++ file, nothing happens when using the key bindings or directly running the corresponding commands. What's going wrong? Have I forgotten something?
First, you don't need to have (global-semantic-tag-folding-mode 1) inside defun - it's better to run this command once...
But I think, that main problem is that you hadn't enabled any Semantic feature (see this section in my article) - at least you need to call (semantic-load-enable-minimum-features) after loading of CEDET.
P.S. you code is working for me (I use semantic-load-enable-excessive-code-helpers in my setup)
try adding following line in your emacs config file after (load-file "~/software/cedet-1.1/common/cedet.el") line;
(semantic-load-enable-code-helpers) ; Enable prototype help and smart completion
I want to use intelligent tabbing in Emacs in C++ mode, but I also want to be able to insert a tab character when necessary. From other posts, I gather that the easiest way is to bind <Ctrl>-<Tab> to indent. However, it appears that Konsole in KUbuntu won't forward the <Ctrl>?
My current .emacs file contains:
(defun my-c-mode-common-hook ()
(setq c++-tab-always-indent t)
(setq tab-width 4)
(setq indent-tabs-mode t)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(global-set-key [C-tab] 'self-insert-command)
So I believe that this will bind <Ctrl>-<Tab> to inserting a tab character. However, when I run:
<Ctrl>-h k <Ctrl>-<Tab>
Emacs only reports that I pressed the tab key. Is there some option to Konsole (which I have searched through to no avail) or global preferences in KUbuntu that I need to set so that the <Ctrl>- is also forwarded? (It certainly forwards all of the other <Ctrl>-blah commands.)
You can use Control-Q (quote, is what I think of in order to remember this), and then press your Tab key, and you'll insert a tab character. You can use Control-Q to insert any character sequence you need to. Hope this helps. :)
I had to solve the same problem and I found the answer here:
http://www.linux-archive.org/ubuntu-user/189410-equivalent-xterm-vt100-translations-string-gnome-terminal.html
What I did is the followings.
prepare my own konsole key bind customization file
~/.kde/share/apps/konsole/linux-custom.keytab
run konsole by specifying the keytab I customized
% konsole --keytab linux-custom
bind keys in Emacs
My binding in linux-custom.keytab is
key Tab +Control : "\E[4t" # control tab will generate esc [ 4 t
key Backtab : "\E[4s" # shift tab will generate esc [ 4 s
(I don't know any rule for assigning key code so I chose some code which are not yet used.)
In my Emacs customization file called from .emacs I put the following bindings
(define-prefix-command 'terminal-key-map)
(global-set-key (kbd "\e[") 'terminal-key-map)
(define-key terminal-key-map (kbd "4t") 'other-window) ;control tab
(define-key terminal-key-map (kbd "4s") 'other-window) ;shift tab
I also customized other keys such as control ;, control ', control =, etc. in the same way.