Emacs – Error when calling (server-start)

[Origin]: https://stackoverflow.com/questions/885793/emacs-error-when-calling-server-start

I am currently using GNU Emacs 23.0.93.1 in Windows Vista SP1. In my .emacs file I make a call to (server-start) and that is causing an error with the message The directory ~/.emacs.d/server is unsafe. Has anyone seen this and know a fix or workaround? … other than leaving server turned off 😉

Here is the stack trace:

Debugger entered--Lisp error: (error "The directory ~/.emacs.d/server is unsafe")
  signal(error ("The directory ~/.emacs.d/server is unsafe"))
  error("The directory %s is unsafe" "~/.emacs.d/server")
  server-ensure-safe-dir("~\\.emacs.d\\server\\")
  server-start(nil)
  call-interactively(server-start t nil)
  execute-extended-command(nil)
  call-interactively(execute-extended-command nil nil)

I found this solution on EmacsWiki:

“The problem is the ownership of the directory ~/.emacs.d/server when you also have “Administrators” rights on your account. Create the directory ~/.emacs.d/server and set the owner of this directory to your login name and the problem is gone. As I have a “Dutch” version of Windows 7 I don’t know the English terms exactly but here’s the procedure:

Click R-mouse on ~/.emacs.d/server and select “Properties” (last item in menu). From Properties select the Tab “Security” and then select the button “Advanced”. Then select the Tab “Owner” and change the owner from Administrators (<your-pc-name>\Administrators) into <your-login-name> (<your-pc-name>\<your-login-name>. Now the server code will accept this directory as secure because you are the owner.

Hope this helps for all you guys, it solved the problem for me anyway.

W.K.R. Reutefleut”

It definitely works on Vista, with Emacs 23.2.1.

Advertisements

C brace indentation

[Origin]: https://emacs.stackexchange.com/questions/22673/c-brace-indentation

I am new to Emacs and trying to learn the basics.

I am writing a few C programs and I noticed that the default brace indentation is as follows:

for(i = 0; i &lt; 10; ++i)
    {
        // code 
    }

How would I go about modifying this behaviour to achieve the following instead:

for(i = 0; i &lt; 10; ++i)
{
    // code
}

As mentioned in this answer on SO, you can do:

(setq c-default-style "bsd")

This will set the style for all C-based modes. If you want to set it only for one, do e.g.:

(add-to-list 'c-default-style '(c-mode "bsd"))

However, setting c-default-style will change various other style settings, which may not be what you want. To only change the post-for-loop-brace indentation, do:

(add-to-list 'c-offsets-alist '(substatement-open . 0))

(This will shadow the old value, which AFAIK shouldn’t cause any problems. See this question and its answers for possible ways to actually replace the old value.)

Now to generalize: how do you find the specific syntactic symbol in the c-offsets-alist that you need to modify?

Note the line that has faulty indentation (in this case, the one with the { after the for loop), and move the point to that line. Then do:

M-x c-show-syntactic-information

(or C-c C-s). This will give you e.g.:

Syntactic analysis: ((substatement-open 16))

Another option is to do M-x c-set-offset (or C-c C-o), which will give you the following prompt:

Syntactic symbol to change: |substatement-open

Here the | marks the position of the cursor, with the relevant symbol auto-filled for you.

Thanks to @nispio for the info!

How to delete/unbind a name defined in Emacs Lisp?

[Origin]: https://lists.gnu.org/archive/html/help-gnu-emacs/2004-01/msg00072.html

Re: How to delete/unbind a name defined in Emacs Lisp?


From: Jesper Harder
Subject: Re: How to delete/unbind a name defined in Emacs Lisp?
Date: Tue, 06 Jan 2004 15:34:19 +0100
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

WANG Wei <address@hidden> writes:

> When we say (defun xxx () ...), we introduce a new name "xxx" in
> Emacs. A lot of such names will dirty the global name space. So I
> wonder how to delete names that I don't need any more.

Use `fmakunbound' to remove a function and `makunbound' to remove a
variable.

Is it possible to make yasnippets to expand snippets inside an org-mode babel section in the appropriate mode?

[Origin]: https://emacs.stackexchange.com/questions/26991/is-it-possible-to-make-yasnippets-to-expand-snippets-inside-an-org-mode-babel-se

As of 2017, Jan 22, if you set org-src-tab-acts-natively and org-src-fontify-natively, then TAB in source blocks will expand snippets of the block’s language. You may want to set yas-buffer-local-condition to stop org mode snipppets from shadowing the block mode’s snippets:

(defun my-org-mode-hook ()
  (setq-local yas-buffer-local-condition
              '(not (org-in-src-block-p t))))
(add-hook 'org-mode-hook #'my-org-mode-hook)

See also https://github.com/joaotavora/yasnippet/issues/761https://github.com/joaotavora/yasnippet/pull/760

shareedit

Conflicts between org-mode and yasnippet

[Origin]: https://stackoverflow.com/questions/9418148/conflicts-between-org-mode-and-yasnippet

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)))
shareedit

Emacs: Stop Cursor Going into Minibuffer Prompt

[Origin]: http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html

in emacs minibuffer prompt, when you press the left arrow key, the cursor will move back all the way over the prompt text. This is annoying because user often will hold down 【Alt+b】 to move back by word to edit, and when user starts to type something, emacs will say “This is read-only”. Then you have to manually move cursor out of the prompt. You can try it now by Alt+x query-replace.

Here’s how to set the cursor not going into prompt. Put the following in your emacs init.

;; minibuffer, stop cursor going into prompt
(customize-set-variable
 'minibuffer-prompt-properties
 (quote (read-only t cursor-intangible t face minibuffer-prompt))))

( Thanks to Clément Pit-Claudel)

Here’s alternative way to do it. Might work better if emacs changed in the future by the time you read this.

  1. Alt+x customize-group.
  2. Type “minibuffer”.
  3. scroll down to “Minibuffer Prompt Properties”.
  4. Check box “Don’t Enter”.
  5. Go to the top, click “Apply and Save”
emacs customize-group minibuffer 2016-06-16
M-x customize-group, “minibuffer”.

After that, emacs will insert the following to your init file:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(minibuffer-prompt-properties
   (quote
    (read-only t cursor-intangible t face minibuffer-prompt))))