0%

《商业模式全史》这本书是日本作家三谷宏治所作。

在亚马逊关掉国内的网站前买了这本书,很早之前看到过,这位作者也还有另外一本和商业相关的书。

全书一共有以下几个章节。 会慢慢概括和罗列一些书中提到的公司和模式。

什么是商业模式

商业模式/Business Model, 这个词语听起来还挺高大上的。说通俗一点其实就是通过什么方法赚钱/盈利。

创生期(1673-1969)

变革期(1970=1990)

创造期(1991-2001)

巨无霸战争与“小个子”崛起

如何进行商业模式创新

相关

推荐另一本我读过的Business Model Generation。这是一本教读者怎么去“画”一个商业模式的书。像slide 一样一页一页的书, 能从中读出一些新的思考方式和角度。

Share a script I used today to generate batch of barcodes by using Python.

  1. generate the range of barcode you want.
  2. use label to generate an image.
  3. fill the image generated in step 2 into a PDF and save it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#!/usr/bin/env python3
from itertools import product

from typing import List
from reportlab.lib.pagesizes import A4
from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics.barcode.eanbc import Ean13BarcodeWidget
from reportlab.graphics import renderPDF
from reportlab.pdfgen.canvas import Canvas

PAGESIZE = A4 # choose the final print page size
NUM_LABELS_X = 3 # how many barcodes per line
NUM_LABELS_Y = 5 # how many barcodes per column
BAR_WIDTH = 1.5 # barcode length
BAR_HEIGHT = 51.0 # barcode height
TEXT_Y = 80
BARCODE_Y = 17

LABEL_WIDTH = PAGESIZE[0] / NUM_LABELS_X
LABEL_HEIGHT = PAGESIZE[1] / NUM_LABELS_Y
SHEET_TOP = PAGESIZE[1]

def codes(number):
""" Generate all the possible barcodes
params
number: the range number of each position
"""
for barcode in product(range(10), repeat = number):
yield "".join(map(str, barcode))

def label(ean13: str, description: str) -> Drawing:
"""
Generate a drawing with EAN-13 barcode and descriptive text.
:param ean13: The EAN-13 Code.
:type ean13: str
:param description: Short product description.
:type description: str
:return: Drawing with barcode and description
:rtype: Drawing
"""
print(ean13)
text = String(0, TEXT_Y, description, fontName="Helvetica",
fontSize=10, textAnchor="middle")
text.x = LABEL_WIDTH / 2 # center text (anchor is in the middle)

barcode = Ean13BarcodeWidget(ean13)
barcode.barWidth = BAR_WIDTH
barcode.barHeight = BAR_HEIGHT
x0, y0, bw, bh = barcode.getBounds()
barcode.x = (LABEL_WIDTH - bw) / 2 # center barcode
barcode.y = BARCODE_Y # spacing from label bottom (pt)
label_drawing = Drawing(LABEL_WIDTH, LABEL_HEIGHT)
label_drawing.add(text)
label_drawing.add(barcode)
return label_drawing

def fill_sheet(canvas: Canvas, label_drawings: List[Drawing]):
"""
Simply fill the given ReportLab canvas with label drawings.
:param canvas: The ReportLab canvas
:type canvas: Canvas
:param label_drawing: Contains Drawing of configured size
:type label_drawing: Drawing
"""
index = 0
for u in range(0, NUM_LABELS_Y):
for i in range(0, NUM_LABELS_X):
x = i * LABEL_WIDTH
y = SHEET_TOP - LABEL_HEIGHT - u * LABEL_HEIGHT
if index >= len(label_drawings):
break
renderPDF.draw(label_drawings[index], canvas, x, y)
index += 1

if __name__ == '__main__':
raw_codes = [code for code in codes(3)]
labels = [label("490177241" + code, '') for code in raw_codes[:200]]
total = NUM_LABELS_X * NUM_LABELS_Y
page = 1
while labels:
canvas = Canvas("{}.pdf".format(page), pagesize=PAGESIZE)
page += 1
fill_sheet(canvas, labels[:min(total, len(labels))])
canvas.save()
labels = labels[min(total, len(labels)):]


Previously I was using pyinotify to do some event notify jobs on local files.

This blog(with the testing script attached) is simply a summary which lists the events type and happening orders when doing different operations.

Script

Downlaod the test script here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python2
import subprocess
import pyinotify
import os
import shutil
mask = pyinotify.ALL_EVENTS
rootdir = '/tmp/test-pyinotify'

