Emacs – Error when calling (server-start)

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

I am currently using GNU Emacs 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")
  call-interactively(server-start t 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.


Lock, mutex, semaphore… what’s the difference?

[Origin]: https://stackoverflow.com/questions/2332765/lock-mutex-semaphore-whats-the-difference

A lock allows only one thread to enter the part that’s locked and the lock is not shared with any other processes.

A mutex is the same as a lock but it can be system wide (shared by multiple processes).

A semaphore does the same as a mutex but allows x number of threads to enter, this can be used for example to limit the number of cpu, io or ram intensive tasks running at the same time.

You also have read/write locks that allows either unlimited number of readers or 1 writer at any given time.

There are a lot of misconceptions regarding these words.This is from a previous post (https://stackoverflow.com/a/24582076/3163691) which fits superb here:

1) Critical Section= User object used for allowing the execution of just one active thread from many others within one process. The other non selected threads are put to sleep.

[No interprocess capability, very primitive object].

2) Mutex Semaphore (aka Mutex)= Kernel object used for allowing the execution of just one active thread from many others, among different processes. The other non selected threads are put to sleep. This object supports thread ownership, thread termination notification, recursion (multiple ‘acquire’ calls from same thread) and ‘priority inversion avoidance’.

[Interprocess capability, very safe to use, a kind of ‘high level’ synchronization object].

3) Counting Semaphore (aka Semaphore)= Kernel object used for allowing the execution of a group of active threads from many others. The other non selected threads are put to sleep.

[Interprocess capability however not very safe to use because it lacks following ‘mutex’ attributes: thread termination notification, recursion?, ‘priority inversion avoidance’?, etc].

4) And now, talking about ‘spinlocks’, first some definitions:

Critical Region= A region of memory shared by 2 or more processes.

Lock= A variable whose value allows or denies the entrance to a ‘critical region’. (It could be implemented as a simple ‘boolean flag’).

Busy waiting= Continuosly testing of a variable until some value appears.


Spin-lock (aka Spinlock)= A lock which uses busy waiting. (The acquiring of the lock is made by xchg or similar atomic operations).

[No thread sleeping, mostly used at kernel level only. Ineffcient for User level code].

