Naive question on how to type-annotated my ocaml prog. in emacs - emacs

I heard we can annotate ocaml prog. by their types. An older thread in the forum suggested using ocaml mode of
http://cristal.inria.fr/~remy/poly/emacs/index.html
I have been using Tuareg mode, in which it suggested using "c-c c-t" to retrieve types, cf. this piece of codes in tuareg.el
(when tuareg-with-caml-mode-p
;; Trigger caml-types
(define-key map [?\C-c ?\C-t] 'caml-types-show-type)
;; To prevent misbehavior in case of error during exploration.
(define-key map [(control mouse-2)] 'caml-types-mouse-ignore)
(define-key map [(control down-mouse-2)] 'caml-types-explore)
I got "c-c c-t" undefined although everything seems to be well configured.
Here is the .emacs file
(setq auto-mode-alist
(cons '("\\.ml[iyl]?$" . caml-mode) auto-mode-alist))
(autoload 'caml-mode "ocaml"
"Major mode for editing Caml code." t)
(autoload 'camldebug "camldebug"
"Call the camldebugger on FILE" t)
;; adjust paths for emacs source code
(add-to-list 'load-path "~/my-emacs-config/caml-mode")
;; adjust paths for emacs ocaml info sources
(require 'info)
(add-to-list 'Info-directory-list "~/my-emacs-config/caml-mode")
Here is the files in caml-mode (which contains ocaml.el)
bash-3.2$ ls ~/my-emacs-config/caml-mode/
caml-compat.el caml-emacs.el caml-font.el caml-help.el caml-hilit.el caml-types.el caml.el camldebug.el inf-caml.el ocaml.el
I did the following
--write an factorial func. in ocaml, called "annot.ml"
let rec f n =
if n = 1 then 0 else n * f(n-1)
--ocamlc -annot annot.ml
--open annot.ml by emacs and press "c-c c-t" while the cursor is under "n"
I got in the minibuffer of emacs
c-c c-t undefined
Conclusion, I still cannot retrieve types. Why??? Thank you for your ideas.
More info: when I try M-x caml-[tab] I get the following list, which does not contain caml-types-show-types
Possible completions are:
caml-mode camldebug
camldebug-backtrace camldebug-break
camldebug-close camldebug-complete
camldebug-delete camldebug-display-frame
camldebug-down camldebug-finish
camldebug-goto camldebug-kill
camldebug-last camldebug-mode
camldebug-next camldebug-open
camldebug-print camldebug-refresh
camldebug-reverse camldebug-run
camldebug-step camldebug-up

You're autoloading caml-mode from ocaml.el or ocaml.elc. But there is no such file! The official Caml mode is in a file called caml.el, and Tuareg mode is in a file called tuareg.el. This explains why opening your .ml file doesn't put you in Ocaml mode and doesn't load the Caml support. Change your autoload to either this to use the official mode
(autoload 'caml-mode "caml"
"Major mode for editing Caml code." t)
or this to use Tuareg mode
(autoload 'caml-mode "tuareg"
"Major mode for editing Caml code." t)

Related

How to turn a (non-interactive) function into a command (interactive function) in Emacs-LISP?

I want to call the function markdown-back-to-heading, which is native in Markdown mode in Emacs. I understand that interactive turns non-interactive functions interactive, or formally functions into commands:
Special Form: interactive arg-descriptor
This special form declares that a function is a command, and that it may therefore be called interactively (via M-x or by entering a key sequence bound to it).
I tried:
(define-key markdown-mode-map (kbd "C-c C-h") 'markdown-back-to-heading)
This throws an error: Wrong type argument: commandp, markdown-back-to-heading.
So I wrapped it with an interactive function, and it works:
(defun my-markdown-back-to-heading ()
"Wrap function to be called interactively."
(interactive)
(markdown-back-to-heading))
(define-key markdown-mode-map (kbd "C-c C-h") 'my-markdown-back-to-heading)
Is there a better way to turn the native function into an interactive command?
You can alternatively use the interactive-form symbol property.
For details see C-hig (elisp)Using Interactive
Here's a simple example:
;; Enable M-x kill-process (to kill the current buffer's process).
;; (This is not normally a command, but it is useful as one.)
(put 'kill-process 'interactive-form '(interactive))
The more complex version that I actually use is:
(put 'kill-process 'interactive-form
'(interactive
(let ((proc (get-buffer-process (current-buffer))))
(if (process-live-p proc)
(unless (yes-or-no-p (format "Kill %S? " proc))
(error "Process not killed"))
(error (format "Buffer %s has no process" (buffer-name))))
(list proc))))
If want to make markdown-back-to-heading interactive, you have a few different good options:
file a bug report to get upstream to make it so. Including a patch along with the bug-report can help speed up the process.
use an advice such as:
(advice-add 'markdown-back-to-heading :before
(lambda () (interactive "^") nil))
If instead you want to improve the interactivity of a function, e.g. if you want to support shift-selection, you can add the interactive code ^ with (interactive "^") instead of (interactive) so that Emacs knows this is a navigation command (and hence if you use it with a shifted-binding it will select the corresponding text). Here is a manual page with the list of interactive codes, and other options for interactivity at the manual page you mentioned.
Following #Stefan's suggestion, I filed a Github issue and submitted a patch, which adds the line (interactive "P") in the source code:
(defun markdown-back-to-heading (&optional invisible-ok)
"Move to previous heading line, or beg of this line if it's a heading.
Only visible heading lines are considered, unless INVISIBLE-OK is non-nil."
(interactive "P")
(markdown-move-heading-common #'outline-back-to-heading invisible-ok))
and now I can keybind it with
(define-key markdown-mode-map (kbd "C-c C-h") 'markdown-back-to-heading)
I had installed markdown-mode from MELPA, so this change required uninstalling the package, then these steps from the repo README. I forked the repo and cloned the repo locally:
git clone git#github.com:miguelmorin/markdown-mode
and added these lines to Emacs initialization:
(add-to-list 'load-path (expand-file-name "~/code/markdown-mode"))
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(autoload 'gfm-mode "markdown-mode"
"Major mode for editing GitHub Flavored Markdown files" t)
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
(require 'markdown-mode)

How to change GUD breakpoint keybinding to the old one

Currently, I am using GUD in the newest version of Emacs. The keybinding has changed since the old Emacs. Now it is "\C-x \C-a \C-b" for setting a breakpoint but it was \C-[space].
I was wondering if there is anyway to change the keybinding to the old format? (For some reason I cannot change my Emacs version)
I am using Emacs 24.5
Here is my .emacs file:
;; .emacs
;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)
;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))
;; enable visual feedback on selections
;(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs#" (system-name)))
;; default to unified diffs
(setq diff-switches "-u")
;; always end a file with a newline
;(setq require-final-newline 'query)
;; Show main source buffer when using gdb
(setq gdb-show-main t)
;; Show all debugging frames in GDB
(setq gdb-many-windows t)
;; see buffer list on the same frame
(global-set-key "\C-x\C-b" 'buffer-menu)
;; old keybinding for breakoint in GUD
(require 'gud)
(define-key gud-mode-map "\C-x SPC" 'gud-break)
Changing your Emacs version should not be necessary. Try this:
(require 'gud)
(define-key gud-mode-map (kbd "C-SPC") 'gud-break)
This will allow you to trigger gud-break with C-SPC. If you are not talking about the gud-break command, replace it with the command you are referring too.
Generally, the answer to the question "can I change this keybinding?" is always "yes" in Emacs.
Somehow I was able to fix it with this:
(require 'gud)
(global-set-key [24 32] (quote gud-break))

setting up semantic with cscope

I'm starting to experiment a bit with using emacs as my development envrionment and I am running into a bit of trouble. I wish to use cscope with semantic for a fairly robust way of searching through my code base. However, after installing cscope (with apt-get install cscope) and moving xscope.el into my ~/.emacs.d/, I am still having trouble calling some settings with my .emacs file. When I try to call (semanticdb-enable-cscope-databases), I get an error that the symbol's function definition is void. I am using emacs 24.3
(semantic-mode 1)
(global-ede-mode 1)
(require 'semantic/ia)
;; Semantic
(global-semantic-idle-completions-mode t)
(global-semantic-decoration-mode t)
(global-semantic-highlight-func-mode t)
(global-semantic-show-unmatched-syntax-mode t)
;; auto-complete stuff
(add-to-list 'load-path "~/.emacs.d")
(require 'auto-complete-config)
(ac-config-default)
(add-hook 'c-mode-common-hook '(lambda ()
;; ac-omni-completion-sources is made buffer local so
;; you need to add it to a mode hook to activate on
;; whatever buffer you want to use it with. This
;; example uses C mode (as you probably surmised).
;; auto-complete.el expects ac-omni-completion-sources to be
;; a list of cons cells where each cell's car is a regex
;; that describes the syntactical bits you want AutoComplete
;; to be aware of. The cdr of each cell is the source that will
;; supply the completion data. The following tells autocomplete
;; to begin completion when you type in a . or a ->
(add-to-list 'ac-omni-completion-sources
(cons "\\." '(ac-source-semantic)))
(add-to-list 'ac-omni-completion-sources
(cons "->" '(ac-source-semantic)))
;; ac-sources was also made buffer local in new versions of
;; autocomplete. In my case, I want AutoComplete to use
;; semantic and yasnippet (order matters, if reversed snippets
;; will appear before semantic tag completions).
(setq ac-sources '(ac-source-semantic ac-source-yasnippet))
))
(require 'xcscope)
(semanticdb-enable-cscope-databases) ;;This is causing problems
;;C mode
(require 'cc-mode)
;;Color theme
(require 'color-theme)
(setq color-theme-is-global t)
(add-to-list 'load-path "/home/bob/.emacs.d/theme/ample-theme/ample-theme.el")
;;(require 'ample-theme)
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
(color-theme-jsc-dark)))
;;set font
(set-face-attribute 'default nil :family "Anonymous Pro" :height 140)
;;line numbers
(global-linum-mode 1)
(custom-set-variables '(linum-format (quote "%4d \u2502 ")))
;;treat .h files at C++
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
;; use F5 as compile
(global-set-key [(f5)] 'compile)
;; make compilation window smaller
(setq compilation-window-height 8)
Now, I really start writing an answer to be able to refine it with time. That is how far I got until now:
There are several versions of cedet.
Emacs 24.3 includes cedet-2.0. But, with respect to the bazaar version cited below it seems to be slightly outdated.
I believe that in this version cscope is supported as one of the tools in semantic-symref-tool-alist.
The variable semantic-symref-tool-alist is described in the info manual. One gets there with the key strokes C-h i g (semantic-user) Configuring SymRef.
One can see the default value of semantic-symref-tool-alist after loading semantic/symref. One of its members is:
((lambda
(rootdir)
(file-exists-p
(expand-file-name "cscope.out" rootdir)))
. cscope)
I think that this is the cscope support in in the built-in version of cedet-2.0 and no additional enabling of cscope is required (?).
The official release is cedet-1.1 from https://sourceforge.net/projects/cedet/files/cedet/cedet-1.1.tar.gz/download.
In this version the function semanticdb-enable-cscope-databases is defined in the file semantic/semanticdb-cscope.el
The bazar-version of cedet is cedet-2.0. It is available via bazaar under:
bzr checkout bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk cedet
In this version the function semanticdb-enable-cscope-databases is defined in cedet/semantic/db-cscope.el.
This file is missing in the version of cedet shipped with emacs 24.3.
Σ: That makes me believe that if you want to use your setup you should use the bazaar version of cedet-2.0.

Conflicts between org-mode and yasnippet

EDIT My issue was related to snippet syntax all along... The configuration below totally works.
I'm trying to use org-mode and yasnippet together and it's not working even with some of the workarounds on the org-mode FAQ. Whenever I hit TAB on a snippet abbreviation the word gets deleted. TAB behaves normally if I'm not over a snippet word, so there's something going on...
I'm using Org-mode version 7.7, yasnippet (version 0.7.0), and GNU Emacs 23.4.1.
Here's my setup:
(setq load-path
(append (list nil
"~/.emacs.d/site-lisp/yasnippet"
"~/.emacs.d/site-lisp/org-7.7/lisp")
load-path))
;; set up yasnippet
(require 'yasnippet)
(yas/initialize)
(setq yas/snippet-dirs '("~/.emacs.d/mysnippets"
"~/.emacs.d/site-lisp/yasnippet/snippets"))
(mapc 'yas/load-directory yas/snippet-dirs)
;; set up org mode
(require 'org-install)
;; fix some org-mode + yasnippet conflicts:
(defun yas/org-very-safe-expand ()
(let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
(add-hook 'org-mode-hook
(lambda ()
(make-variable-buffer-local 'yas/trigger-key)
(setq yas/trigger-key [tab])
(add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
(define-key yas/keymap [tab] 'yas/next-field)))
And I'm pretty sure the hook is running as expected because of the following output of C-h v org-tab-first-hook in an org buffer:
org-tab-first-hook is a variable defined in `org.el'.
Its value is
(yas/org-very-safe-expand org-hide-block-toggle-maybe org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe)
And here's C-h k TAB in an org buffer:
<tab> runs the command org-cycle, which is an interactive Lisp
function in `org.el'.
EDIT
After doing a edebug-defun on my yas/org-very-safe-expand function I'm seeing the following message
Result: "[yas] elisp error! Symbol's value as variable is void: err"
So yas is error'ing out somewhere... My edebug foo is not quite up to par but if I get some time I'll try to single step through and see where the error is. My full emacs configuration is on github here.
Turns out my issue was related to snippet syntax, not setup. Silly silly me...
In other words, this totally works:
;; fix some org-mode + yasnippet conflicts:
(defun yas/org-very-safe-expand ()
(let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
(add-hook 'org-mode-hook
(lambda ()
(make-variable-buffer-local 'yas/trigger-key)
(setq yas/trigger-key [tab])
(add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
(define-key yas/keymap [tab] 'yas/next-field)))
This took me some time to get worked out as well. I'm using Org-mode version 7.7, yasnippet (version 0.6.1c), GNU Emacs 22.1.1. Here are the relevant portions of my .emacs file (there is some flyspell stuff that is irrelevant):
;;
;; org-mode stuff
;;
(add-to-list 'load-path "/Users/cmalone/install/org-mode/org-mode/lisp")
(add-to-list 'load-path "/Users/cmalone/install/org-mode/org-mode/contrib/lisp")
(require 'org-install)
;;
;; for YASnippet
;;
(add-to-list 'load-path "/Users/cmalone/.emacs.d/plugins/yasnippet-0.6.1c")
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "/Users/cmalone/.emacs.d/plugins/yasnippet-0.6.1c/snippets")
;; Make TAB the yas trigger key in the org-mode-hook and enable flyspell mode and autofill
(add-hook 'org-mode-hook
(lambda ()
;; yasnippet
(make-variable-buffer-local 'yas/trigger-key)
(org-set-local 'yas/trigger-key [tab])
(define-key yas/keymap [tab] 'yas/next-field-group)
;; flyspell mode for spell checking everywhere
;; (flyspell-mode 1)
;; auto-fill mode on
(auto-fill-mode 1)))
C-h v org-tab-first-hook is the same as yours except of the yas/org-very-safe-expand of course. C-h k TAB shows:
TAB runs the command yas/expand
which is an interactive Lisp function in `yasnippet.el'.
It is bound to TAB, <menu-bar> <YASnippet> <Expand trigger>.
(yas/expand)
Expand a snippet before point.
If no snippet expansion is possible, fall back to the behaviour
defined in `yas/fallback-behavior'

Remember-mode-hook not working in emacs

I am using GNU Emacs 23.1.1. I used M-x org-version to confirm that I have
Org-mode version 6.34c
When I execute M-x remember, the remember buffer opens but I get the message "Symbol's function value is void: nil". Therefore I think that the remember-mode-hook fails because when I enter text in the remember buffer and hit C-c C-c, the text doesn't get written to todo.org (specified in the template definition below).
Instead I get the message "Target files for notes must be in Org-mode if not filing to top/bottom". Please help. The relevant entries from my .emacs are below:
(require 'remember)
(require 'org-remember)
(org-remember-insinuate)
(setq org-directory "~/")
(define-key global-map "\C-cr" 'org-remember)
(setq remember-annotation-functions '(org-remember-annotation))
(setq remember-handler-functions '(org-remember-handler))
(add-hook 'remember-mode-hook 'org-remember-apply-template)
(setq org-remember-templates
'(("Todo" ?t "* TODO %?\n %i\n %a" "~/todo.org" "Tasks")))
Instead of fiddling with remember, it's probably better for you to upgrade org-mode. After org-mode v6.36 capturing is done by org-capture. Have a look at the info node '9.1 Capture' in the org-manual.