def _process_watcher_events(event):
print("event = %s" % event)

def _(path):
return os.path.join(rootdir, path)

def commands():
commands = [
['ls', rootdir],
['touch', _('origin.txt')],
['cp', _('origin.txt'), _('cp.txt')],
['mv', _('cp.txt'), _('mv.txt')],
['mv', _('mv.txt'), '/tmp/mv.txt'],
['rsync', '-a', '/tmp/mv.txt', _('rsync.txt')],
['scp', '/tmp/mv.txt', _('scp.txt')],
['ln', '-s', _('origin.txt'), _('ln.txt')],
['rm', _('ln.txt')],
['mkdir', _('testdir')],
['ln', _('origin.txt'), _('lnhard.txt')],
['python', '-c', "import os; f = open(os.path.join('%s', 'python.txt'), 'w'); f.write('test_python'); f.close()" % rootdir]
]
for cmd in commands:
print cmd
output = subprocess.check_output(cmd)
yield


if __name__ == "__main__":
if os.path.exists(rootdir):
shutil.rmtree(rootdir)
os.makedirs(rootdir)
watcher = pyinotify.WatchManager()
watcher.add_watch(rootdir, mask=mask, rec=True, auto_add=True, quiet=False)
notifier = pyinotify.Notifier(watcher, _process_watcher_events)
commands = commands()
while True:
notifier.process_events()
try:
next(commands)
while notifier.check_events(timeout=3):
notifier.read_events()
notifier.process_events()
print('===========================================\n')
except StopIteration:
while notifier.check_events(timeout=3):
notifier.read_events()
notifier.process_events()
print('finished')
break
shutil.rmtree(rootdir)

Summary

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
>>> python2 test_pyinotify.py

>>>
['ls', '/tmp/test']
event = <Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name='' path=/tmp/test pathname=/tmp/test wd=1 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=/tmp/test pathname=/tmp/test wd=1 >
event = <Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name='' path=/tmp/test pathname=/tmp/test wd=1 >
===========================================