As a last comment, I am not sure but I can bet you some big bucks that the above first 3 synchronizing objects (#1, #2 and #3) make use of this simple beast (#4) as part of their implementation.

Have a good day!.


-Real-Time Concepts for Embedded Systems by Qing Li with Caroline Yao (CMP Books).

-Modern Operating Systems (3rd) by Andrew Tanenbaum (Pearson Education International).

-Programming Applications for Microsoft Windows (4th) by Jeffrey Richter (Microsoft Programming Series).

Also, you can take a look at look at: https://stackoverflow.com/a/24586803/3163691

What’s the meaning of require: ‘ngModel’?

[Origin]: https://stackoverflow.com/questions/20930592/whats-the-meaning-of-require-ngmodel

This is the HTML for my directive:

<textarea data-modal="modal" data-mydir ng:model="abc"></textarea>

In my directive I have this:

return {
        require: 'ngModel',
        replace: true,
        scope: {
            modal: '=modal',
            ngModel: '=',
            pid: '=pid'

Can someone tell me, what’s the significance of require: ‘ngModel’ ? I see this in many different directives. Could I call this data-modal?

I am confused because when I change it to data-modal I get a message from Angular saying

Controller 'ngModel', required by directive 'textarea', can't be found!

Delete file containing invalid characters in windows

[Origin]: https://serverfault.com/questions/95581/delete-file-containing-invalid-characters-in-windows

I have some files that contain colon character in the filename (eg. 1d67c0d23e859ed4a259749e4a720d9e:default-sink). When I try to remove them from command line with the command:

c:\backup> del /F *.*

I get “The system cannot find the file specified.” for each file. If I specify an individual file:

c:\backup> del /F "1d67c0d23e859ed4a259749e4a720d9e:default-sink"

I get “The filename, directory name, or volume label syntax is incorrect.”. If I try to use rd on the parent folder I get

How can I remove these files?

This worked for me:

  1. Ran chkdsk /f
  2. Rebooted PC
  3. Then I was able to select and delete the file

Close all the files, if any opened, that are saved in the drive which is containing such files. Now, Open the drive properties.

“My Computer” -> “Right Click on the this drive” > properties

Then, go to “Tools” tab and click “Check now” under ‘Error checking’ label.

enter image description hereClick here for larger image

This will unmount your drive and will scan the complete drive for errors, eventually it will delete such files with illegal names. On finishing it will show a messages saying some files were fixed.

I successfully deleted such files from my external hard disk.

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!

Tried to Load Angular More Than Once

[Origin]: https://stackoverflow.com/questions/22595878/tried-to-load-angular-more-than-once

This could be a number of issues: essentially it’s a problem of routeProvider not finding a file and recursively loading the default.

For me, it turned out that it wasn’t minification but concatenation of the js that caused the problems.

angular.module('myApp').config(['$routeProvider', function ($routeProvider) {
      .when('/', {
        templateUrl: 'views/listing.html',
        controller: 'ListingCtrl'
        redirectTo: '/'
  }]).constant('FIREBASE_URL', 'something');

You’ll notice that if the app can’t find a file (i.e., otherwise), then it will redirect to the root, which in this case loads the templateUrl. But if your templateUrl is wrong, then it will cause a recursion that reloads index.html loading angular (and everything else) over and over.

In my case, grunt-concat caused the templateUrl to be wrong after build, but not before.

I had the same issue, The problem was the conflict between JQuery and Angular. Angular couldn’t set the full JQuery library for itself. As JQLite is enough in most cases, I included Angular first in my web page and then I loaded Jquery. The error was gone then.

IE: Prevent confirming dialog box when using window.close() to close a main window

[Origin]: https://blogs.msdn.microsoft.com/rextang/2008/10/17/ie-prevent-confirming-dialog-box-when-using-window-close-to-close-a-main-window/

Been busying on investigating Dynamics CRM 4 Web Application and Outlook VSTO Add-In development for the past weeks and not update blog much. It’s time to do a post now.

Little but useful trick when toying with IE windows.

When there is only a parent IE window and you load some pages with javascript “window.close();” that trying to close the window, in IE there will be a confirming dialog box asking if one really want to close the IE window. This often causes problems if you want to host your IE in a winform, and here are some simple and quick workaround to overcome this.

   1: <HTML>
   2: <HEAD>
   3: <TITLE>Close window without prompt</TITLE>
   4: <SCRIPT LANGUAGE="JavaScript">
   5: <!--
   6: function realClose()
   7: {
   8:     var win=window.open("","_top","","true");
   9:     win.opener=true;
  10:     win.close();
  11: }
  12: //-->
  13: </SCRIPT>
  14: </HEAD>
  15: <BODY>
  16: Close window without prompt
  17: <FORM><INPUT TYPE="button" VALUE="Close ME!" onClick="realClose()"></FORM>
  18: </BODY>
  19: </HTML>

The trick is to open an empty page in self window (the “_top”), and then close the opened window in javascript to fool IE that he is closing a child window. this worked without problems.

Further more, if you don’t have ways to modify the page you are opening, thus not able to embed the realClose() function to the page, maybe in a WinForm that hosting a IE window and actually you don’t know what page you are going to open, maybe this way would work.

   1: <HTML>
   2: <HEAD>
   3: <TITLE>Close window without prompt</TITLE>
   4: <SCRIPT LANGUAGE="JavaScript">
   5: <!--
   6: function realClose()
   7: {
   8:     var win=window.open("","_top","","true");
   9:     win.opener=true;
  10:     //win.close();
  11:     win.realclosefunc();
  12: }
  13: window.realclosefunc = window.close;
  14: window.close = realClose;
  15: //-->
  16: </SCRIPT>
  17: </HEAD>
  18: <BODY>
  19: Close window without prompt
  20: <FORM><INPUT TYPE="button" VALUE="Close ME!" onClick="javascript: window.close();"></FORM>
  21: </BODY>
  22: </HTML>

in this way, when in WinForm, try to manipulate DOM of the hosting IE window, and try to insert the piece of code in the head part of page, then change the default window.close function to our self-made function to close the window. using this way won’t need to do a string replacement of the downloaded html contents to replace window.close() to our close function. little bit tidy, but still doable…

For WinForm hosting pattern, using .net 2.0 WinForm WebBrowser control won’t give you that magic WindowClosing event to prevent IE closing in your WinForm. There are articles introducing hooking DWebBrowserEvents2 interface to get this event working with WebBrowser control, but for no reason it just not working.

So I just tried to use COM Interop way to bridge the ActiveX IE control to .net by using aximp.exe command, and by doing this found that the WindowClosing event is working and able to detect the IE close before that confirming dialog box showed up, and then to cancel the IE close action inside the event and close my WinForm. this should be the easiest way to accomplish this task I think.