用于switch ... case语句的Emacs缩进

时间:2011-08-27 06:58:27

标签: emacs switch-statement indentation

Emacs中的缩进始终有效,但我面临一些关于switch - case陈述的问题。

例如,

switch (x) {
case 'A':
case 'B':
    printf("hello");

printf(...);
printf(...);
break;
}

我希望以这种方式显示:

switch (x) {
case 'A':
case 'B':
    printf("hello");

    printf(...);
    printf(...);
    break;
}

如何?

2 个答案:

答案 0 :(得分:0)

在缓冲区中:

`M-x c-set-style` RET `k&r` RET

在档案.emacs中:

(c-set-style "k&r")

答案 1 :(得分:0)

最后发现了这一点:

将光标置于public class TransactionWorker extends Worker { private static final String TAG = "TransactionWorker"; private boolean success = false; private boolean started = false; public TransactionWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); } @NonNull @Override public Result doWork() { //database path String path = getInputData().getString("path"); //increment amount long increment = getInputData().getLong("increment",0); DatabaseReference ref; try{ //if database reference does not exist yet // (e.g. app not closed or database not started yet) ref = FirebaseDatabase.getInstance().getReference(path); }catch (NullPointerException error){ error.printStackTrace(); return Result.retry(); } //wait while the transaction did not succeed yet while(!success){ //only sleep if the transaction already started if(started){ try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } continue; } //start transaction only if not started yet ref.runTransaction(new Transaction.Handler() { @NonNull @Override public Transaction.Result doTransaction(@NonNull MutableData mutableData) { long value = 0; try{ value = mutableData.getValue(Long.class); }catch (Exception e){ e.printStackTrace(); } //increment value mutableData.setValue(value + increment); return Transaction.success(mutableData); } @Override public void onComplete(@Nullable DatabaseError databaseError, boolean b, @Nullable DataSnapshot dataSnapshot) { Log.d(TAG, "onComplete: " + b); success = b; } }); started = true; } //work succeeded return Result.success(); }} 关键字上。然后public static void doIncrementTransaction(String path,final long increment){ Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED).build(); Data transactData = new Data.Builder().putString("path",path) .putLong("increment",increment).build(); OneTimeWorkRequest oneTimeWorkRequest = new OneTimeWorkRequest. Builder(TransactionWorker.class).setInputData(transactData) .setConstraints(constraints) .setBackoffCriteria(BackoffPolicy.LINEAR,3000, TimeUnit.MILLISECONDS) .build(); WorkManager.getInstance(this).enqueue(oneTimeWorkRequest); } 。然后应说类似case。点击C-c C-o。然后输入您希望Syntactic symbol to change: case-label标签缩进的默认空格数。