['touch', '/tmp/test/origin.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x4 maskname=IN_ATTRIB name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
===========================================

['cp', '/tmp/test/origin.txt', '/tmp/test/cp.txt']
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
===========================================

['mv', '/tmp/test/cp.txt', '/tmp/test/mv.txt']
event = <Event cookie=416768 dir=False mask=0x40 maskname=IN_MOVED_FROM name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event cookie=416768 dir=False mask=0x80 maskname=IN_MOVED_TO name=mv.txt path=/tmp/test pathname=/tmp/test/mv.txt src_pathname=/tmp/test/cp.txt wd=1 >
===========================================

['mv', '/tmp/test/mv.txt', '/tmp/mv.txt']
event = <Event cookie=416769 dir=False mask=0x40 maskname=IN_MOVED_FROM name=mv.txt path=/tmp/test pathname=/tmp/test/mv.txt wd=1 >
===========================================

['rsync', '-a', '/tmp/mv.txt', '/tmp/test/rsync.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x4 maskname=IN_ATTRIB name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x4 maskname=IN_ATTRIB name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event cookie=416770 dir=False mask=0x40 maskname=IN_MOVED_FROM name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event cookie=416770 dir=False mask=0x80 maskname=IN_MOVED_TO name=rsync.txt path=/tmp/test pathname=/tmp/test/rsync.txt src_pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
===========================================

['scp', '/tmp/mv.txt', '/tmp/test/scp.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=scp.txt path=/tmp/test pathname=/tmp/test/scp.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=scp.txt path=/tmp/test pathname=/tmp/test/scp.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=scp.txt path=/tmp/test pathname=/tmp/test/scp.txt wd=1 >
===========================================

['ln', '-s', '/tmp/test/origin.txt', '/tmp/test/ln.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=ln.txt path=/tmp/test pathname=/tmp/test/ln.txt wd=1 >
===========================================

['rm', '/tmp/test/ln.txt']
event = <Event dir=False mask=0x200 maskname=IN_DELETE name=ln.txt path=/tmp/test pathname=/tmp/test/ln.txt wd=1 >
===========================================

['mkdir', '/tmp/test/testdir']
event = <Event dir=True mask=0x40000100 maskname=IN_CREATE|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
===========================================

event = <Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
event = <Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
===========================================

['ln', '/tmp/test/origin.txt', '/tmp/test/lnhard.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=lnhard.txt path=/tmp/test pathname=/tmp/test/lnhard.txt wd=1 >
===========================================

['python', '-c', "import os; f = open(os.path.join('/tmp/test', 'python.txt'), 'w'); f.write('test_python'); f.close()"]
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
event = <Event dir=False mask=0x2 maskname=IN_MODIFY name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
===========================================

finished

pyinotify result table

I used to use spacemacs as my daily environment for developing. Spacemacs is powerful and fancy. But sometimes I have to accept it’s concept and common usages. Yesterday I tried to upgrade my Emacs from 25 to 27 which broke the spacemacs config. Then I think it’s a good time to learn more detail about Emacs. So I decide to write my own config from the scratch.

It will be time cost but maybe it’s worth to do it. I would like to have fully control over the powerful Emacs ;)

This blog will keep updating as my simple .emacs file growing. Thanks for every suggestion and tutorial. I will later list all the resources and tutorials I have met during the configuration.

Features

  1. multiple cursor operations
  2. Alt+arrow key to jump between windows
  3. Alt+num (0~8) to switch to windows directly
  4. Side-bar imenu

flymake settings

  1. global config file is under ~/.config/flake8

TODO

  • C++ language support
  • better M-x menu
  • select multiple words and edit
  • better fuzzy search
  • add ivy for search
  • window management. restore or forth to windows status. save windows status
  • general jump in buffer. save bookmark etc.

Language support packages

Python

  1. python programming in emacs
  2. Elpy The package I used in this configuration.

shortcuts

.emacs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

;;; HOW TO DEBUG
;;; (toggle-debug-on-error)
;;; (toggle-debug-on-quit)


(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.
'(custom-safe-themes
'("04232a0bfc50eac64c12471607090ecac9d7fd2d79e388f8543d1c5439ed81f5" "6e70d505e0957aaa67562ff0487b7b1b1e10f879655f2c47adf85949790fb687" default))
'(display-line-numbers t)
'(nil nil t)
'(package-selected-packages
'(magit-stgit counsel-projectile projectile zenburn-theme zenburn magit go-mode counsel ivy-hydra imenus multiple-cursors imenu-list use-package elpy winum)))
(custom-set-faces
;; custom-set-faces 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.
'(org-document-title ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 2.0 :underline nil))))
'(org-level-1 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.75))))
'(org-level-2 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.5))))
'(org-level-3 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.25))))
'(org-level-4 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.1))))
'(org-level-5 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif"))))
'(org-level-6 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif"))))
'(org-level-7 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif"))))
'(org-level-8 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif")))))

;; load emacs 24's package system. Add MELPA repository.
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
;; '("melpa" . "http://stable.melpa.org/packages/") ; many packages won't show if using stable
'("melpa" . "http://melpa.org/packages/")
t))
(package-initialize)

;; create prefix key. M-m
(define-prefix-command 'M-m
)
(global-set-key (kbd "M-m") M-m)

;; split window
(global-set-key (kbd "M-m w -") 'split-window-vertically)
(global-set-key (kbd "M-m w /") 'split-window-horizontally)


;; M-[arrow] jump to
;; use-package bind-key shortcuts instead of global-set-key to prevent major mode overwrite global key settings
;; from https://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings
(global-set-key (kbd "M-<left>") 'windmove-left)
(global-set-key (kbd "M-<right>") 'windmove-right)
(global-set-key (kbd "M-<up>") 'windmove-up)
(global-set-key (kbd "M-<down>") 'windmove-down)

;; M-num jump to window directly
(global-set-key (kbd "C-`") 'winum-select-window-by-number)
(global-set-key (kbd "C-²") 'winum-select-window-by-number)
(global-set-key (kbd "M-0") 'winum-select-window-0-or-10)
(global-set-key (kbd "M-1") 'winum-select-window-1)
(global-set-key (kbd "M-2") 'winum-select-window-2)
(global-set-key (kbd "M-3") 'winum-select-window-3)
(global-set-key (kbd "M-4") 'winum-select-window-4)
(global-set-key (kbd "M-5") 'winum-select-window-5)
(global-set-key (kbd "M-6") 'winum-select-window-6)
(global-set-key (kbd "M-7") 'winum-select-window-7)
(global-set-key (kbd "M-8") 'winum-select-window-8)

(require 'winum)
(defun winum-assign-9-to-calculator-8-to-flycheck-errors ()
(cond
((equal (buffer-name) "*Calculator*") 9)
((equal (buffer-name) "*Flycheck errors*") 8)))

(defun winum-assign-0-to-neotree ()
(when (string-match-p (buffer-name) ".*\\*NeoTree\\*.*") 10))

(add-to-list 'winum-assign-functions #'winum-assign-9-to-calculator-8-to-flycheck-errors)
(add-to-list 'winum-assign-functions #'winum-assign-0-to-neotree)

(set-face-attribute 'winum-face nil :weight 'bold)


(setq window-numbering-scope 'global
winum-reverse-frame-list nil
winum-auto-assign-0-to-minibuffer t
winum-assign-func 'my-winum-assign-func
winum-auto-setup-mode-line t
winum-format " %s "
winum-mode-line-position 1
winum-ignored-buffers '(" *which-key*"))

(winum-mode)

;; python
;; elpy
(elpy-enable)
;; disable shortcuts under elpy-mode, these are conflit with windows management and not so useful
(define-key elpy-mode-map (kbd "M-<left>") nil)
(define-key elpy-mode-map (kbd "M-<right>") nil)
(define-key elpy-mode-map (kbd "M-<up>") nil)
(define-key elpy-mode-map (kbd "M-<down>") nil)


;; windows management
;; use 'winner-mode' to redo and undo windows. This is usefull when you want to maxinum one window and back to multiple windows later.
;; winner-redo C-c <right>
;; winner-undo C-c <left>
(winner-mode 1)


;; imenu-list
;; shortcuts: Ctrl-'

(use-package imenu-list
:ensure t
:bind ("C-." . imenu-list-minor-mode)
:config
(setq imenu-list-focus-after-activation t))

(global-set-key (kbd "C-'") 'imenu-list-smart-toggle)


;; use which-function-mode to show where I am. usefull when function/class is huge
(which-function-mode)
;; when it cannot determinted, show n/a instead of ???
(setq which-func-unknown "n/a")
;; show the position on top
(setq-default header-line-format
'((which-func-mode ("" which-func-format " "))))
(setq mode-line-misc-info
;; We remove Which Function Mode from the mode line, because it's mostly
;; invisible here anyway.
(assq-delete-all 'which-func-mode mode-line-misc-info))


;; multiple-cursors
;; mark different lines/words and edit: 1. select the word. 2. C-> to select next lines

(require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)


;; ivy search
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
(global-set-key "\C-s" 'swiper)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-find-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
(global-set-key (kbd "C-c k") 'counsel-ag)
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)


(global-set-key (kbd "C-s-<right>") (lambda () (interactive) (enlarge-window-horizontally 5)))
(global-set-key (kbd "C-s-<left>") (lambda () (interactive) (shrink-window-horizontally 5)))
(global-set-key (kbd "C-s-<up>") (lambda () (interactive) (enlarge-window 5)))
(global-set-key (kbd "C-s-<down>") (lambda () (interactive) (shrink-window 5)))


;; ;; projectile
;; ;; (projectile-mode)
;; (counsel-projectile-mode 1)
;; (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
;; ;; set completion option
;; (setq projectile-completion-system 'ivy)
;; (setq 'projectile-globally-ignored-directories '(".git"
;; ".svn"
;; ".venv"))

;; (setq 'projectile-globally-ignored-files '(".pyc"
;; "~"))


;; (let ((projectile-project-root-files-top-down-recurring '(".git"))))
;; ;; enable projectile caching
;; (setq projectile-enable-caching t)
;; (setq projectile-use-native-indexing t)


;;====================================
;; Searching
;;====================================

;; use counsel-git to find file under current git repo
;; C-c g (counsel-git)


;; search buffer
;; I know that string is in my Emacs somewhere!
(require 'cl)
(defcustom search-all-buffers-ignored-files (list (rx-to-string '(and bos (or ".bash_history" "TAGS") eos)))
"Files to ignore when searching buffers via \\[search-all-buffers]."
:type 'editable-list)

(require 'grep)
(defun search-all-buffers (regexp prefix)
"Searches file-visiting buffers for occurence of REGEXP. With
prefix > 1 (i.e., if you type C-u \\[search-all-buffers]),
searches all buffers."
(interactive (list (grep-read-regexp)
current-prefix-arg))
(message "Regexp is %s; prefix is %s" regexp prefix)
(multi-occur
(if (member prefix '(4 (4)))
(buffer-list)
(remove-if
(lambda (b) (some (lambda (rx) (string-match rx (file-name-nondirectory (buffer-file-name b)))) search-all-buffers-ignored-files))
(remove-if-not 'buffer-file-name (buffer-list))))

regexp))

(global-set-key [f7] 'search-all-buffers)


;; hide welcome screen, show scratch directly
(setq inhibit-startup-screen t)

;; enable code folding by using hideshow
;; https://www.emacswiki.org/emacs/HideShow
;; C-c @ C-M-s show all
;; C-c @ C-M-h hide all
;; C-c @ C-s show block
;; C-c @ C-h hide block
;; C-c @ C-c toggle hide/show
;; (hs-minor-mode t)


;;
;; flymake
;; Finding Syntax Errors On The Fly
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Flymake.html
(define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error)
(define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error)

;;
;; c++ mode setting up
;;
;; mapping for file extension and mode
;; set .h header file open in c++ mode
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

(defun bucketzxm-c++-mode-hook ()
(setq c-basic-offset 4)
(c-set-offset 'substatement-open 0))

(add-hook 'c++-mode-hook 'bucketzxm-c++-mode-hook)


;;
;; markdown
;;
;; M-x (flymd-flyit) to start a browser
(require 'flymd)
(setq flymd-output-directory "/tmp")
;; set browser to firefox due to compatibility problem
;; https://github.com/mola-T/flymd/blob/master/browser.md#user-content-chrome-windows-or-uix
(defun my-flymd-browser-function (url)
(let ((browse-url-browser-function 'browse-url-firefox))
(browse-url url)))
(setq flymd-browser-open-function 'my-flymd-browser-function)



;;
;; org-mode
;;
;; reference: https://zzamboni.org/post/beautifying-org-mode-in-emacs/
;;

;; hide the emphasis markup(e.g. /.../ for italics
(setq org-hide-emphasis-markers t)

;; set font-lock subsitution for list markers (use - for list)
(font-lock-add-keywords 'org-mode
'(("^ *\\([-]\\) "
(0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
;; replace all headlines markers with different Unicode bullets
(use-package org-bullets
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

;; set up a nice proportional font, in different sizes, for the headlines.
(let* ((variable-tuple
(cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
((x-list-fonts "Verdana") '(:font "Verdana"))
((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
(nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro."))))
(base-font-color (face-foreground 'default nil 'default))
(headline `(:inherit default :weight bold :foreground ,base-font-color)))

(custom-theme-set-faces
'user
`(org-level-8 ((t (,@headline ,@variable-tuple))))
`(org-level-7 ((t (,@headline ,@variable-tuple))))
`(org-level-6 ((t (,@headline ,@variable-tuple))))
`(org-level-5 ((t (,@headline ,@variable-tuple))))
`(org-level-4 ((t (,@headline ,@variable-tuple :height 1.1))))
`(org-level-3 ((t (,@headline ,@variable-tuple :height 1.25))))
`(org-level-2 ((t (,@headline ,@variable-tuple :height 1.5))))
`(org-level-1 ((t (,@headline ,@variable-tuple :height 1.75))))
`(org-document-title ((t (,@headline ,@variable-tuple :height 2.0 :underline nil))))))


;; change default font
(add-to-list 'default-frame-alist
'(font . "Fira Code-12:Regular"))

;; get a good theme
;; (add-to-list 'custom-theme-load-path "~/.emacs.d/themes/zenburn")
;; (load-theme 'zenburn 1)



剁手Realforce R2TLA 键盘

正在用这把新买的Realforce键盘写这篇文章,这把键盘是Realforce的新款,但是等US布局等了很久。因为HHKB BT在Linux上的蓝牙表现实在不行,今天兴起剁手了这把Realforce新出的键盘。

带税原价现在是2.8w左右,用了Bic camera的积分扣了5000日元,然后正好是Line Pay的月末20%Cash back活动,降低到1.8w左右,然后有10%的积分,所以最终价格约是17000日元.(虽然感觉还是挺贵的)

因为之前HHKB是45G的,公司用的archiss茶轴也很重,估计超过50g了。 所以这把realforce我选择了30g的最轻版本。

不多说上图

  1. 开箱
2. 箱内 2.1 一个拔键器和两个备用键帽 2.2 两张垫片

使用感受

30g敲起来还是很轻的,这个系列一共4个重量的版本,30g,40g,55g和变化的。尝试了一下变化版版好像感觉不出太大的差别,这款键盘还是带带APC功能的,但是我还不知道怎么调整键程 orz. 用起暂时来挺舒服的,终于不用忍受蓝牙HHKB在Linux上各种的问题了…..